forked from yutiansut/QUANTAXIS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
executable file
·45 lines (35 loc) · 1.22 KB
/
example.py
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
# coding:utf-8
import csv
import datetime
import time
import pymongo
from QUANTAXIS_Trade.QA_tradex import QA_Trade_stock_api, QA_Trade_stock_util
st = QA_Trade_stock_api.QA_Stock()
st.get_config()
client = st.QA_trade_stock_login()
print('可用资金查询')
print(st.QA_trade_stock_get_cash(client))
print('当前持仓股票查询')
print(st.QA_trade_stock_get_stock(client))
print('委托查询')
print(st.QA_trade_stock_get_orders(client))
holder = st.QA_trade_stock_get_holder(client)
account = QA_Trade_stock_util.QA_get_account_assest(st, client)
hold_list = [l['code'] for l in account['stock']]
# 打开股票列表
stock_lists = ['000001', '600010']
# 买入
for item in stock_lists:
try:
st.QA_trade_stock_post_order(client, [0, 4, holder[0], item, 0, 100])
except:
st.QA_trade_stock_post_order(client, [0, 4, holder[1], item, 0, 100])
# 获取当前持仓股票
account = QA_Trade_stock_util.QA_get_account_assest(st, client)
hold_list = [l['code'] for l in account['stock']]
# 卖出
for item in hold_list:
if str(item)[6] == '0':
st.QA_trade_stock_post_order(client, [1, 4, holder[0], item, 0, 100])
else:
st.QA_trade_stock_post_order(client, [1, 4, holder[1], item, 0, 100])