获取qmt账号的持仓情况后,我们进入下一步,如何获得当前账号的委托状况
还是之前的步骤,打开qmt,选择独立交易,
之后使用pycharm,编写py文件
导入包:
from xtquant import xtdata
from xtquant.xttrader import XtQuantTrader, XtQuantTraderCallback
from xtquant.xttype import StockAccount
import time, datetime, traceback, sys
import pandas as pd
连接miniqmt:
path = r'C:\国金QMT交易端模拟\userdata_mini'
# QMT账号
account = '55003243'
# 取账号信息
session_id = int(time.time())
xt_trader = XtQuantTrader(path, session_id)
acc = StockAccount(account, 'STOCK')
# 启动交易线程
xt_trader.start()
# 建立交易连接,返回0表示连接成功
connect_result = xt_trader.connect()
print('建立交易连接,返回0表示连接成功', connect_result)
# 对交易回调进行订阅,订阅后可以收到交易主推,返回0表示订阅成功
subscribe_result = xt_trader.subscribe(acc)
print('对交易回调进行订阅,订阅后可以收到交易主推,返回0表示订阅成功', subscribe_result)
获取当前账户委托情况:
#查询委托
orders = xt_trader.query_stock_orders(acc)
print("委托数量", len(orders))
data2 = pd.DataFrame()
if len(orders) != 0:for i in range(len(orders)):df = pd.DataFrame()df['账号类型'] = [orders[i].account_type]df['资金账号'] = [orders[i].account_id]df['证券代码'] = [orders[i].stock_code]df['证券代码'] = df['证券代码'].apply(lambda x: str(x)[:6])df['订单编号'] = [orders[i].order_id]df['柜台合同编号'] = [orders[i].order_sysid]df['报单时间'] = [orders[i].order_time]df['委托类型'] = [orders[i].order_type]df['委托数量'] = [orders[i].order_volume]df['报价类型'] = [orders[i].price_type]df['委托价格'] = [orders[i].price]df['成交数量'] = [orders[i].traded_volume]df['成交均价'] = [orders[i].traded_price]df['委托状态'] = [orders[i].order_status]df['委托状态描述'] = [orders[i].status_msg]df['策略名称'] = [orders[i].strategy_name]df['委托备注'] = [orders[i].order_remark]data2 = pd.concat([data2, df], ignore_index=True)
print('委托',data2)
实际持仓情况
基本上,账户的基本信息获取流程相关课程已经全部完毕。
接下来,就开始获取股票数据,财务数据,量价数据。