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,11 +3,12 @@ from vnpy.event import EventEngine
|
||||
from vnpy.trader.engine import MainEngine
|
||||
from vnpy.trader.ui import MainWindow, create_qapp
|
||||
|
||||
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.ctptest import CtptestGateway
|
||||
#from vnpy.gateway.femas import FemasGateway
|
||||
#from vnpy.gateway.tiger import TigerGateway
|
||||
#from vnpy.gateway.oes import OesGateway
|
||||
@ -17,8 +18,7 @@ from vnpy.trader.ui import MainWindow, create_qapp
|
||||
#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.hbdm import HbdmGateway
|
||||
|
||||
#from vnpy.app.cta_strategy import CtaStrategyApp
|
||||
#from vnpy.app.csv_loader import CsvLoaderApp
|
||||
@ -35,9 +35,11 @@ def main():
|
||||
event_engine = EventEngine()
|
||||
|
||||
main_engine = MainEngine(event_engine)
|
||||
|
||||
main_engine.add_gateway(BinanceGateway)
|
||||
#main_engine.add_gateway(XtpGateway)
|
||||
#main_engine.add_gateway(CtpGateway)
|
||||
# # main_engine.add_gateway(CtptestGateway)
|
||||
# main_engine.add_gateway(CtptestGateway)
|
||||
#main_engine.add_gateway(FemasGateway)
|
||||
#main_engine.add_gateway(IbGateway)
|
||||
#main_engine.add_gateway(FutuGateway)
|
||||
@ -49,8 +51,7 @@ def main():
|
||||
#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_gateway(HbdmGateway)
|
||||
|
||||
#main_engine.add_app(CtaStrategyApp)
|
||||
#main_engine.add_app(CtaBacktesterApp)
|
||||
|
@ -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)
|
||||
|
||||
@ -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