diff --git a/v2realbot/__pycache__/config.cpython-310.pyc b/v2realbot/__pycache__/config.cpython-310.pyc index 62b8a15..7a5c5de 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 c82fabd..2665b4f 100644 --- a/v2realbot/config.py +++ b/v2realbot/config.py @@ -2,6 +2,7 @@ from alpaca.data.enums import DataFeed from v2realbot.enums.enums import Mode, Account from appdirs import user_data_dir +COUNT_API_REQUESTS = True STRATVARS_UNCHANGEABLES = ['pendingbuys', 'blockbuy', 'jevylozeno', 'limitka'] DATA_DIR = user_data_dir("v2realbot") #BT DELAYS diff --git a/v2realbot/interfaces/__pycache__/backtest_interface.cpython-310.pyc b/v2realbot/interfaces/__pycache__/backtest_interface.cpython-310.pyc index 3806770..4857509 100644 Binary files a/v2realbot/interfaces/__pycache__/backtest_interface.cpython-310.pyc and b/v2realbot/interfaces/__pycache__/backtest_interface.cpython-310.pyc differ diff --git a/v2realbot/interfaces/backtest_interface.py b/v2realbot/interfaces/backtest_interface.py index 28c7639..8a3a0e6 100644 --- a/v2realbot/interfaces/backtest_interface.py +++ b/v2realbot/interfaces/backtest_interface.py @@ -2,7 +2,9 @@ from alpaca.trading.enums import OrderSide, OrderType from threading import Lock from v2realbot.interfaces.general_interface import GeneralInterface from v2realbot.backtesting.backtester import Backtester -from v2realbot.config import BT_DELAYS +from v2realbot.config import BT_DELAYS, COUNT_API_REQUESTS +from datetime import datetime +from v2realbot.utils.utils import zoneNY """" backtester methods can be called @@ -17,49 +19,71 @@ class BacktestInterface(GeneralInterface): def __init__(self, symbol, bt: Backtester) -> None: self.symbol = symbol self.bt = bt + self.count_api_requests = COUNT_API_REQUESTS + self.mincnt = list([dict(minute=0,count=0)]) #TODO time v API nejspis muzeme dat pryc a BT bude si to brat primo ze self.time (nezapomenout na + BT_DELAYS) # self.time = self.bt.time + #pocita pocet api requestu za minutu + def count(self): + if self.count_api_requests: + #get minute od the day + now = datetime.fromtimestamp(self.bt.time).astimezone(zoneNY) + dayminute = now.hour*60 + now.minute + if self.mincnt[-1]["minute"] == dayminute: + self.mincnt[-1]["count"] += 1 + else: + self.mincnt.append(dict(minute=dayminute, count=1)) + """initial checks.""" def start_checks(self): print("start_checks") """buy market""" def buy(self, size = 1, repeat: bool = False): + self.count() #add REST API latency return self.bt.submit_order(time=self.bt.time + BT_DELAYS.strat_to_sub,symbol=self.symbol,side=OrderSide.BUY,size=size,order_type = OrderType.MARKET) """buy limit""" def buy_l(self, price: float, size: int = 1, repeat: bool = False, force: int = 0): + self.count() return self.bt.submit_order(time=self.bt.time + BT_DELAYS.strat_to_sub,symbol=self.symbol,side=OrderSide.BUY,size=size,price=price,order_type = OrderType.LIMIT) """sell market""" def sell(self, size = 1, repeat: bool = False): + self.count() return self.bt.submit_order(time=self.bt.time + BT_DELAYS.strat_to_sub,symbol=self.symbol,side=OrderSide.SELL,size=size,order_type = OrderType.MARKET) """sell limit""" async def sell_l(self, price: float, size = 1, repeat: bool = False): + self.count() return self.bt.submit_order(time=self.bt.time + BT_DELAYS.strat_to_sub,symbol=self.symbol,side=OrderSide.SELL,size=size,price=price,order_type = OrderType.LIMIT) """replace order""" async def repl(self, orderid: str, price: float = None, size: int = None, repeat: bool = False): + self.count() return self.bt.replace_order(time=self.bt.time + BT_DELAYS.strat_to_sub,id=orderid,size=size,price=price) """cancel order""" #TBD exec predtim? def cancel(self, orderid: str): + self.count() return self.bt.cancel_order(time=self.bt.time + BT_DELAYS.strat_to_sub, id=orderid) """get positions ->(size,avgp)""" #TBD exec predtim? def pos(self): + self.count() return self.bt.get_open_position(symbol=self.symbol) """get open orders ->list(Order)""" def get_open_orders(self, side: OrderSide, symbol: str): + self.count() return self.bt.get_open_orders(side=side, symbol=symbol) def get_last_price(self, symbol: str): + self.count() return self.bt.get_last_price(time=self.bt.time) diff --git a/v2realbot/interfaces/live_interface.py b/v2realbot/interfaces/live_interface.py index 180d6a7..46e29d3 100644 --- a/v2realbot/interfaces/live_interface.py +++ b/v2realbot/interfaces/live_interface.py @@ -167,8 +167,8 @@ class LiveInterface(GeneralInterface): return -1 """get open orders ->list(Order)""" - def get_open_orders(self, side: OrderSide, symbol: str): # -> list(Order): - getRequest = GetOrdersRequest(status=QueryOrderStatus.OPEN, side=OrderSide.SELL, symbols=[symbol]) + def get_open_orders(self, symbol: str, side: OrderSide = OrderSide.SELL): # -> list(Order): + getRequest = GetOrdersRequest(status=QueryOrderStatus.OPEN, side=side, symbols=[symbol]) try: # Market order submit orderlist = self.trading_client.get_orders(getRequest) diff --git a/v2realbot/main.py b/v2realbot/main.py index 0cf90d0..5ecc708 100644 --- a/v2realbot/main.py +++ b/v2realbot/main.py @@ -31,7 +31,7 @@ ic.configureOutput(includeContext=True) def threadName(): return '%s |> ' % str(current_thread().name) ic.configureOutput(prefix=threadName) -#ic.disable() +ic.disable() """"" Main entry point of the bot. Starts strategies according to config file, each in separate thread. diff --git a/v2realbot/static/index.html b/v2realbot/static/index.html index 9f1a47c..ef6bb27 100644 --- a/v2realbot/static/index.html +++ b/v2realbot/static/index.html @@ -60,7 +60,7 @@