雪球模拟组合查询和交易脚本-python 发表于 2022-01-11 | 字数统计: 422 字 | 阅读时长 ≈ 2 分钟 Talk cheap, show code12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667import requestsimport json# 使用前需要替换 cookie 和 组合 id, 怎么找见下边截图/链接cookie = your_cookiesgroup_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 (✪ω✪) 打赏 支付宝