diff --git a/vnpy/app/algo_trading/engine.py b/vnpy/app/algo_trading/engine.py index 77f110f0..ee7af87b 100644 --- a/vnpy/app/algo_trading/engine.py +++ b/vnpy/app/algo_trading/engine.py @@ -283,7 +283,7 @@ class AlgoEngine(BaseEngine): ret = self.stop_algo(req.orderid) if ret: - order.cancelTime = datetime.now().strftime('%H:%M:%S.%f') + order.cancel_time = datetime.now().strftime('%H:%M:%S.%f') order.status = Status.CANCELLED event1 = Event(type=EVENT_ORDER, data=order) self.event_engine.put(event1) diff --git a/vnpy/app/cta_crypto/back_testing.py b/vnpy/app/cta_crypto/back_testing.py index ab2f03a1..134e838b 100644 --- a/vnpy/app/cta_crypto/back_testing.py +++ b/vnpy/app/cta_crypto/back_testing.py @@ -354,7 +354,7 @@ class BackTestingEngine(object): return self.volume_tick.get(vt_symbol, 1) def set_contract(self, symbol: str, exchange: Exchange, product: Product, name: str, size: int, - price_tick: float, volume_tick: float = 1, margin_rate: float = 0.1): + price_tick: float, volume_tick: float = 0.1, margin_rate: float = 0.1): """设置合约信息""" vt_symbol = '.'.join([symbol, exchange.value]) if vt_symbol not in self.contract_dict: @@ -560,8 +560,8 @@ class BackTestingEngine(object): exchange=Exchange(symbol_data.get('exchange', 'LOCAL')), product=Product(symbol_data.get('product', "期货")), size=symbol_data.get('symbol_size', 10), - price_tick=symbol_data.get('price_tick', 1), - volume_tick=symbol_data.get('min_volume', 1), + price_tick=symbol_data.get('price_tick', 0.01), + volume_tick=symbol_data.get('min_volume', 0.1), margin_rate=margin_rate ) @@ -601,8 +601,8 @@ class BackTestingEngine(object): def new_bar(self, bar): """新的K线""" self.last_bar.update({bar.vt_symbol: bar}) - if self.last_dt is None or (bar.datetime and bar.datetime > self.last_dt): - self.last_dt = bar.datetime + if self.last_dt is None or (bar.datetime and bar.datetime > self.last_dt - timedelta(seconds=self.bar_interval_seconds)): + self.last_dt = bar.datetime + timedelta(seconds=self.bar_interval_seconds) self.set_price(bar.vt_symbol, bar.close_price) self.cross_stop_order(bar=bar) # 撮合停止单 self.cross_limit_order(bar=bar) # 先撮合限价单 @@ -887,7 +887,7 @@ class BackTestingEngine(object): if register_strategy.strategy_name != strategy.strategy_name: return False order.status = Status.CANCELLED - order.cancelTime = str(self.last_dt) + order.cancel_time = str(self.last_dt) self.active_limit_orders.pop(vt_orderid, None) strategy.on_order(order) return True @@ -941,7 +941,7 @@ class BackTestingEngine(object): strategy_cond = strategy.strategy_name == order_strategy.strategy_name if offset_cond and symbol_cond and strategy_cond: - self.write_log(u'撤销订单:{},{} {}@{}' + self.write_log(u'撤销限价订单:{},{} {}@{}' .format(vt_orderid, order.direction, order.price, order.volume)) order.status = Status.CANCELLED order.cancel_time = str(self.last_dt) diff --git a/vnpy/app/cta_strategy_pro/back_testing.py b/vnpy/app/cta_strategy_pro/back_testing.py index f010e482..7d580e05 100644 --- a/vnpy/app/cta_strategy_pro/back_testing.py +++ b/vnpy/app/cta_strategy_pro/back_testing.py @@ -583,8 +583,8 @@ class BackTestingEngine(object): def new_bar(self, bar): """新的K线""" self.last_bar.update({bar.vt_symbol: bar}) - if self.last_dt is None or (bar.datetime and bar.datetime > self.last_dt): - self.last_dt = bar.datetime + if self.last_dt is None or (bar.datetime and bar.datetime > self.last_dt - timedelta(seconds=self.bar_interval_seconds)): + self.last_dt = bar.datetime + timedelta(seconds=self.bar_interval_seconds) self.set_price(bar.vt_symbol, bar.close_price) self.cross_stop_order(bar=bar) # 撮合停止单 self.cross_limit_order(bar=bar) # 先撮合限价单 @@ -898,7 +898,7 @@ class BackTestingEngine(object): if register_strategy.strategy_name != strategy.strategy_name: return False order.status = Status.CANCELLED - order.cancelTime = str(self.last_dt) + order.cancel_time = str(self.last_dt) self.active_limit_orders.pop(vt_orderid, None) strategy.on_order(order) return True @@ -960,6 +960,7 @@ class BackTestingEngine(object): if strategy: strategy.on_order(order) + # 撤销本地停止单 for stop_orderid in list(self.active_stop_orders.keys()): order = self.active_stop_orders.get(stop_orderid, None) order_strategy = self.order_strategy_dict.get(stop_orderid, None) @@ -992,6 +993,7 @@ class BackTestingEngine(object): def cross_stop_order(self, bar: BarData = None, tick: TickData = None): """ + 本地停止单撮合 Cross stop order with last bar/tick data. """ vt_symbol = bar.vt_symbol if bar else tick.vt_symbol diff --git a/vnpy/component/cta_line_bar.py b/vnpy/component/cta_line_bar.py index b32d1327..e707b76d 100644 --- a/vnpy/component/cta_line_bar.py +++ b/vnpy/component/cta_line_bar.py @@ -1055,7 +1055,9 @@ class CtaLineBar(object): gateway_name=tick.gateway_name, symbol=tick.symbol, exchange=tick.exchange, - datetime=tick.datetime + datetime=tick.datetime, + interval=self.interval, + interval_num=self.bar_interval ) # 创建新的K线 # 计算K线的整点分钟周期,这里周期最小是1分钟。如果你是采用非整点分钟,例如1.5分钟,请把这段注解掉 if self.minute_interval and self.interval == Interval.SECOND: diff --git a/vnpy/component/cta_policy.py b/vnpy/component/cta_policy.py index 91c9c3a5..7925e355 100644 --- a/vnpy/component/cta_policy.py +++ b/vnpy/component/cta_policy.py @@ -8,6 +8,7 @@ from vnpy.component.base import CtaComponent from vnpy.trader.utility import get_folder_path TNS_STATUS_OBSERVATE = 'observate' +TNS_STATUS_READY = 'ready' TNS_STATUS_ORDERING = 'ordering' TNS_STATUS_OPENED = 'opened' TNS_STATUS_CLOSED = 'closed' diff --git a/vnpy/gateway/binancef/binancef_gateway.py b/vnpy/gateway/binancef/binancef_gateway.py index 3e152b6b..3c2b09ac 100644 --- a/vnpy/gateway/binancef/binancef_gateway.py +++ b/vnpy/gateway/binancef/binancef_gateway.py @@ -38,6 +38,7 @@ from vnpy.trader.object import ( SubscribeRequest, HistoryRequest ) +from vnpy.trader.utility import print_dict from vnpy.trader.event import EVENT_TIMER from vnpy.event import Event, EventEngine @@ -508,11 +509,14 @@ class BinancefRestApi(RestClient): "unrealizedProfit": "-0.44537584", // 持仓未实现盈亏 "walletBalance": "9.19485176" // 账户余额 }""" + # self.gateway.write_log(print_dict(asset)) account = AccountData( accountid=f"{self.gateway_name}_{asset['asset']}", balance=float(asset["marginBalance"]), frozen=float(asset["maintMargin"]), holding_profit=float(asset['unrealizedProfit']), + currency='USDT', + margin=float(asset["initialMargin"]), gateway_name=self.gateway_name ) diff --git a/vnpy/trader/object.py b/vnpy/trader/object.py index 06a11eae..2da0edb4 100644 --- a/vnpy/trader/object.py +++ b/vnpy/trader/object.py @@ -96,6 +96,7 @@ class BarData(BaseData): trading_day: str = "" # '%Y-%m-%d' interval: Interval = None # constant.py Internal 1m, 1h, 1d, 1w .etc + interval_num: int = 1 # 5 for 5m, 5h etc volume: float = 0 open_interest: float = 0 open_price: float = 0