consolidation process added
This commit is contained in:
46
testy/moduleTests/backtestInterfaceTest.py
Normal file
46
testy/moduleTests/backtestInterfaceTest.py
Normal file
@ -0,0 +1,46 @@
|
||||
from v2realbot.config import Keys, get_key
|
||||
from v2realbot.enums.enums import Mode, Account, OrderSide
|
||||
from alpaca.trading.enums import OrderSide, OrderStatus, TradeEvent, OrderType
|
||||
from v2realbot.common.model import TradeUpdate, Order
|
||||
from v2realbot.interfaces.live_interface import LiveInterface
|
||||
from v2realbot.interfaces.backtest_interface import BacktestInterface
|
||||
from v2realbot.backtesting.backtester import Backtester
|
||||
from datetime import datetime
|
||||
from v2realbot.utils.utils import zoneNY
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
def callback():
|
||||
print("callback entry")
|
||||
|
||||
|
||||
start = datetime(2023, 4, 10, 9, 30, 0, 0, tzinfo=zoneNY)
|
||||
end = datetime(2023, 4, 10, 9, 35, 0, 0, tzinfo=zoneNY)
|
||||
btdata: list = []
|
||||
cash=10000
|
||||
#key = get_key(mode=Mode.PAPER, account=Account.ACCOUNT1)
|
||||
symbol = "BAC"
|
||||
|
||||
bt = Backtester(symbol = symbol, order_fill_callback= callback, btdata=btdata, cash=cash, bp_from=start, bp_to=end)
|
||||
|
||||
bt.open_orders = [Order(id=uuid4(),
|
||||
submitted_at = datetime(2023, 3, 17, 9, 30, 0, 0, tzinfo=zoneNY),
|
||||
symbol = "BAC",
|
||||
qty = 1,
|
||||
status = OrderStatus.ACCEPTED,
|
||||
order_type = OrderType.LIMIT,
|
||||
side = OrderSide.SELL,
|
||||
limit_price=22.4),
|
||||
Order(id=uuid4(),
|
||||
submitted_at = datetime(2023, 3, 17, 9, 30, 00, 0, tzinfo=zoneNY),
|
||||
symbol = "BAC",
|
||||
qty = 1,
|
||||
order_type = OrderType.MARKET,
|
||||
status = OrderStatus.ACCEPTED,
|
||||
side = OrderSide.BUY)]
|
||||
|
||||
bt_interface = BacktestInterface(symbol=symbol, bt=bt)
|
||||
|
||||
orderlist = bt.get_open_orders(symbol=symbol, side=None)
|
||||
|
||||
print(orderlist)
|
||||
print(len(orderlist))
|
||||
57
testy/moduleTests/liveInterfaceTest.py
Normal file
57
testy/moduleTests/liveInterfaceTest.py
Normal file
@ -0,0 +1,57 @@
|
||||
from v2realbot.config import Keys, get_key
|
||||
from v2realbot.enums.enums import Mode, Account, OrderSide
|
||||
from v2realbot.interfaces.live_interface import LiveInterface
|
||||
from msgpack import packb, unpackb
|
||||
key = get_key(mode=Mode.PAPER, account=Account.ACCOUNT1)
|
||||
symbol = "BAC"
|
||||
li = LiveInterface(symbol=symbol, key=key)
|
||||
|
||||
|
||||
##tady jsem skoncil - otestovat tento kod na variantach
|
||||
# pendinbuys na PAPER
|
||||
#pak dat do Vykladaci ENTRY a otestovat i na BT
|
||||
data = {}
|
||||
data["index"] = 30
|
||||
consolidation_bar_count = 10
|
||||
pendingbuys = {'22dd3fe21-2c61-4ddd-b7df-cbdb3c1f7b79': '29.63', 'fe7b4baa-ef61-4867-b111-b1c3fc016dce': '29.59', '40253d42-bc00-4476-8f7a-28449fc00080': '29.57'}
|
||||
|
||||
##konzolidace kazdy Nty bar dle nastaveni
|
||||
if int(data["index"])%int(consolidation_bar_count) == 0:
|
||||
print("***Consolidation ENTRY***")
|
||||
|
||||
orderlist = li.get_open_orders(symbol=symbol, side=None)
|
||||
#print(orderlist)
|
||||
pendingbuys_new = {}
|
||||
limitka = None
|
||||
jevylozeno = 1
|
||||
for o in orderlist:
|
||||
if o.side == OrderSide.SELL:
|
||||
print("Puvodni LIMITKA", limitka)
|
||||
limitka = o.id
|
||||
print("Přepsaná LIMITKA", limitka)
|
||||
if o.side == OrderSide.BUY:
|
||||
pendingbuys_new[str(o.id)]=o.limit_price
|
||||
|
||||
if pendingbuys_new != pendingbuys:
|
||||
print("ROZDILNA PENDINGBUYS přepsána")
|
||||
print("OLD",pendingbuys)
|
||||
pendingbuys = unpackb(packb(pendingbuys_new))
|
||||
print("NEW", pendingbuys)
|
||||
print("OLD jevylozeno",jevylozeno)
|
||||
if len(pendingbuys) > 0:
|
||||
jevylozeno = 1
|
||||
else:
|
||||
jevylozeno = 0
|
||||
print("NEW jevylozeno",jevylozeno)
|
||||
|
||||
#print(limitka)
|
||||
#print(pendingbuys_new)
|
||||
#print(pendingbuys)
|
||||
#print(len(pendingbuys))
|
||||
#print(len(pendingbuys_new))
|
||||
#print(jevylozeno)
|
||||
print("***CONSOLIDATION EXIT***")
|
||||
|
||||
else:
|
||||
print("no time for consolidation", data["index"])
|
||||
|
||||
Reference in New Issue
Block a user