funkcni vterinovky bez vychytavek

This commit is contained in:
David Brazda
2023-04-14 22:34:45 +02:00
parent 12ee30112f
commit 2a9ed56fca
10 changed files with 34 additions and 8 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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.

View File

@ -60,7 +60,7 @@
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"><i class="fa fa-plus"></i> Stop Strategy</h4>
<h4 class="modal-title_stop"><i class="fa fa-plus"></i> Stop Strategy</h4>
</div>
<div class="modal-body">
<div class="form-group">
@ -176,7 +176,7 @@
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"><i class="fa fa-plus"></i> Delete Record</h4>
<h4 class="modal-title_del"><i class="fa fa-plus"></i> Delete Record</h4>
</div>
<div class="modal-body">
<div class="form-group">
@ -198,7 +198,7 @@
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"><i class="fa fa-plus"></i> Run strategy</h4>
<h4 class="modal-title_run"><i class="fa fa-plus"></i> Run strategy</h4>
</div>
<div class="modal-body">
<div class="form-group">

View File

@ -228,7 +228,6 @@ $(document).ready(function () {
row = stratinRecords.row('.selected').data();
window.$('#delModal').modal('show');
$('#delid').val(row.id);
$('.modal-title').html(" Delete Record");
$('#action').val('delRecord');
$('#save').val('Delete');

View File

@ -261,6 +261,8 @@ class Strategy:
self.stop()
if self.mode == Mode.BT:
print("REQUEST COUNT:", self.interface.mincnt)
self.bt.backtest_end = datetime.now()
print(40*"*",self.mode, "BACKTEST RESULTS",40*"*")
#-> account, cash,trades,open_orders