|
@@ -12,6 +12,7 @@ import pymysql
|
|
import multiprocessing as mp
|
|
import multiprocessing as mp
|
|
import math
|
|
import math
|
|
import psutil
|
|
import psutil
|
|
|
|
+from apscheduler.schedulers.blocking import BlockingScheduler
|
|
|
|
|
|
auth('18616891214', 'Ea?*7f68nD.dafcW34d!')
|
|
auth('18616891214', 'Ea?*7f68nD.dafcW34d!')
|
|
db_pool = pymysql.connect(host='localhost',
|
|
db_pool = pymysql.connect(host='localhost',
|
|
@@ -23,6 +24,21 @@ cursor_pool = db_pool.cursor()
|
|
engine_stock = create_engine('mysql+pymysql://root:r6kEwqWU9!v3@localhost:3307/qmt_stocks_whole?charset=utf8')
|
|
engine_stock = create_engine('mysql+pymysql://root:r6kEwqWU9!v3@localhost:3307/qmt_stocks_whole?charset=utf8')
|
|
|
|
|
|
|
|
|
|
|
|
+def run(seq):
|
|
|
|
+ print(seq)
|
|
|
|
+ '''阻塞线程接收行情回调'''
|
|
|
|
+ import time
|
|
|
|
+ client = xtdata.get_client()
|
|
|
|
+ while True:
|
|
|
|
+ time.sleep(3)
|
|
|
|
+ now_date = dt.now()
|
|
|
|
+ if not client.is_connected() or dt.now() > now_date.replace(hour=13, minute=26, second=0):
|
|
|
|
+ xtdata.unsubscribe_quote(seq)
|
|
|
|
+ raise Exception('行情服务连接断开')
|
|
|
|
+ break
|
|
|
|
+ return
|
|
|
|
+
|
|
|
|
+
|
|
def real_price(datas):
|
|
def real_price(datas):
|
|
# i = '000001.SZ'
|
|
# i = '000001.SZ'
|
|
for i in datas:
|
|
for i in datas:
|
|
@@ -211,8 +227,8 @@ def buy_trader(data, positions):
|
|
order_id = xt_trader.order_stock(acc, stock, xtconstant.STOCK_BUY, volume, xtconstant.LATEST_PRICE,
|
|
order_id = xt_trader.order_stock(acc, stock, xtconstant.STOCK_BUY, volume, xtconstant.LATEST_PRICE,
|
|
current_price, 'strategy1', 'order_test')
|
|
current_price, 'strategy1', 'order_test')
|
|
print(order_id)
|
|
print(order_id)
|
|
- else:
|
|
|
|
- print(f'Cash只有:{cash} 或者 现有持仓{len(positions)} 超过了{max_pos}')
|
|
|
|
|
|
+ else:
|
|
|
|
+ print(f'Cash只有:{cash} 或者 现有持仓{len(positions)} 超过了{max_pos}')
|
|
engine_hlfx_pool.dispose()
|
|
engine_hlfx_pool.dispose()
|
|
print('一轮结束了,现在时间是:', dt.now())
|
|
print('一轮结束了,现在时间是:', dt.now())
|
|
|
|
|
|
@@ -231,6 +247,13 @@ def trader(data):
|
|
buy_trader(data, positions)
|
|
buy_trader(data, positions)
|
|
|
|
|
|
|
|
|
|
|
|
+def bridge():
|
|
|
|
+ print("start")
|
|
|
|
+ stocks = xtdata.get_stock_list_in_sector('沪深A股')
|
|
|
|
+ seq = xtdata.subscribe_whole_quote(stocks, callback=trader)
|
|
|
|
+ run(seq)
|
|
|
|
+
|
|
|
|
+
|
|
class MyXtQuantTraderCallback(XtQuantTraderCallback):
|
|
class MyXtQuantTraderCallback(XtQuantTraderCallback):
|
|
def on_disconnected(self):
|
|
def on_disconnected(self):
|
|
"""
|
|
"""
|
|
@@ -304,7 +327,6 @@ if __name__ == '__main__':
|
|
pus = psutil.Process()
|
|
pus = psutil.Process()
|
|
pus.cpu_affinity([4, 5, 6, 7])
|
|
pus.cpu_affinity([4, 5, 6, 7])
|
|
|
|
|
|
- print("start")
|
|
|
|
# 指定客户端所在路径
|
|
# 指定客户端所在路径
|
|
path = r'c:\\qmt\\userdata_mini'
|
|
path = r'c:\\qmt\\userdata_mini'
|
|
# 生成session id 整数类型 同时运行的策略不能重复
|
|
# 生成session id 整数类型 同时运行的策略不能重复
|
|
@@ -324,8 +346,13 @@ if __name__ == '__main__':
|
|
subscribe_result = xt_trader.subscribe(acc)
|
|
subscribe_result = xt_trader.subscribe(acc)
|
|
print('对交易回调进行订阅,订阅后可以收到交易主推,返回0表示订阅成功', subscribe_result)
|
|
print('对交易回调进行订阅,订阅后可以收到交易主推,返回0表示订阅成功', subscribe_result)
|
|
|
|
|
|
|
|
+ scheduler = BlockingScheduler()
|
|
|
|
+ scheduler.add_job(func=bridge, trigger='cron', day_of_week='0-4', hour='9', minute='40',
|
|
|
|
+ timezone="Asia/Shanghai")
|
|
|
|
+ try:
|
|
|
|
+ scheduler.start()
|
|
|
|
+ except (KeyboardInterrupt, SystemExit):
|
|
|
|
+ pass
|
|
|
|
+
|
|
|
|
|
|
- stocks = xtdata.get_stock_list_in_sector('沪深A股')
|
|
|
|
- xtdata.subscribe_whole_quote(stocks, callback=trader)
|
|
|
|
- xtdata.run()
|
|
|
|
# xtdata.subscribe_quote('000001.SZ', '1d', '', '', count=1, callback=MA)
|
|
# xtdata.subscribe_quote('000001.SZ', '1d', '', '', count=1, callback=MA)
|