[bug fix]
This commit is contained in:
parent
b94065902a
commit
5c80cde613
@ -462,6 +462,16 @@ class CtaStockTemplate(CtaTemplate):
|
|||||||
if name in setting:
|
if name in setting:
|
||||||
setattr(self, name, setting[name])
|
setattr(self, name, setting[name])
|
||||||
|
|
||||||
|
def sync_data(self):
|
||||||
|
"""同步更新数据"""
|
||||||
|
if not self.backtesting:
|
||||||
|
self.write_log(u'保存k线缓存数据')
|
||||||
|
self.save_klines_to_cache()
|
||||||
|
|
||||||
|
if self.inited and self.trading:
|
||||||
|
self.write_log(u'保存policy数据')
|
||||||
|
self.policy.save()
|
||||||
|
|
||||||
def save_klines_to_cache(self, kline_names: list = []):
|
def save_klines_to_cache(self, kline_names: list = []):
|
||||||
"""
|
"""
|
||||||
保存K线数据到缓存
|
保存K线数据到缓存
|
||||||
@ -573,7 +583,7 @@ class CtaStockTemplate(CtaTemplate):
|
|||||||
for lg in long_grids:
|
for lg in long_grids:
|
||||||
if len(lg.order_ids) > 0:
|
if len(lg.order_ids) > 0:
|
||||||
self.write_log(f'清除委托单:{lg.order_ids}')
|
self.write_log(f'清除委托单:{lg.order_ids}')
|
||||||
[self.cta_engine.cancel_order(vt_orderid) for vt_orderid in lg.order_ids]
|
[self.cta_engine.cancel_order(self, vt_orderid) for vt_orderid in lg.order_ids]
|
||||||
lg.order_ids = []
|
lg.order_ids = []
|
||||||
if lg.open_status:
|
if lg.open_status:
|
||||||
pos = self.get_position(lg.vt_symbol)
|
pos = self.get_position(lg.vt_symbol)
|
||||||
@ -1041,6 +1051,10 @@ class CtaStockTemplate(CtaTemplate):
|
|||||||
return
|
return
|
||||||
vt_symbol = ordering_grid.vt_symbol
|
vt_symbol = ordering_grid.vt_symbol
|
||||||
cur_price = self.cta_engine.get_price(vt_symbol)
|
cur_price = self.cta_engine.get_price(vt_symbol)
|
||||||
|
if cur_price is None:
|
||||||
|
self.write_error(f'暂时不能获取{vt_symbol}最新价格')
|
||||||
|
return
|
||||||
|
|
||||||
buy_volume = ordering_grid.volume - ordering_grid.traded_volume
|
buy_volume = ordering_grid.volume - ordering_grid.traded_volume
|
||||||
min_trade_volume = self.cta_engine.get_volume_tick(vt_symbol)
|
min_trade_volume = self.cta_engine.get_volume_tick(vt_symbol)
|
||||||
if availiable < buy_volume * cur_price:
|
if availiable < buy_volume * cur_price:
|
||||||
|
@ -517,7 +517,8 @@ class XtpTdApi(TdApi):
|
|||||||
else:
|
else:
|
||||||
# 股票
|
# 股票
|
||||||
direction, offset = DIRECTION_STOCK_XTP2VT[data["side"]]
|
direction, offset = DIRECTION_STOCK_XTP2VT[data["side"]]
|
||||||
|
insert_time = str(data["insert_time"])
|
||||||
|
dt = datetime.strptime(insert_time, '%Y%m%d%H%M%S%f')
|
||||||
order = OrderData(
|
order = OrderData(
|
||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
exchange=MARKET_XTP2VT[data["market"]],
|
exchange=MARKET_XTP2VT[data["market"]],
|
||||||
@ -530,7 +531,8 @@ class XtpTdApi(TdApi):
|
|||||||
volume=data["quantity"],
|
volume=data["quantity"],
|
||||||
traded=data["qty_traded"],
|
traded=data["qty_traded"],
|
||||||
status=STATUS_XTP2VT[data["order_status"]],
|
status=STATUS_XTP2VT[data["order_status"]],
|
||||||
time=data["insert_time"],
|
datetime=dt,
|
||||||
|
time=dt.strftime('%H:%M:%S'),
|
||||||
gateway_name=self.gateway_name
|
gateway_name=self.gateway_name
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -545,6 +547,9 @@ class XtpTdApi(TdApi):
|
|||||||
else:
|
else:
|
||||||
direction, offset = DIRECTION_STOCK_XTP2VT[data["side"]]
|
direction, offset = DIRECTION_STOCK_XTP2VT[data["side"]]
|
||||||
|
|
||||||
|
trade_time = str(data["trade_time"])
|
||||||
|
dt = datetime.strptime(trade_time,'%Y%m%d%H%M%S%f')
|
||||||
|
|
||||||
trade = TradeData(
|
trade = TradeData(
|
||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
exchange=MARKET_XTP2VT[data["market"]],
|
exchange=MARKET_XTP2VT[data["market"]],
|
||||||
@ -555,7 +560,8 @@ class XtpTdApi(TdApi):
|
|||||||
offset=offset,
|
offset=offset,
|
||||||
price=data["price"],
|
price=data["price"],
|
||||||
volume=data["quantity"],
|
volume=data["quantity"],
|
||||||
time=data["trade_time"],
|
datetime=dt,
|
||||||
|
time=dt.strftime('%H:%M:%S'),
|
||||||
gateway_name=self.gateway_name
|
gateway_name=self.gateway_name
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -767,12 +773,13 @@ class XtpTdApi(TdApi):
|
|||||||
|
|
||||||
# stock type
|
# stock type
|
||||||
else:
|
else:
|
||||||
|
req.offset = Offset.NONE
|
||||||
xtp_req = {
|
xtp_req = {
|
||||||
"ticker": req.symbol,
|
"ticker": req.symbol,
|
||||||
"market": MARKET_VT2XTP[req.exchange],
|
"market": MARKET_VT2XTP[req.exchange],
|
||||||
"price": req.price,
|
"price": req.price,
|
||||||
"quantity": int(req.volume),
|
"quantity": int(req.volume),
|
||||||
"side": DIRECTION_STOCK_VT2XTP.get((req.direction, Offset.NONE), ""),
|
"side": DIRECTION_STOCK_VT2XTP.get((req.direction,req.offset), ""),
|
||||||
"price_type": ORDERTYPE_VT2XTP[req.type],
|
"price_type": ORDERTYPE_VT2XTP[req.type],
|
||||||
"business_type": BUSINESS_VT2XTP[req.offset]
|
"business_type": BUSINESS_VT2XTP[req.offset]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user