-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathqmtData.py
More file actions
57 lines (49 loc) · 2.19 KB
/
qmtData.py
File metadata and controls
57 lines (49 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from xtquant.xttrader import XtQuantTrader, XtQuantTraderCallback
from xtquant.xttype import StockAccount
from xtquant import xtconstant
from xtquant import xtdata
import requests
from datetime import datetime, timedelta
import json
import random
def get_price(code):
print(f"正在查询{code}当前价格")
res = xtdata.get_full_tick([code])
#print(res[code]) # {'timetag': '20240228 11:30:01', 'lastPrice': 1686, 'open': 1688.92, 'high': 1696.57, 'low': 1674.01, 'lastClose': 1689.5, 'amount': 3139981100, 'volume': 18649, 'pvolume': 1864909, 'stockStatus': 0, 'openInt': 13, 'settlementPrice': 0, 'lastSettlementPrice': 0, 'askPrice': [1688.5, 1688.53, 1688.84, 0, 0], 'bidPrice': [1686.12, 1686, 1685.26, 0, 0], 'askVol': [98, 3, 1, 0, 0], 'bidVol': [1, 1, 1, 0, 0]}
print(res[code]['lastPrice'])
return (res[code]['lastPrice'])
def get_daily_info(code):
print(f"正在查询{code}行情信息")
quote=xtdata.get_full_tick([code])
detail=xtdata.get_instrument_detail(code)
info={
'ts_code':code,
'open':quote[code]['open'],
'high':quote[code]['high'],
'low':quote[code]['low'],
'close':quote[code]['lastPrice'],
'volume':quote[code]['amount'],
'amount':quote[code]['volume'],
'name':detail['InstrumentName'],
'vwap':0,
'stop':detail['InstrumentStatus'],
'up_limit':detail['UpStopPrice'],
'down_limit':detail['DownStopPrice'],
}
print(info)
return info
def subscribe(xt_trader,code):
# 对交易回调进行订阅,订阅后可以收到交易主推,返回0表示订阅成功
subscribe_result = xt_trader.subscribe(acc)
if subscribe_result != 0:
print('账号订阅失败 %d'%subscribe_result)
sub=xtdata.subscribe_whole_quote(['SH', 'SZ'], callback=None)
print(1)
xtdata.subscribe_quote(['002624'], period='1d', start_time='', end_time='', count=0, callback=None)
print(2)
try:
x=xtdata.get_market_data(field_list=[], stock_list=['002624'], period='1d', start_time='', end_time='', count=-1, dividend_type='none', fill_data=True)
except:
print("------------------")
print(3)
print(x)