diff --git a/testy/testSlope.py b/testy/testSlope.py new file mode 100644 index 0000000..423a9ef --- /dev/null +++ b/testy/testSlope.py @@ -0,0 +1,15 @@ + +sma = list + +sma = [28.90, 28.91, 28.91, 28.92, 28.97, 28.99] +slope_lookback = 4 +roc_lookback = 4 + +slope = (sma[-1] - sma[-slope_lookback])/slope_lookback +roc = ((sma[-1] - sma[-roc_lookback])/sma[-roc_lookback])*100 + +print(slope) + + +# -1 až 0 klesání +# 0 až 1 stoupání \ No newline at end of file diff --git a/testy/testTelegram.py b/testy/testTelegram.py new file mode 100644 index 0000000..b46e6f6 --- /dev/null +++ b/testy/testTelegram.py @@ -0,0 +1,3 @@ +from v2realbot.utils.utils import send_to_telegram + +send_to_telegram("nazdarek") \ No newline at end of file diff --git a/v2realbot/ENTRY_backtest_strategyVykladaci.py b/v2realbot/ENTRY_backtest_strategyVykladaci.py index 65cfcf5..6444c01 100644 --- a/v2realbot/ENTRY_backtest_strategyVykladaci.py +++ b/v2realbot/ENTRY_backtest_strategyVykladaci.py @@ -45,7 +45,10 @@ stratvars = AttributeDict(maxpozic = 250, curve = [0.01, 0.01, 0.01, 0, 0.02, 0.02, 0.01,0.01, 0.01,0.03, 0.01, 0.01, 0.01,0.04, 0.01,0.01, 0.01,0.05, 0.01,0.01, 0.01,0.01, 0.06,0.01, 0.01,0.01, 0.01], blockbuy = 0, ticks2reset = 0.04, - consolidation_bar_count = 10) + consolidation_bar_count = 10, + slope_lookback = 20, + minimum_slope = -0.23 + ) ##toto rozparsovat a strategii spustit stejne jako v main toml_string = """ [[strategies]] @@ -106,7 +109,7 @@ def next(data, state: StrategyState): price = last_price ##prvni se vyklada na aktualni cenu, další jdou podle krivky, nula v krivce zvyšuje množství pro následující iteraci state.buy_l(price=price, size=qty) - print("prvni limitka na aktuální cenu. Další podle křicvky", price, qty) + print("prvni limitka na aktuální cenu. Další podle křivky", price, qty) for i in range(0,vykladka-1): price = price2dec(float(price - curve[i])) if price == last_price: @@ -133,24 +136,55 @@ def next(data, state: StrategyState): return 0 try: + + ## slope vyresi rychlé sesupy - jeste je treba podchytit pomalejsi sesupy + + + slope = 99 + #minimum slope disabled if -1 + + + #roc_lookback = 20 #print(state.vars.MA, "MACKO") #print(state.bars.hlcc4) state.indicators.ema = ema(state.bars.close, state.vars.MA) #state.bars.vwap #trochu prasarna, EMAcko trunc na 3 mista - kdyz se osvedci, tak udelat efektivne state.indicators.ema = [trunc(i,3) for i in state.indicators.ema] ic(state.vars.MA, state.vars.Trend, state.indicators.ema[-5:]) + + slope_lookback = int(state.vars.slope_lookback) + minimum_slope = float(state.vars.minimum_slope) + + if len(state.bars.close) > slope_lookback: + #slope = ((state.indicators.ema[-1] - state.indicators.ema[-slope_lookback])/slope_lookback)*100 + #PUVODNI slope = ((state.bars.close[-1] - state.bars.close[-slope_lookback])/slope_lookback)*100 + slope = ((state.bars.close[-1] - state.bars.close[-slope_lookback])/state.bars.close[-slope_lookback])*100 + #roc = ((state.indicators.ema[-1] - state.indicators.ema[-roc_lookback])/state.indicators.ema[-roc_lookback])*100 + state.indicators.slope.append(slope) + #state.indicators.roc.append(roc) + ic(state.indicators.slope[-5:]) + #ic(state.indicators.roc[-5:]) except Exception as e: - print("No data for MA yet", str(e)) + print("Exception in NEXT Indicator section", str(e)) print("is falling",isfalling(state.indicators.ema,state.vars.Trend)) print("is rising",isrising(state.indicators.ema,state.vars.Trend)) - #and data['index'] > state.vars.lastbuyindex+state.vars.Trend: - #neni vylozeno muzeme nakupovat + #SLOPE ANGLE PROTECTION + if slope < minimum_slope: + print("OCHRANA SLOPE TOO HIGH") + if len(state.vars.pendingbuys)>0: + print("CANCEL PENDINGBUYS") + ic(state.vars.pendingbuys) + res = asyncio.run(state.cancel_pending_buys()) + ic(state.vars.pendingbuys) + print("slope", slope) + print("min slope", minimum_slope) + if ic(state.vars.jevylozeno) == 0: print("Neni vylozeno, muzeme testovat nakup") - if isfalling(state.indicators.ema,state.vars.Trend): + if isfalling(state.indicators.ema,state.vars.Trend) and slope > minimum_slope: print("BUY MARKET") ic(data['updated']) ic(state.time) @@ -167,7 +201,7 @@ def next(data, state: StrategyState): #TODO predelat mechanismus ticků (zrelativizovat), aby byl pouzitelny na tituly s ruznou cenou #TODO spoustet 1x za X iteraci nebo cas if state.vars.jevylozeno == 1: - #pokud mame vylozeno a cena je vetsi nez 0.04 + #pokud mame vylozeno a cena je vetsi nez tick2reset if len(state.vars.pendingbuys)>0: maxprice = max(state.vars.pendingbuys.values()) print("max cena v orderbuys", maxprice) @@ -264,6 +298,8 @@ def init(state: StrategyState): #place to declare new vars print("INIT v main",state.name) state.indicators['ema'] = [] + state.indicators['slope'] = [] + #state.indicators['roc'] = [] def main(): diff --git a/v2realbot/backtesting/__pycache__/backtester.cpython-310.pyc b/v2realbot/backtesting/__pycache__/backtester.cpython-310.pyc index 3a47187..01a0da4 100644 Binary files a/v2realbot/backtesting/__pycache__/backtester.cpython-310.pyc and b/v2realbot/backtesting/__pycache__/backtester.cpython-310.pyc differ diff --git a/v2realbot/backtesting/backtester.py b/v2realbot/backtesting/backtester.py index d914b45..19e88d0 100644 --- a/v2realbot/backtesting/backtester.py +++ b/v2realbot/backtesting/backtester.py @@ -517,7 +517,7 @@ class Backtester: #with lock: for o in self.open_orders: #print(o) - if o.symbol == symbol: + if o.symbol == symbol and o.canceled_at is None: if side is None or o.side == side: res.append(o) return res diff --git a/v2realbot/controller/services.py b/v2realbot/controller/services.py index 646b5b0..1ebc057 100644 --- a/v2realbot/controller/services.py +++ b/v2realbot/controller/services.py @@ -235,6 +235,7 @@ def capsule(target: object, db: object): reason = "SHUTDOWN OK" except Exception as e: reason = "SHUTDOWN Exception:" + str(e) + print(str(e)) print(reason) finally: # remove runners after thread is stopped and save results to stratin history diff --git a/v2realbot/interfaces/__pycache__/live_interface.cpython-310.pyc b/v2realbot/interfaces/__pycache__/live_interface.cpython-310.pyc index f50c098..aa7f84b 100644 Binary files a/v2realbot/interfaces/__pycache__/live_interface.cpython-310.pyc and b/v2realbot/interfaces/__pycache__/live_interface.cpython-310.pyc differ diff --git a/v2realbot/interfaces/live_interface.py b/v2realbot/interfaces/live_interface.py index b877635..62f809b 100644 --- a/v2realbot/interfaces/live_interface.py +++ b/v2realbot/interfaces/live_interface.py @@ -147,7 +147,7 @@ class LiveInterface(GeneralInterface): return a except APIError as e: #order doesnt exist - if e.code == 40410000: return 0,0 + if e.code == 40410000: return 0 else: print("nepovedlo se zrusit objednavku", str(e)) #raise Exception(e) diff --git a/v2realbot/main.py b/v2realbot/main.py index 5ecc708..a22ffa3 100644 --- a/v2realbot/main.py +++ b/v2realbot/main.py @@ -11,7 +11,7 @@ from fastapi import FastAPI, Depends, HTTPException, status from fastapi.security import APIKeyHeader import uvicorn from uuid import UUID -import controller.services as cs +import v2realbot.controller.services as cs from v2realbot.common.model import StrategyInstance, RunnerView, RunRequest from fastapi import FastAPI, WebSocket, WebSocketDisconnect, Depends, HTTPException, status, WebSocketException, Cookie, Query from fastapi.responses import HTMLResponse, FileResponse diff --git a/v2realbot/static/index.html b/v2realbot/static/index.html index 5f13f39..f16ddc8 100644 --- a/v2realbot/static/index.html +++ b/v2realbot/static/index.html @@ -79,7 +79,13 @@
- + + + + + + + @@ -192,6 +198,28 @@ +