Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
VladKochetov007 committed May 30, 2021
1 parent db31189 commit 8512889
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 25 deletions.
40 changes: 36 additions & 4 deletions quick_trade/trading_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import random
import time
import typing
from typing import Dict, List, Tuple, Any
from typing import Dict, List, Tuple, Any, Iterable

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -78,6 +78,8 @@ class Trader(object):
__last_take_profit: float
returns_strategy_diff: List[float]
sec_interval: int
supports: Dict[int, float]
resistances: Dict[int, float]

def __init__(self,
ticker: str = 'BTC/USDT',
Expand Down Expand Up @@ -286,6 +288,7 @@ def strategy_diff(self, frame_to_diff: pd.Series, *args, **kwargs) -> utils.PRED
"""
self.returns = list(np.digitize(frame_to_diff.diff(), bins=[0]))
self.set_open_stop_and_take()
self.set_credit_leverages()
return self.returns

def strategy_buy_hold(self, *args, **kwargs) -> utils.PREDICT_TYPE_LIST:
Expand Down Expand Up @@ -682,6 +685,19 @@ def strategy_ichimoku(self,
self.set_open_stop_and_take()
return self.returns

def crossover(self, fast: Iterable, slow: Iterable):
self.returns = []
for s, f in zip(slow, fast):
if s < f:
self.returns.append(utils.BUY)
elif s > f:
self.returns.append(utils.SELL)
else:
self.returns.append(utils.EXIT)
self.set_credit_leverages()
self.set_open_stop_and_take()
return self.returns

def inverse_strategy(self, swap_tpop_take: bool = True, *args, **kwargs) -> utils.PREDICT_TYPE_LIST:
"""
makes signals inverse:
Expand Down Expand Up @@ -761,13 +777,17 @@ def backtest(self,
seted,
credit_lev,
high,
low) in enumerate(zip(self.returns[:-1],
low,
next_h,
next_l) in enumerate(zip(self.returns[:-1],
self.stop_losses[:-1],
self.take_profits[:-1],
seted_[:-1],
self.credit_leverages[:-1],
data_high[:-1],
data_low[:-1])):
data_low[:-1],
data_high[1:],
data_low[1:])):

if seted is not np.nan:
if oldsig != utils.EXIT:
Expand All @@ -785,7 +805,8 @@ def backtest(self,
exit_take_stop = False
ignore_breakout = True

if min(stop_loss, take_profit) < low <= high < max(stop_loss, take_profit) or ignore_breakout:
next_breakout = min(stop_loss, take_profit) < next_l <= next_h < max(stop_loss, take_profit)
if (min(stop_loss, take_profit) < low <= high < max(stop_loss, take_profit) and next_breakout) or ignore_breakout:
diff = data_column[e + 1] - data_column[e]
else:
exit_take_stop = True
Expand Down Expand Up @@ -1600,3 +1621,14 @@ def find_all_talib_patterns(self, *args, **kwargs):
patterns = map(utils.anti_set_, patterns)
self.set_open_stop_and_take()
return self.multi_strategy_collider(*patterns, mode='super')

def get_support_resistanse(self) -> Dict[str, Dict[int, float]]:
lows = self.df['Low'].values
highs = self.df['High'].values
for i in range(2, len(lows)-2):
if lows[i-2] >= lows[i-1] >= lows[i] <= lows[i+1] <= lows[i+2]:
self.supports[i] = lows[i]
if highs[i-2] <= highs[i-1] <= highs[i] >= highs[i+1] >= highs[i+2]:
self.resistances[i] = highs[i]
return {'resistance': self.resistances,
'supports': self.supports}
7 changes: 1 addition & 6 deletions quick_trade/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import datetime as dt
import json
import logging
import os
from typing import Any, List, Union

import numpy as np
Expand All @@ -23,10 +22,6 @@
SELL: PREDICT_TYPE = 0
EXIT: PREDICT_TYPE = 2

IEX_TOKEN: str = 'Tpk_a4bc3e95d4c94810a3b2d4138dc81c5d'

os.environ['IEX_API_VERSION'] = 'iexcloud-sandbox'
os.environ['IEX_TOKEN'] = IEX_TOKEN
__author__: str = 'Vlad Kochetov'
__credits__: List[str] = ["Hemerson Tacon -- Stack overflow",
"hpaulj -- Stack overflow",
Expand All @@ -42,7 +37,7 @@
"https://teletype.in/@cozy_codespace/Hk70-Ntl4 -- heroku and threading problems",
"https://stackoverflow.com/questions/57838939/handling-exceptions-with-bulk-api-requests --"
"IEX token"]
__version__: str = "4.2.2"
__version__: str = "4.3"

SCATTER_SIZE: float = 12.0
SCATTER_ALPHA: float = 1.0
Expand Down
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plotly
pykalman
numpy
pandas
plotly==4.14.3
pykalman==0.9.5
numpy==1.20.3
pandas==1.2.4
ta==0.7.0
scipy
ccxt
scipy==1.6.3
ccxt==1.50.66
18 changes: 9 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
author='Vlad Kochetov',
author_email='[email protected]',
packages=setuptools.find_packages(),
version='4.2.2',
version='4.3',
description='Trading system for cryto, forex, stocks and others',
long_description=long_desc,
long_description_content_type="text/markdown",
url='https://github.com/VladKochetov007/quick_trade',
install_requires=[
'plotly',
'pykalman',
'numpy',
'pandas',
'ta==0.7.0',
'scipy',
'ccxt',
'plotly==4.14.3'
'pykalman==0.9.5'
'numpy==1.20.3'
'pandas==1.2.4'
'ta==0.7.0'
'scipy==1.6.3'
'ccxt==1.50.66'
],
download_url='https://github.com/VladKochetov007/quick_trade/archive/4.2.tar.gz',
download_url='https://github.com/VladKochetov007/quick_trade/archive/4.3.tar.gz',
keywords=[
'technical-analysis',
'python3',
Expand Down

0 comments on commit 8512889

Please sign in to comment.