diff --git a/v2realbot/ENTRY_backtest_strategyVykladaci.py b/v2realbot/ENTRY_backtest_strategyVykladaci.py index c003341..de54ef1 100644 --- a/v2realbot/ENTRY_backtest_strategyVykladaci.py +++ b/v2realbot/ENTRY_backtest_strategyVykladaci.py @@ -114,12 +114,15 @@ def next(data, state: StrategyState): #zaroven docasne menime ticks2reset na defenzivni 0.06 state.vars.ticks2reset = 0.06 state.ilog(e="DEF: Menime tick2reset na 0.06", ticks2reset=state.vars.ticks2reset, ticks2reset_backup=state.vars.ticks2reset_backup) + defense = True else: + defense = False #vracime zpet, pokud bylo zmeneno if state.vars.ticks2reset != state.vars.ticks2reset_backup: state.vars.ticks2reset = state.vars.ticks2reset_backup state.ilog(e="DEF: Menime tick2reset zpet na"+str(state.vars.ticks2reset), ticks2reset=state.vars.ticks2reset, ticks2reset_backup=state.vars.ticks2reset_backup) + if kolikmuzu < vykladka: vykladka = kolikmuzu if len(curve) < vykladka: @@ -131,9 +134,13 @@ def next(data, state: StrategyState): state.ilog(e="BUY Vykladame", msg=f"first price {price=} {vykladka=}", curve=curve, ema=state.indicators.ema[-1], trend=state.vars.Trend, price=price, vykladka=vykladka) ##prvni se vyklada na aktualni cenu, další jdou podle krivky, nula v krivce zvyšuje množství pro následující iteraci - ##VAR - na zaklade conf. muzeme jako prvni posilat MARKET + ##VAR - na zaklade conf. muzeme jako prvni posilat MARKET order if safe_get(state.vars, "first_buy_market") == True: - state.buy(size=qty) + #pri defenzivnim rezimu pouzivame vzdy LIMIT order + if defense: + state.buy_l(price=price, size=qty) + else: + state.buy(size=qty) else: state.buy_l(price=price, size=qty) print("prvni limitka na aktuální cenu. Další podle křivky", price, qty) diff --git a/v2realbot/__pycache__/config.cpython-310.pyc b/v2realbot/__pycache__/config.cpython-310.pyc index 43a4ca9..8a9750e 100644 Binary files a/v2realbot/__pycache__/config.cpython-310.pyc and b/v2realbot/__pycache__/config.cpython-310.pyc differ diff --git a/v2realbot/config.py b/v2realbot/config.py index 23d4f27..6e15f25 100644 --- a/v2realbot/config.py +++ b/v2realbot/config.py @@ -8,7 +8,7 @@ QUIET_MODE = False #0 - optimistic, every knot high will fill the order #N - N consecutive trades required #not impl.yet -#minimum is 1 +#minimum is 1, na alpace live to vetsinou vychazi 7-8 u BAC, je to hodne podobne tomu, nez je cena překonaná pul centu. tzn. 7-8 a nebo FillCondition.SLOW BT_FILL_CONS_TRADES_REQUIRED = 3 #during bt trade execution logs X-surrounding trades of the one that triggers the fill BT_FILL_LOG_SURROUNDING_TRADES = 10 diff --git a/v2realbot/strategy/StrategyOrderLimitVykladaci.py b/v2realbot/strategy/StrategyOrderLimitVykladaci.py index 8f6ae12..53bac50 100644 --- a/v2realbot/strategy/StrategyOrderLimitVykladaci.py +++ b/v2realbot/strategy/StrategyOrderLimitVykladaci.py @@ -59,7 +59,7 @@ class StrategyOrderLimitVykladaci(Strategy): self.state.vars.limitka = puvodni else: self.state.vars.limitka_price = cena - self.state.ilog(e="Příchozí BUY notif - menime limitku", msg=o.status, status=o.status, orderid=str(o.id), limitka=str(self.state.vars.limitka), limtka_price=self.state.vars.limitka_price, puvodni_limitka=str(puvodni)) + self.state.ilog(e="Příchozí BUY notif - menime limitku", msg=o.status, status=o.status, orderid=str(o.id), limitka=str(self.state.vars.limitka), limtka_price=self.state.vars.limitka_price, size=int(self.state.positions), puvodni_limitka=str(puvodni)) except APIError as e: self.state.ilog(e="API ERROR pri zmene limitky", msg=str(e), orderid=str(o.id), limitka=str(self.state.vars.limitka), limitka_price=self.state.vars.limitka_price, puvodni_limitka=str(puvodni)) @@ -80,19 +80,23 @@ class StrategyOrderLimitVykladaci(Strategy): #podle prumerne ceny, kolik stalo toto mnozstvi avg_costs = float(self.state.avgp) * float(data.qty) if avg_costs == 0: - self.state.ilog(e="Nemame naklady na PROFIT, AVGP je nula. Zaznamenano jako 0", msg="naklady=utrzena cena. TBD opravit.") + self.state.ilog(e="ERR: Nemame naklady na PROFIT, AVGP je nula. Zaznamenano jako 0", msg="naklady=utrzena cena. TBD opravit.") avg_costs = sold_amount trade_profit = (sold_amount - avg_costs) self.state.profit += trade_profit - self.state.ilog(e=f"SELL not - PROFIT:{round(float(trade_profit),3)} celkem:{round(float(self.state.profit),3)}", msg=str(data.event), sold_amount=sold_amount, avg_costs=avg_costs, trade_qty=data.qty, trade_price=data.price, orderid=str(data.order.id)) + self.state.ilog(e=f"SELL notif - PROFIT:{round(float(trade_profit),3)} celkem:{round(float(self.state.profit),3)}", msg=str(data.event), sold_amount=sold_amount, avg_costs=avg_costs, trade_qty=data.qty, trade_price=data.price, orderid=str(data.order.id)) - if data.event == TradeEvent.PARTIAL_FILL: - self.state.ilog(e="SELL notifikace - Partial fill", msg="pouze update pozic", orderid=str(data.order.id)) - #ic("partial fill jen udpatujeme pozice") - #TODO tento update mozna vyhodit a pockat vzdy na plny fill - otestovat az bude cas - self.state.avgp, self.state.positions = self.interface.pos() - elif data.event == TradeEvent.FILL or data.event == TradeEvent.CANCELED: + #update pozic, v trade update je i pocet zbylych pozic + old_avgp = self.state.avgp + old_pos = self.state.positions + self.state.positions = int(data.position_qty) + if int(data.position_qty) == 0: + self.state.avgp = 0 + self.state.ilog(e="SELL notifikace "+str(data.order.status), msg="update pozic", old_avgp=old_avgp, old_pos=old_pos, avgp=self.state.avgp, pos=self.state.positions, orderid=str(data.order.id)) + #self.state.avgp, self.state.positions = self.interface.pos() + + if data.event == TradeEvent.FILL or data.event == TradeEvent.CANCELED: print("Příchozí SELL notifikace - complete FILL nebo CANCEL", data.event) #muzeme znovu nakupovat, mazeme limitku, blockbuy a pendingbuys #self.state.blockbuy = 0 diff --git a/v2realbot/strategy/__pycache__/StrategyOrderLimitVykladaci.cpython-310.pyc b/v2realbot/strategy/__pycache__/StrategyOrderLimitVykladaci.cpython-310.pyc index 30e224a..d78b5eb 100644 Binary files a/v2realbot/strategy/__pycache__/StrategyOrderLimitVykladaci.cpython-310.pyc and b/v2realbot/strategy/__pycache__/StrategyOrderLimitVykladaci.cpython-310.pyc differ diff --git a/v2realbot/strategy/__pycache__/base.cpython-310.pyc b/v2realbot/strategy/__pycache__/base.cpython-310.pyc index 13e9b64..56b12a1 100644 Binary files a/v2realbot/strategy/__pycache__/base.cpython-310.pyc and b/v2realbot/strategy/__pycache__/base.cpython-310.pyc differ diff --git a/v2realbot/strategy/base.py b/v2realbot/strategy/base.py index 9bf8e7e..5c9cf49 100644 --- a/v2realbot/strategy/base.py +++ b/v2realbot/strategy/base.py @@ -318,6 +318,7 @@ class Strategy: now = self.bt.time print("NOTIFICATION ARRIVED AT:", now) + self.update_live_timenow() #pokud jde o FILL zapisujeme do self.trades a notifikujeme if data.event == TradeEvent.FILL: @@ -336,9 +337,14 @@ class Strategy: async def orderUpdateSell(self,data): print(data) + #pouze pro live a paper + def update_live_timenow(self): + if self.mode == Mode.LIVE or self.mode == Mode.PAPER: + self.state.time = datetime.now().timestamp() + ##method to override by child class. Allows to call specific code right before running next iteration. def before_iteration(self): - pass + self.update_live_timenow() ##kroky po iteraci def after_iteration(self, item):