Merge branch 'binance' into binance_gateway_0611
This commit is contained in:
commit
2611e84393
223
tests/backtesting/backtesting_portfolio.ipynb
Normal file
223
tests/backtesting/backtesting_portfolio.ipynb
Normal file
File diff suppressed because one or more lines are too long
@ -3,29 +3,29 @@ from vnpy.event import EventEngine
|
||||
from vnpy.trader.engine import MainEngine
|
||||
from vnpy.trader.ui import MainWindow, create_qapp
|
||||
|
||||
# from vnpy.gateway.bitmex import BitmexGateway
|
||||
# from vnpy.gateway.futu import FutuGateway
|
||||
# from vnpy.gateway.ib import IbGateway
|
||||
# from vnpy.gateway.ctp import CtpGateway
|
||||
# # from vnpy.gateway.ctptest import CtptestGateway
|
||||
# from vnpy.gateway.femas import FemasGateway
|
||||
# from vnpy.gateway.tiger import TigerGateway
|
||||
# from vnpy.gateway.oes import OesGateway
|
||||
# from vnpy.gateway.okex import OkexGateway
|
||||
# from vnpy.gateway.huobi import HuobiGateway
|
||||
# from vnpy.gateway.bitfinex import BitfinexGateway
|
||||
# from vnpy.gateway.onetoken import OnetokenGateway
|
||||
# from vnpy.gateway.okexf import OkexfGateway
|
||||
# from vnpy.gateway.xtp import XtpGateway
|
||||
from vnpy.gateway.hbdm import HbdmGateway
|
||||
# from vnpy.gateway.tap import TapGateway
|
||||
from vnpy.gateway.binance import BinanceGateway
|
||||
#from vnpy.gateway.bitmex import BitmexGateway
|
||||
#from vnpy.gateway.futu import FutuGateway
|
||||
#from vnpy.gateway.ib import IbGateway
|
||||
#from vnpy.gateway.ctp import CtpGateway
|
||||
# from vnpy.gateway.ctptest import CtptestGateway
|
||||
#from vnpy.gateway.femas import FemasGateway
|
||||
#from vnpy.gateway.tiger import TigerGateway
|
||||
#from vnpy.gateway.oes import OesGateway
|
||||
#from vnpy.gateway.okex import OkexGateway
|
||||
#from vnpy.gateway.huobi import HuobiGateway
|
||||
#from vnpy.gateway.bitfinex import BitfinexGateway
|
||||
#from vnpy.gateway.onetoken import OnetokenGateway
|
||||
#from vnpy.gateway.okexf import OkexfGateway
|
||||
#from vnpy.gateway.xtp import XtpGateway
|
||||
#from vnpy.gateway.hbdm import HbdmGateway
|
||||
|
||||
# from vnpy.app.cta_strategy import CtaStrategyApp
|
||||
# from vnpy.app.csv_loader import CsvLoaderApp
|
||||
# from vnpy.app.algo_trading import AlgoTradingApp
|
||||
# from vnpy.app.cta_backtester import CtaBacktesterApp
|
||||
# from vnpy.app.data_recorder import DataRecorderApp
|
||||
# from vnpy.app.risk_manager import RiskManagerApp
|
||||
#from vnpy.app.cta_strategy import CtaStrategyApp
|
||||
#from vnpy.app.csv_loader import CsvLoaderApp
|
||||
#from vnpy.app.algo_trading import AlgoTradingApp
|
||||
#from vnpy.app.cta_backtester import CtaBacktesterApp
|
||||
#from vnpy.app.data_recorder import DataRecorderApp
|
||||
#from vnpy.app.risk_manager import RiskManagerApp
|
||||
|
||||
|
||||
def main():
|
||||
@ -35,29 +35,30 @@ def main():
|
||||
event_engine = EventEngine()
|
||||
|
||||
main_engine = MainEngine(event_engine)
|
||||
# main_engine.add_gateway(XtpGateway)
|
||||
# main_engine.add_gateway(CtpGateway)
|
||||
# # main_engine.add_gateway(CtptestGateway)
|
||||
# main_engine.add_gateway(FemasGateway)
|
||||
# main_engine.add_gateway(IbGateway)
|
||||
# main_engine.add_gateway(FutuGateway)
|
||||
# main_engine.add_gateway(BitmexGateway)
|
||||
# main_engine.add_gateway(TigerGateway)
|
||||
# main_engine.add_gateway(OesGateway)
|
||||
# main_engine.add_gateway(OkexGateway)
|
||||
# main_engine.add_gateway(HuobiGateway)
|
||||
# main_engine.add_gateway(BitfinexGateway)
|
||||
# main_engine.add_gateway(OnetokenGateway)
|
||||
# main_engine.add_gateway(OkexfGateway)
|
||||
main_engine.add_gateway(HbdmGateway)
|
||||
# main_engine.add_gateway(TapGateway)
|
||||
|
||||
# main_engine.add_app(CtaStrategyApp)
|
||||
# main_engine.add_app(CtaBacktesterApp)
|
||||
# main_engine.add_app(CsvLoaderApp)
|
||||
# main_engine.add_app(AlgoTradingApp)
|
||||
# main_engine.add_app(DataRecorderApp)
|
||||
# main_engine.add_app(RiskManagerApp)
|
||||
main_engine.add_gateway(BinanceGateway)
|
||||
#main_engine.add_gateway(XtpGateway)
|
||||
#main_engine.add_gateway(CtpGateway)
|
||||
# main_engine.add_gateway(CtptestGateway)
|
||||
#main_engine.add_gateway(FemasGateway)
|
||||
#main_engine.add_gateway(IbGateway)
|
||||
#main_engine.add_gateway(FutuGateway)
|
||||
#main_engine.add_gateway(BitmexGateway)
|
||||
#main_engine.add_gateway(TigerGateway)
|
||||
#main_engine.add_gateway(OesGateway)
|
||||
#main_engine.add_gateway(OkexGateway)
|
||||
#main_engine.add_gateway(HuobiGateway)
|
||||
#main_engine.add_gateway(BitfinexGateway)
|
||||
#main_engine.add_gateway(OnetokenGateway)
|
||||
#main_engine.add_gateway(OkexfGateway)
|
||||
#main_engine.add_gateway(HbdmGateway)
|
||||
|
||||
#main_engine.add_app(CtaStrategyApp)
|
||||
#main_engine.add_app(CtaBacktesterApp)
|
||||
#main_engine.add_app(CsvLoaderApp)
|
||||
#main_engine.add_app(AlgoTradingApp)
|
||||
#main_engine.add_app(DataRecorderApp)
|
||||
#main_engine.add_app(RiskManagerApp)
|
||||
|
||||
main_window = MainWindow(main_engine, event_engine)
|
||||
main_window.showMaximized()
|
||||
|
@ -330,9 +330,11 @@ class BacktestingEngine:
|
||||
""""""
|
||||
self.output("开始计算策略统计指标")
|
||||
|
||||
if not df:
|
||||
# Check DataFrame input exterior
|
||||
if df is None:
|
||||
df = self.daily_df
|
||||
|
||||
# Check for init DataFrame
|
||||
if df is None:
|
||||
# Set all statistics to 0 if no trade.
|
||||
start_date = ""
|
||||
@ -476,9 +478,11 @@ class BacktestingEngine:
|
||||
|
||||
def show_chart(self, df: DataFrame = None):
|
||||
""""""
|
||||
if not df:
|
||||
# Check DataFrame input exterior
|
||||
if df is None:
|
||||
df = self.daily_df
|
||||
|
||||
|
||||
# Check for init DataFrame
|
||||
if df is None:
|
||||
return
|
||||
|
||||
|
@ -348,6 +348,7 @@ class BinanceRestApi(RestClient):
|
||||
data=data,
|
||||
extra=req
|
||||
)
|
||||
|
||||
print("撤单本地id:", req.orderid, "撤单远端id:", sys_orderid)
|
||||
|
||||
def start_userStream(self):
|
||||
@ -446,6 +447,7 @@ class BinanceRestApi(RestClient):
|
||||
time=time,
|
||||
gateway_name=self.gateway_name,
|
||||
)
|
||||
|
||||
print("委托查询--远端id:",sys_orderid, "本地Id:", local_orderid)
|
||||
self.order_manager.on_order(order)
|
||||
|
||||
@ -704,7 +706,7 @@ class BinanceTradeWebsocketApi(BinanceWebsocketApiBase):
|
||||
# gateway_name=self.gateway_name
|
||||
# )
|
||||
# self.on_order(order)
|
||||
|
||||
|
||||
# push account data change
|
||||
if packet["e"] == "outboundAccountInfo":
|
||||
for account_data in packet["B"]:
|
||||
@ -718,8 +720,8 @@ class BinanceTradeWebsocketApi(BinanceWebsocketApiBase):
|
||||
|
||||
def on_order(self, data: dict):
|
||||
""""""
|
||||
|
||||
sys_orderid = str(data["i"])
|
||||
|
||||
order = self.order_manager.get_order_with_sys_orderid(sys_orderid)
|
||||
if not order:
|
||||
self.order_manager.add_push_data(sys_orderid, data)
|
||||
@ -737,7 +739,6 @@ class BinanceTradeWebsocketApi(BinanceWebsocketApiBase):
|
||||
print("远端ID:", sys_orderid, "本地ID:", order)
|
||||
self.order_manager.on_order(order)
|
||||
|
||||
|
||||
# Push trade event
|
||||
traded_volume = data.traded
|
||||
if not traded_volume:
|
||||
|
@ -253,6 +253,9 @@ class BarGenerator:
|
||||
"""
|
||||
Generate the bar data and call callback immediately.
|
||||
"""
|
||||
self.bar.datetime = self.bar.datetime.replace(
|
||||
second=0, microsecond=0
|
||||
)
|
||||
self.on_bar(self.bar)
|
||||
self.bar = None
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user