-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfollower.py
More file actions
82 lines (73 loc) · 2.26 KB
/
follower.py
File metadata and controls
82 lines (73 loc) · 2.26 KB
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
# -*- coding: utf-8 -*-
#!/usr/local/bin/python`
import urllib
import re
import math
import sys
import os
import os.path
import thread
import tushare as ts
reload(sys)
sys.setdefaultencoding("utf-8")
import threading
import time
import pandas as pd
from MyStock import *
f = open('pure_code', 'r')
class myThread (threading.Thread):
def __init__(self, name):
threading.Thread.__init__(self)
self.name = name
def run(self):
print "Starting " + self.name
f_out=open("result/follower_%s" % (datetime.today().date().strftime('%Y%m%d')), 'a')
while True:
code = get_code()
if not code:
return
try:
current_data = ts.get_realtime_quotes('%s' % (code))
csv_file = 'qfq_data/%s.csv' % (code)
if not os.path.exists(csv_file):
continue
peak_data = pd.read_csv(csv_file)
if current_data.empty or peak_data.empty:
continue
ph_today = float(current_data['high'].values[0])
price = float(current_data['price'].values[0])
if price > 15:
continue
pre_close = float(current_data['pre_close'].values[0])
pl_today = float(current_data['low'].values[0])
po_today = float(current_data['open'].values[0])
ma5, ma10, ma20, ma30 = get_mas_live_qfq(code, price)
if (ma5 < ma10) or (ma10 < ma20):
continue
if pl_today > ( po_today * 0.96 ) or pl_today > (ma5 * 1.3):
continue
if hist_zt_qfq(peak_data.head(3), code):
print code, ma5, ma10, ma20, ma30
f_out.write('%s\n' % (code))
except Exception as e:
print 'something wrong with code: %s, %s' % (code, str(e))
f_out.close()
def get_code():
threadLock.acquire()
r = f.readline()
threadLock.release()
return r.strip()
threadLock = threading.Lock()
threads = []
# 创建新线程
i = 0
while (i<10):
threads.append(myThread(i))
i = i + 1
# 开启新线程
for thread in threads:
thread.start()
# 等待所有线程完成
for t in threads:
t.join()
f.close()