-
Notifications
You must be signed in to change notification settings - Fork 31
/
HaiTong.py
90 lines (68 loc) · 2.62 KB
/
HaiTong.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import datetime
import easytrader
import json
import sys
from Strategy.gridTrade import grid_bs, time, code2name
if sys.platform == 'linux':
user = ''
elif sys.platform == 'darwin':
user = ''
else:
user = easytrader.use('ths')
user.connect(r'E:\Program Files\东方同花顺\xiadan.exe')
# user.prepare(user='张照博', password='xxx', comm_password='xxx')
# user.prepare('D:\Program Files\海通证券委托\yh_client.json') # 配置文件路径
# user.buy()
class User():
def __init__(self, user):
self.user = user
print(user.balance)
self.zi_jin_yu_e = user.balance['资金余额']
self.ke_yong_jin_e = user.balance['可用金额']
self.ke_qu_jin_e = user.balance['可取金额']
self.zong_zi_chan = user.balance['总资产']
self.stock = Stock(user.position)
def buy(self, code, price, amount):
self.user.buy(code, price, amount)
def sell(self, code, price, amount):
self.user.sell(code, price, amount)
def get_balance(self):
return self.ke_yong_jin_e
def user_refresh(self):
self.user.refresh()
def get_today_trades(self):
return self.user.today_trades
def get_today_entrusts(self):
return self.user.today_entrusts
def show(self):
print("资金余额:%s\n-->\t可用资金:%s\n-->\t可取金额:%s\n-->\t总资产:%s\n-->\t"%(self.zi_jin_yu_e, self.ke_yong_jin_e, self.ke_qu_jin_e, self.zong_zi_chan))
print("当前持仓股票:\n-->\t", self.stock.get_position())
class Stock():
def __init__(self, position):
self.position = position
def get_position(self):
return self.position
def get_Account():
return User(user)
if __name__ == '__main__':
# codes = ['510050', '588000', '601666', '600900', '002044', '000725', '600031']
codes = ['588000']#,'588000', ]#,'159949']
# code2name(codes)
# data = user.position
# for k,v in data.items():
# print(k, v)
# grid_bs(['513550', '002044','000725','600031'], user)
# grid_bs(['600900', '600036', '510050', '002044','000725','600031'], user)
while len(codes) > 0:
if int(datetime.datetime.now().strftime('%H')) < 9:
print("\r九点都没到!!%s")
time.sleep(1800)
elif int(datetime.datetime.now().strftime('%H')) == 9 \
and int(datetime.datetime.now().strftime('%M')) < 29:
print("\r坐等开盘!!%s")
time.sleep(60)
continue
else:
s = grid_bs(codes, user)
codes.remove(s)
# grid_bs(['513550','510050','002044','000725','600031'], user)