雪球模拟组合查询和交易脚本-python

Talk cheap, show code

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
58
59
60
61
62
63
64
65
66
67
import requests
import json

# 使用前需要替换 cookie 和 组合 id, 怎么找见下边截图/链接
cookie = your_cookies
group_id = yout_group_id

# 持仓查询函数
def hold_stock():
headers = {
‘authority’: ‘tc.xueqiu.com’,
‘sec-ch-ua’: ‘” Not A;Brand”;v=“99”, “Chromium”;v=“96”, “Google Chrome”;v=“96”’,
‘accept’: ‘application/json, text/plain, */*’,
# ‘accept’: ‘application/json, charset=UTF-8’,
‘sec-ch-ua-mobile’: ‘?0’,
‘user-agent’: ‘Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36’,
‘sec-ch-ua-platform’: ‘”Windows”’,
‘origin’: ‘https://xueqiu.com’,
‘sec-fetch-site’: ‘same-site’,
‘sec-fetch-mode’: ‘cors’,
‘sec-fetch-dest’: ‘empty’,
‘referer’: ‘https://xueqiu.com/performance’,
‘accept-language’: ‘zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7’,
‘cookie’: cookie,
}

params = (
(‘gid’, group_id),
)
response = requests.get(‘https://tc.xueqiu.com/tc/snowx//MONI/performances.json’, headers=headers, params=params)
response.encoding = “utf-8
content = json.loads(response.text)
res_stock = content[‘result_data’][‘performances’][1][‘list’]
res_asset = content[‘result_data’][‘performances’][1][‘assets’]
return res_asset, res_stock

# 交易函数
def trade(direction, date, comment, stock_code, price, shares, tax_rate):
headers = {
‘authority’: ‘tc.xueqiu.com’,
‘sec-ch-ua’: ‘” Not A;Brand”;v=“99”, “Chromium”;v=“96”, “Google Chrome”;v=“96”’,
‘accept’: ‘application/json, text/plain, */*’,
‘content-type’: ‘application/x-www-form-urlencoded’,
‘sec-ch-ua-mobile’: ‘?0’,
‘user-agent’: ‘Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36’,
‘sec-ch-ua-platform’: ‘”Windows”’,
‘origin’: ‘https://xueqiu.com’,
‘sec-fetch-site’: ‘same-site’,
‘sec-fetch-mode’: ‘cors’,
‘sec-fetch-dest’: ‘empty’,
‘referer’: ‘https://xueqiu.com/performance’,
‘accept-language’: ‘zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7’,
‘cookie’: cookie,
}
data = {
‘type’: direction, # 1 是买 2 是卖
‘date’: date,
‘comment’: comment, # 备注
‘gid’: group_id,
‘symbol’: stock_code,
‘price’: price,
‘shares’: shares,
‘tax_rate’: tax_rate, # 卖是千一, 买是 0
‘commission_rate’: ‘0.1’, # 买卖都是万一

}
response = requests.post(‘https://tc.xueqiu.com/tc/snowx/MONI/transaction/add.json’, headers=headers, data=data)

写在后边

时间少,要做的事情有很多,希望能靠谱,做事,就不废话了…

公众号链接(贴图)

雪球模拟组合查询和交易脚本-python

(✪ω✪)