forked from shidenggui/easyquant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
62 lines (42 loc) · 1.91 KB
/
test.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
import easyquotation
import easyquant
import easytrader
from easyquant import DefaultQuotationEngine, DefaultLogHandler, PushBaseEngine
print('easyquant 测试 DEMO')
print('请输入你使用的券商:')
choose = input('1: 华泰 2: 佣金宝 3: 银河 4: 雪球模拟组合\n:')
broker = 'ht'
if choose == '2':
broker = 'yjb'
elif choose == '3':
broker = 'yh'
elif choose == '4':
broker = 'xq'
def get_broker_need_data(choose_broker):
need_data = input('请输入你的帐号配置文件路径(直接回车使用 %s.json)\n:' % choose_broker)
if need_data == '':
return '%s.json' % choose_broker
return need_data
need_data = get_broker_need_data(broker)
class LFEngine(PushBaseEngine):
EventType = 'lf'
def init(self):
self.source = easyquotation.use('lf')
def fetch_quotation(self):
return self.source.stocks(['162411', '000002'])
quotation_choose = input('请输入使用行情引擎 1: sina 2: leverfun 十档 行情(目前只选择了 162411, 000002)\n:')
quotation_engine = DefaultQuotationEngine if quotation_choose == '1' else LFEngine
push_interval = int(input('请输入行情推送间隔(s)\n:'))
quotation_engine.PushInterval = push_interval
log_type_choose = input('请输入 log 记录方式: 1: 显示在屏幕 2: 记录到指定文件\n: ')
log_type = 'stdout' if log_type_choose == '1' else 'file'
log_filepath = input('请输入 log 文件记录路径\n: ') if log_type == 'file' else ''
log_handler = DefaultLogHandler(name='测试', log_type=log_type, filepath=log_filepath)
remove_zero = 1
if broker == 'ht':
remove_zero = input('华泰有些08开头的帐号需要去掉0才能使用,请输入 是否去掉0: 1: 去掉 2: 不去掉\n: ')
user = easytrader.use(broker, remove_zero=remove_zero == 1)
user.prepare(need_data)
m = easyquant.MainEngine(user, quotation_engines=[quotation_engine], log_handler=log_handler)
m.load_strategy()
m.start()