diff --git a/v2realbot/ENTRY_backtest_strategyVykladaci.py b/v2realbot/ENTRY_backtest_strategyVykladaci.py index 9e031af..cdbd707 100644 --- a/v2realbot/ENTRY_backtest_strategyVykladaci.py +++ b/v2realbot/ENTRY_backtest_strategyVykladaci.py @@ -222,10 +222,13 @@ def next(data, state: StrategyState): if state.vars.jevylozeno == 1: ##CONSOLIDATION PART kazdy Nty bar dle nastaveni if int(data["index"])%int(state.vars.consolidation_bar_count) == 0: - print("***Consolidation ENTRY***") - state.ilog(e="***Konzolidujeme") + print("***CONSOLIDATION ENTRY***") + state.ilog(e="CONSOLIDATION ENTRY ***") orderlist = state.interface.get_open_orders(symbol=state.symbol, side=None) + #pro jistotu jeste dotahneme aktualni pozice + state.avgp, state.positions = state.interface.pos() + #print(orderlist) pendingbuys_new = {} limitka_old = state.vars.limitka @@ -254,18 +257,28 @@ def next(data, state: StrategyState): price=price2dec(float(state.avgp)+state.vars.profit) state.vars.limitka = asyncio.run(state.interface.sell_l(price=price, size=state.positions)) state.vars.limitka_price = price - state.ilog(e="Vytvořena nová limitka", limitka=str(state.vars.limitka), limtka_price=state.vars.limitka_price) + if state.vars.limitka == -1: + state.ilog(e="Vytvoreni limitky neprobehlo, vracime None", msg=str(state.vars.limitka)) + state.vars.limitka = None + state.vars.limitka_price = None + else: + state.ilog(e="Vytvořena nová limitka", limitka=str(state.vars.limitka), limtka_price=state.vars.limitka_price) - if int(state.positions) > 0 and (int(state.positions) != int(limitka_qty)): + elif state.vars.limitka is not None and int(state.positions) > 0 and (int(state.positions) != int(limitka_qty)): #limitka existuje, ale spatne mnostvi - updatujeme state.ilog(e="Limitka existuje, ale spatne mnozstvi - updatujeme", msg="POS"+str(state.positions)+" lim_qty:"+str(limitka_qty), pos=state.positions, limitka_qty=limitka_qty) #snad to nespadne, kdyztak pridat exception handling + puvodni = state.vars.limitka state.vars.limitka = asyncio.run(state.interface.repl(price=state.vars.limitka_price, orderid=state.vars.limitka, size=int(state.positions))) - limitka_qty = int(state.positions) - state.ilog(e="Změněna limitka", limitka=str(state.vars.limitka), limitka_price=state.vars.limitka_price, limitka_qty=limitka_qty) - - #dodelat limitka existuje, ale spatne + + if state.vars.limitka == -1: + state.ilog(e="Replace limitky neprobehl, vracime puvodni", msg=str(state.vars.limitka), puvodni=puvodni) + state.vars.limitka = puvodni + else: + limitka_qty = int(state.positions) + state.ilog(e="Změněna limitka", limitka=str(state.vars.limitka), limitka_price=state.vars.limitka_price, limitka_qty=limitka_qty) + #tbd pokud se bude vyskytovat pak pridat ještě konzolidaci ceny limitky if pendingbuys_new != state.vars.pendingbuys: state.ilog(e="Rozdilna PB prepsana", pb_new=pendingbuys_new, pb_old = state.vars.pendingbuys) @@ -291,15 +304,14 @@ def next(data, state: StrategyState): #print(len(pendingbuys_new)) #print(jevylozeno) print("***CONSOLIDATION EXIT***") - state.ilog(e="***Konzolidace konec") + state.ilog(e="CONSOLIDATION EXIT ***") else: state.ilog(e="No time for consolidation", msg=data["index"]) print("no time for consolidation", data["index"]) #HLAVNI ITERACNI LOG JESTE PRED AKCI - obsahuje aktualni hodnoty vetsiny parametru lp = state.interface.get_last_price(symbol=state.symbol) - state.ilog(e="ENTRY", msg="AVGP:"+str(state.avgp)+ "POS:" +str(state.positions), last_price=lp, stratvars=state.vars) - + state.ilog(e="ENTRY", msg="AVGP:"+str(round(state.avgp,2))+ "POS:" +str(state.positions)+" PROFIT:"+str(round(state.profit,2)), last_price=lp, stratvars=state.vars) #maxSlopeMA = -0.03 #SLOPE ANGLE PROTECTIONs diff --git a/v2realbot/__pycache__/config.cpython-310.pyc b/v2realbot/__pycache__/config.cpython-310.pyc index 8264042..aa6c4a1 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 b6ec2f7..6f07067 100644 --- a/v2realbot/config.py +++ b/v2realbot/config.py @@ -2,8 +2,11 @@ from alpaca.data.enums import DataFeed from v2realbot.enums.enums import Mode, Account from appdirs import user_data_dir +#no print in console QUIET_MODE = False +#backend counter of api requests COUNT_API_REQUESTS = False +#stratvars that cannot be changed in gui STRATVARS_UNCHANGEABLES = ['pendingbuys', 'blockbuy', 'jevylozeno', 'limitka'] DATA_DIR = user_data_dir("v2realbot") #BT DELAYS diff --git a/v2realbot/interfaces/__pycache__/live_interface.cpython-310.pyc b/v2realbot/interfaces/__pycache__/live_interface.cpython-310.pyc index aa7f84b..7cbdf74 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/static/js/mywebsocket.js b/v2realbot/static/js/mywebsocket.js index 1c8d7ba..555f349 100644 --- a/v2realbot/static/js/mywebsocket.js +++ b/v2realbot/static/js/mywebsocket.js @@ -41,7 +41,7 @@ function connect(event) { } if (parsed_data.hasOwnProperty("bars")) { - console.log("mame bary") + // console.log("mame bary") var bar = parsed_data.bars candlestickSeries.update(bar); volumeSeries.update({ @@ -173,24 +173,24 @@ function connect(event) { } if (parsed_data.hasOwnProperty("statinds")) { - console.log("got static indicators") + // console.log("got static indicators") var statinds = parsed_data.statinds if (Object.keys(statinds).length > 0) { - console.log("got static indicators") - console.log(JSON.stringify(statinds)) + // console.log("got static indicators") + // console.log(JSON.stringify(statinds)) for (const [klic, hodnota] of Object.entries(statinds)) { - console.log(JSON.stringify(klic)) - console.log(JSON.stringify(hodnota)) + // console.log(JSON.stringify(klic)) + // console.log(JSON.stringify(hodnota)) //TODO predelat na configuracni klice vizualizacni dotahovane z backendu, ktere namapuji vybrane stratvars na typ vizualizace if (klic === "angle") { //nejsou vsechny hodnoty if (Object.keys(hodnota).length > 0) { - console.log("angle nalezen"); - console.log(JSON.stringify(hodnota)); + // console.log("angle nalezen"); + // console.log(JSON.stringify(hodnota)); if (angleSeries !== 1) { - console.log("angle neni jedna" + toString(angleSeries)) + // console.log("angle neni jedna" + toString(angleSeries)) chart.removeSeries(angleSeries) } @@ -200,11 +200,13 @@ function connect(event) { lineStyle: 2, color: "#d432e6", lastValueVisible: false, - priceLineVisible: false + priceLineVisible: false, + priceLineWidth: 0, + priceLineStyle: 3 }) dataPoints = [{time: hodnota.lookbacktime, value: hodnota.lookbackprice},{ time: hodnota.time, value: hodnota.price}] - console.log("pridano") - console.log(toString(dataPoints)) + // console.log("pridano") + // console.log(toString(dataPoints)) angleSeries.setData(dataPoints) } } @@ -222,7 +224,7 @@ function connect(event) { } if (parsed_data.hasOwnProperty("indicators")) { - console.log("jsme uvnitr indikatoru") + // console.log("jsme uvnitr indikatoru") var indicators = parsed_data.indicators //if there are indicators it means there must be at least two keys (except time which is always present) if (Object.keys(indicators).length > 1) { diff --git a/v2realbot/static/main.css b/v2realbot/static/main.css index 3ef09c1..8421371 100644 --- a/v2realbot/static/main.css +++ b/v2realbot/static/main.css @@ -34,7 +34,7 @@ } #msgContainer { - display: inline-block; + /* display: inline-block; */ overflow: auto; height: 568px; } diff --git a/v2realbot/strategy/StrategyOrderLimitVykladaci.py b/v2realbot/strategy/StrategyOrderLimitVykladaci.py index c490bdb..d1e7fe7 100644 --- a/v2realbot/strategy/StrategyOrderLimitVykladaci.py +++ b/v2realbot/strategy/StrategyOrderLimitVykladaci.py @@ -26,7 +26,7 @@ class StrategyOrderLimitVykladaci(Strategy): self.state.ilog(e="Příchozí BUY notifikace - mazeme ji z pb", msg="order status:"+o.status, orderid=str(o.id), pb=self.state.vars.pendingbuys) print("limit buy filled or cancelled. Vyhazujeme z pendingbuys.") ic(self.state.vars.pendingbuys) - + if data.event == TradeEvent.FILL or data.event == TradeEvent.PARTIAL_FILL: ic("vstupujeme do orderupdatebuy") print(data) @@ -67,6 +67,18 @@ class StrategyOrderLimitVykladaci(Strategy): raise Exception(e) async def orderUpdateSell(self, data: TradeUpdate): + + #PROFIT + #profit pocitame z TradeUpdate.price a TradeUpdate.qty - aktualne provedene mnozstvi a cena + #naklady vypocteme z prumerne ceny, kterou mame v pozicich + if data.event == TradeEvent.FILL or data.event == TradeEvent.PARTIAL_FILL: + sold_amount = data.qty * data.price + #podle prumerne ceny, kolik stalo toto mnozstvi + avg_costs = self.state.avgp * data.qty + trade_profit = (sold_amount - avg_costs) + self.state.profit += trade_profit + self.state.ilog(e="SELL not - PROFIT: "+str(round(trade_profit,3))+" celkem: "+str(round(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") @@ -77,10 +89,6 @@ class StrategyOrderLimitVykladaci(Strategy): #muzeme znovu nakupovat, mazeme limitku, blockbuy a pendingbuys #self.state.blockbuy = 0 - #ADDPROFIT - datd o funkce, zatim vraci chybu - #prodej = data.order.filled_qty * data.order.filled_avg_price - #nakup = self.state.positions - ic("notifikace sell mazeme limitku a update pozic") #updatujeme pozice self.state.avgp, self.state.positions = self.interface.pos() diff --git a/v2realbot/strategy/__pycache__/StrategyOrderLimitVykladaci.cpython-310.pyc b/v2realbot/strategy/__pycache__/StrategyOrderLimitVykladaci.cpython-310.pyc index 58a26e8..469eb00 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 dc78ba9..4f9323d 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 7ce66eb..499483e 100644 --- a/v2realbot/strategy/base.py +++ b/v2realbot/strategy/base.py @@ -5,7 +5,7 @@ from datetime import datetime from v2realbot.utils.utils import AttributeDict, zoneNY, is_open_rush, is_close_rush, json_serial, print from v2realbot.utils.tlog import tlog from v2realbot.enums.enums import RecordType, StartBarAlign, Mode, Order, Account -from v2realbot.config import BT_DELAYS, get_key, HEARTBEAT_TIMEOUT +from v2realbot.config import BT_DELAYS, get_key, HEARTBEAT_TIMEOUT, QUIET_MODE import queue #from rich import print from v2realbot.loader.aggregator import TradeAggregator2Queue, TradeAggregator2List, TradeAggregator @@ -48,7 +48,6 @@ class Strategy: self.account = account self.key = get_key(mode=self.mode, account=self.account) self.rtqueue = None - self.profit = 0 #TODO predelat na dynamické queues @@ -495,10 +494,12 @@ class StrategyState: self.sell_l = self.interface.sell_l self.cancel_pending_buys = None self.iter_log_list = [] + self.profit = 0 def ilog(self, e: str = None, msg: str = None, **kwargs): if e is None: row = dict(time=self.time, message=msg, details=kwargs) else: row = dict(time=self.time, event=e, message=msg, details=kwargs) - self.iter_log_list.append(row) \ No newline at end of file + self.iter_log_list.append(row) + print(row) diff --git a/v2realbot/utils/__pycache__/utils.cpython-310.pyc b/v2realbot/utils/__pycache__/utils.cpython-310.pyc index 1985ba1..8781759 100644 Binary files a/v2realbot/utils/__pycache__/utils.cpython-310.pyc and b/v2realbot/utils/__pycache__/utils.cpython-310.pyc differ