[update]
This commit is contained in:
parent
7f7f1e97ea
commit
042e25fe7e
@ -1,13 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
PROGRAM_NAME=celery
|
||||
|
||||
# Kill old processes
|
||||
echo "-------PROGRAM_NAME1--------"
|
||||
ID=`ps -ef | grep $PROGRAM_NAME | grep -v "$0" | grep -v "grep" | grep "python" | awk '{print $2}'`
|
||||
echo $ID
|
||||
for id in $ID
|
||||
do
|
||||
kill -9 $id
|
||||
echo "killed $id"
|
||||
done
|
@ -1 +1 @@
|
||||
celery -A vnpy.task.celery_app worker --max-tasks-per-child 1 -l info > tests/celery/worker.log 2>tests/celery/worker-error.log &
|
||||
celery -A vnpy.task.celery_app worker --max-tasks-per-child 1 -l debug > tests/celery/worker.log 2>tests/celery/worker-error.log &
|
||||
|
@ -592,7 +592,7 @@ class CtaEngine(BaseEngine):
|
||||
order = self.main_engine.get_order(vt_orderid)
|
||||
if not order:
|
||||
self.write_log(msg=f"撤单失败,找不到委托{vt_orderid}",
|
||||
strategy_name=strategy.strategy_name,
|
||||
strategy_Name=strategy.strategy_name,
|
||||
level=logging.ERROR)
|
||||
return False
|
||||
|
||||
|
@ -634,16 +634,6 @@ class CtaFutureTemplate(CtaTemplate):
|
||||
self.gt.save()
|
||||
self.display_grids()
|
||||
|
||||
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 get_positions(self):
|
||||
"""
|
||||
获取策略当前持仓(重构,使用主力合约)
|
||||
@ -787,7 +777,7 @@ class CtaFutureTemplate(CtaTemplate):
|
||||
grid.open_status = True
|
||||
self.write_log(f'{grid.direction.value}单已开仓完毕,order_price:{order.price}'
|
||||
+ f',volume:{order.volume}')
|
||||
self.gt.save()
|
||||
|
||||
# 网格的所有委托单部分执行完毕
|
||||
else:
|
||||
old_traded_volume = grid.traded_volume
|
||||
@ -800,7 +790,6 @@ class CtaFutureTemplate(CtaTemplate):
|
||||
self.write_log(f'剩余委托单号:{grid.order_ids}')
|
||||
|
||||
# 在策略得活动订单中,移除
|
||||
self.write_log(f'移除活动订单:{order.vt_orderid}')
|
||||
self.active_orders.pop(order.vt_orderid, None)
|
||||
|
||||
def on_order_open_canceled(self, order: OrderData):
|
||||
@ -1014,17 +1003,21 @@ class CtaFutureTemplate(CtaTemplate):
|
||||
# 发出平多委托
|
||||
if grid.traded_volume > 0:
|
||||
grid.volume -= grid.traded_volume
|
||||
grid.volume = round(grid.volume, 7)
|
||||
grid.traded_volume = 0
|
||||
|
||||
grid.volume = round(grid.volume, 7)
|
||||
|
||||
if 0 < self.account_pos.long_pos < grid.volume:
|
||||
self.write_error(u'当前{}的多单持仓:{},不满足平仓目标:{},强制降低'
|
||||
if self.account_pos.volume <= 0:
|
||||
self.write_error(u'当前{}的净持仓:{},不能平多单'
|
||||
.format(self.vt_symbol,
|
||||
self.account_pos.long_pos,
|
||||
self.account_pos.volume))
|
||||
return False
|
||||
if self.account_pos.volume < grid.volume:
|
||||
self.write_error(u'当前{}的净持仓:{},不满足平仓目标:{}, 强制降低'
|
||||
.format(self.vt_symbol,
|
||||
self.account_pos.volume,
|
||||
grid.volume))
|
||||
|
||||
grid.volume = self.account_pos.long_pos
|
||||
grid.volume = self.account_pos.volume
|
||||
|
||||
vt_orderids = self.sell(
|
||||
vt_symbol=self.vt_symbol,
|
||||
|
@ -38,35 +38,48 @@ class CtaGrid(object):
|
||||
包括交易方向,开仓价格,平仓价格,止损价格,开仓状态,平仓状态
|
||||
"""
|
||||
|
||||
def __init__(self, **kwargs ):
|
||||
def __init__(self,
|
||||
direction: Direction = None,
|
||||
open_price: float = 0,
|
||||
close_price: float = 0,
|
||||
stop_price: float = 0,
|
||||
vt_symbol: str = '',
|
||||
volume: float = 0,
|
||||
traded_volume: float = 0,
|
||||
order_status: bool = False,
|
||||
open_status: bool = False,
|
||||
close_status: bool = False,
|
||||
open_time: datetime = None,
|
||||
order_time: datetime = None,
|
||||
reuse_count: int = 0,
|
||||
type: str = ''
|
||||
):
|
||||
|
||||
self.id: str = kwargs.get('id', str(uuid.uuid1())) # gid
|
||||
self.direction = kwargs.get('direction', None) # 交易方向(LONG:多,正套;SHORT:空,反套)
|
||||
if isinstance(self.direction, str):
|
||||
self.direction = Direction(self.direction)
|
||||
self.open_price = kwargs.get('open_price', 0) # 开仓价格
|
||||
self.close_price = kwargs.get('close_price', 0) # 止盈价格
|
||||
self.stop_price = kwargs.get('stop_price', 0) # 止损价格
|
||||
self.vt_symbol = kwargs.get('vt_symbol', '') # 品种合约
|
||||
self.volume = kwargs.get('volume', 0.0) # 开仓数量( 兼容数字货币 )
|
||||
self.traded_volume = kwargs.get('traded_volume', 0.0) # 已成交数量 开仓时,为开仓数量,平仓时,为平仓数量
|
||||
self.order_status = kwargs.get('order_status', False) # 挂单状态: True,已挂单,False,未挂单
|
||||
self.order_ids = kwargs.get('order_ids',[]) # order_id list
|
||||
self.open_status = kwargs.get('open_status', False) # 开仓状态
|
||||
self.close_status = kwargs.get('close_status', False) # 平仓状态
|
||||
self.open_time = kwargs.get('open_time', None) # 开仓时间
|
||||
self.order_time = kwargs.get('order_time', None) # 委托时间
|
||||
self.lock_grid_ids = kwargs.get('lock_grid_ids', []) # 锁单的网格,[gid,gid]
|
||||
self.reuse_count = kwargs.get('reuse_count', 0) # 重用次数(0, 平仓后是否删除)
|
||||
self.type = kwargs.get('type', '') # 网格类型标签
|
||||
self.snapshot = kwargs.get('snapshot',{}) # 切片数据,如记录开仓点时的某些状态数据
|
||||
self.id: str = str(uuid.uuid1()) # gid
|
||||
self.direction = direction # 交易方向(LONG:多,正套;SHORT:空,反套)
|
||||
self.open_price = open_price # 开仓价格
|
||||
self.close_price = close_price # 止盈价格
|
||||
self.stop_price = stop_price # 止损价格
|
||||
self.vt_symbol = vt_symbol # 品种合约
|
||||
self.volume = volume # 开仓数量( 兼容数字货币 )
|
||||
self.traded_volume = traded_volume # 已成交数量 开仓时,为开仓数量,平仓时,为平仓数量
|
||||
self.order_status = order_status # 挂单状态: True,已挂单,False,未挂单
|
||||
self.order_ids = [] # order_id list
|
||||
self.open_status = open_status # 开仓状态
|
||||
self.close_status = close_status # 平仓状态
|
||||
self.open_time = open_time # 开仓时间
|
||||
self.order_time = order_time # 委托时间
|
||||
self.lock_grid_ids = [] # 锁单的网格,[gid,gid]
|
||||
self.reuse_count = reuse_count # 重用次数(0, 平仓后是否删除)
|
||||
self.type = type # 网格类型标签
|
||||
self.snapshot = {} # 切片数据,如记录开仓点时的某些状态数据
|
||||
|
||||
def to_json(self):
|
||||
"""输出JSON"""
|
||||
|
||||
j = OrderedDict()
|
||||
j['id'] = self.id
|
||||
j['direction'] = self.direction.value if isinstance(self.direction, Direction) else ''
|
||||
j['direction'] = self.direction.value if self.direction else ''
|
||||
j['open_price'] = self.open_price # 开仓价格
|
||||
j['close_price'] = self.close_price # 平仓价格
|
||||
j['stop_price'] = self.stop_price # 止损价格
|
||||
@ -77,7 +90,7 @@ class CtaGrid(object):
|
||||
j['order_ids'] = self.order_ids # OrderId
|
||||
j['open_status'] = self.open_status # 开仓状态
|
||||
j['close_status'] = self.close_status # 平仓状态
|
||||
j['lock_grid_ids'] = self.lock_grid_ids # 对锁的网格
|
||||
j['lockGrids'] = self.lock_grid_ids # 对锁的网格
|
||||
j['reuse_count'] = self.reuse_count # 是否重用
|
||||
j['type'] = self.type # 类型
|
||||
j['snapshot'] = self.snapshot # 切片数据
|
||||
@ -111,7 +124,7 @@ class CtaGrid(object):
|
||||
self.vt_symbol = j.get('vt_symbol', '')
|
||||
self.volume = j.get('volume', 0.0)
|
||||
self.traded_volume = j.get('traded_volume', 0.0) # 已交易的合约数量
|
||||
self.lock_grid_ids = j.get('lock_grid_ids', [])
|
||||
self.lock_grid_ids = j.get('lockGrids', [])
|
||||
self.type = j.get('type', '')
|
||||
|
||||
self.reuse_count = j.get('reuse_count', 0)
|
||||
@ -887,8 +900,8 @@ class CtaGridTrade(CtaComponent):
|
||||
data[u'up_grids'] = up_grids
|
||||
data[u'dn_grids'] = dn_grids
|
||||
|
||||
with open(grid_json_file, 'w', encoding='utf8') as f:
|
||||
json_data = json.dumps(data, indent=4, ensure_ascii=True)
|
||||
with open(grid_json_file, 'w') as f:
|
||||
json_data = json.dumps(data, indent=4)
|
||||
f.write(json_data)
|
||||
|
||||
self.write_log(u'GrideTrade保存文件{}完成'.format(grid_json_file))
|
||||
@ -915,7 +928,7 @@ class CtaGridTrade(CtaComponent):
|
||||
self.write_log(u'{}不存在,新建保存保存'.format(grid_json_file))
|
||||
try:
|
||||
with open(grid_json_file, 'w') as f:
|
||||
json_data = json.dumps(data, indent=4, ensure_ascii=True)
|
||||
json_data = json.dumps(data, indent=4)
|
||||
f.write(json_data)
|
||||
except Exception as ex:
|
||||
self.write_log(u'写入网格文件{}异常:{}'.format(grid_json_file, str(ex)))
|
||||
@ -938,7 +951,7 @@ class CtaGridTrade(CtaComponent):
|
||||
grids = []
|
||||
for grid_obj in json_grids:
|
||||
|
||||
grid = CtaGrid(**grid_obj)
|
||||
grid = CtaGrid(grid_obj)
|
||||
|
||||
self.write_log(grid.to_str())
|
||||
|
||||
|
@ -1,25 +0,0 @@
|
||||
期货砖块图数据
|
||||
|
||||
1.重建
|
||||
砖图高度,为3,5,10, K3, K5, K10个最小跳动
|
||||
从mongo数据库,获取最后一笔记录得日期/时间
|
||||
从tdx数据源,获取历史分笔数据(开始时间,结束时间/当前时间, 合约代码)=》 Queue
|
||||
从Queue=》 renko on Tick
|
||||
|
||||
2. 查询
|
||||
从mongo数据库,获取数据。
|
||||
缓存至本地(数量切片缓存)
|
||||
返回K线记录
|
||||
|
||||
|
||||
股票砖图数据
|
||||
1.重建
|
||||
砖图高度,为max(价格千分之一,0.01)得3,5,10个最小跳动
|
||||
从mongo数据库,获取最后一笔记录得日期/时间
|
||||
从tdx数据源,获取历史分笔数据(开始时间,结束时间/当前时间, 合约代码)=》 Queue
|
||||
从Queue=》 renko on Tick
|
||||
|
||||
2. 查询
|
||||
从mongo数据库,获取数据。
|
||||
缓存至本地(数量切片缓存)
|
||||
返回K线记录
|
@ -409,7 +409,7 @@ class BinancefRestApi(RestClient):
|
||||
"side": DIRECTION_VT2BINANCEF[req.direction],
|
||||
"type": ORDERTYPE_VT2BINANCEF[req.type],
|
||||
"price": float(req.price),
|
||||
"quantity": round(req.volume, 7),
|
||||
"quantity": float(req.volume),
|
||||
"newClientOrderId": orderid,
|
||||
"newOrderRespType": "ACK"
|
||||
}
|
||||
@ -813,18 +813,6 @@ class BinancefTradeWebsocketApi(WebsocketClient):
|
||||
account.available = float(acc_data["cw"])
|
||||
self.gateway.on_account(account)
|
||||
|
||||
for pos_data in packet["a"]["P"]:
|
||||
position = PositionData(
|
||||
symbol=pos_data["s"],
|
||||
exchange=Exchange.BINANCE,
|
||||
direction=Direction.NET,
|
||||
volume=round(float(pos_data["pa"]), 7),
|
||||
price=float(pos_data["ep"]),
|
||||
pnl=float(pos_data["cr"]),
|
||||
gateway_name=self.gateway_name,
|
||||
)
|
||||
self.gateway.on_position(position)
|
||||
|
||||
def on_order(self, packet: dict) -> None:
|
||||
""""""
|
||||
self.gateway.write_log(json.dumps(packet, indent=2))
|
||||
|
Loading…
Reference in New Issue
Block a user