bugfixy + update time now
This commit is contained in:
@ -114,12 +114,15 @@ def next(data, state: StrategyState):
|
|||||||
#zaroven docasne menime ticks2reset na defenzivni 0.06
|
#zaroven docasne menime ticks2reset na defenzivni 0.06
|
||||||
state.vars.ticks2reset = 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)
|
state.ilog(e="DEF: Menime tick2reset na 0.06", ticks2reset=state.vars.ticks2reset, ticks2reset_backup=state.vars.ticks2reset_backup)
|
||||||
|
defense = True
|
||||||
else:
|
else:
|
||||||
|
defense = False
|
||||||
#vracime zpet, pokud bylo zmeneno
|
#vracime zpet, pokud bylo zmeneno
|
||||||
if state.vars.ticks2reset != state.vars.ticks2reset_backup:
|
if state.vars.ticks2reset != state.vars.ticks2reset_backup:
|
||||||
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)
|
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 kolikmuzu < vykladka: vykladka = kolikmuzu
|
||||||
|
|
||||||
if len(curve) < vykladka:
|
if len(curve) < vykladka:
|
||||||
@ -131,8 +134,12 @@ 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)
|
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
|
##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:
|
if safe_get(state.vars, "first_buy_market") == True:
|
||||||
|
#pri defenzivnim rezimu pouzivame vzdy LIMIT order
|
||||||
|
if defense:
|
||||||
|
state.buy_l(price=price, size=qty)
|
||||||
|
else:
|
||||||
state.buy(size=qty)
|
state.buy(size=qty)
|
||||||
else:
|
else:
|
||||||
state.buy_l(price=price, size=qty)
|
state.buy_l(price=price, size=qty)
|
||||||
|
|||||||
Binary file not shown.
@ -8,7 +8,7 @@ QUIET_MODE = False
|
|||||||
#0 - optimistic, every knot high will fill the order
|
#0 - optimistic, every knot high will fill the order
|
||||||
#N - N consecutive trades required
|
#N - N consecutive trades required
|
||||||
#not impl.yet
|
#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
|
BT_FILL_CONS_TRADES_REQUIRED = 3
|
||||||
#during bt trade execution logs X-surrounding trades of the one that triggers the fill
|
#during bt trade execution logs X-surrounding trades of the one that triggers the fill
|
||||||
BT_FILL_LOG_SURROUNDING_TRADES = 10
|
BT_FILL_LOG_SURROUNDING_TRADES = 10
|
||||||
|
|||||||
@ -59,7 +59,7 @@ class StrategyOrderLimitVykladaci(Strategy):
|
|||||||
self.state.vars.limitka = puvodni
|
self.state.vars.limitka = puvodni
|
||||||
else:
|
else:
|
||||||
self.state.vars.limitka_price = cena
|
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:
|
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))
|
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
|
#podle prumerne ceny, kolik stalo toto mnozstvi
|
||||||
avg_costs = float(self.state.avgp) * float(data.qty)
|
avg_costs = float(self.state.avgp) * float(data.qty)
|
||||||
if avg_costs == 0:
|
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
|
avg_costs = sold_amount
|
||||||
|
|
||||||
trade_profit = (sold_amount - avg_costs)
|
trade_profit = (sold_amount - avg_costs)
|
||||||
self.state.profit += trade_profit
|
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:
|
#update pozic, v trade update je i pocet zbylych pozic
|
||||||
self.state.ilog(e="SELL notifikace - Partial fill", msg="pouze update pozic", orderid=str(data.order.id))
|
old_avgp = self.state.avgp
|
||||||
#ic("partial fill jen udpatujeme pozice")
|
old_pos = self.state.positions
|
||||||
#TODO tento update mozna vyhodit a pockat vzdy na plny fill - otestovat az bude cas
|
self.state.positions = int(data.position_qty)
|
||||||
self.state.avgp, self.state.positions = self.interface.pos()
|
if int(data.position_qty) == 0:
|
||||||
elif data.event == TradeEvent.FILL or data.event == TradeEvent.CANCELED:
|
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)
|
print("Příchozí SELL notifikace - complete FILL nebo CANCEL", data.event)
|
||||||
#muzeme znovu nakupovat, mazeme limitku, blockbuy a pendingbuys
|
#muzeme znovu nakupovat, mazeme limitku, blockbuy a pendingbuys
|
||||||
#self.state.blockbuy = 0
|
#self.state.blockbuy = 0
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@ -318,6 +318,7 @@ class Strategy:
|
|||||||
now = self.bt.time
|
now = self.bt.time
|
||||||
|
|
||||||
print("NOTIFICATION ARRIVED AT:", now)
|
print("NOTIFICATION ARRIVED AT:", now)
|
||||||
|
self.update_live_timenow()
|
||||||
|
|
||||||
#pokud jde o FILL zapisujeme do self.trades a notifikujeme
|
#pokud jde o FILL zapisujeme do self.trades a notifikujeme
|
||||||
if data.event == TradeEvent.FILL:
|
if data.event == TradeEvent.FILL:
|
||||||
@ -336,9 +337,14 @@ class Strategy:
|
|||||||
async def orderUpdateSell(self,data):
|
async def orderUpdateSell(self,data):
|
||||||
print(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.
|
##method to override by child class. Allows to call specific code right before running next iteration.
|
||||||
def before_iteration(self):
|
def before_iteration(self):
|
||||||
pass
|
self.update_live_timenow()
|
||||||
|
|
||||||
##kroky po iteraci
|
##kroky po iteraci
|
||||||
def after_iteration(self, item):
|
def after_iteration(self, item):
|
||||||
|
|||||||
Reference in New Issue
Block a user