-
Notifications
You must be signed in to change notification settings - Fork 0
/
abhunting.go
149 lines (121 loc) · 2.7 KB
/
abhunting.go
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package main
import (
"fmt"
"os"
"os/signal"
"sort"
"strconv"
"sync"
"time"
"github.com/whomm/a-bargain-hunting/util"
)
type Int64Slice []int64
func (p Int64Slice) Len() int { return len(p) }
func (p Int64Slice) Less(i, j int) bool { return p[i] < p[j] }
func (p Int64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
var blist sync.Map
var c chan os.Signal
func ndaylow(code string, day int) {
var xp []util.IfengKdata
for retry := 0; retry < 3; retry++ {
var err error
xp, err = util.Get_k_daily(code)
if err == nil && len(xp) > 0 {
break
}
if retry == 2 {
fmt.Println("get history data error :" + code)
return
}
time.Sleep(time.Second)
}
length := len(xp) - 1
theb := util.Bargain{}
theb.Low = 10000000
theb.Code = code
theb.Day = day
var volumendaylist Int64Slice
for i := 0; i < day; i++ {
if length >= i {
if xp[length-i].Low < theb.Low {
theb.Low = xp[length-i].Low
}
volumendaylist = append(volumendaylist, xp[length-i].Volume)
}
}
sort.Sort(volumendaylist)
//计算中位数
if day&1 == 1 {
theb.VolumeMe = volumendaylist[day/2]
} else {
theb.VolumeMe = (volumendaylist[day/2] + volumendaylist[day/2-1]) / 2
}
//fmt.Println(volumendaylist, theb.VolumeMe)
for {
g, err := util.Get_real_time_data(code)
if err == nil {
theb.Update(g)
blist.Store(code, theb)
}
time.Sleep(time.Second)
}
}
//Tolow 最低价涨幅
type Tolow struct {
code string
tolow float64
tome float64
}
//Tolowlist 最低价涨幅排序列表
type Tolowlist []Tolow
func (s Tolowlist) Len() int {
return len(s)
}
func (s Tolowlist) Less(i, j int) bool {
return s[i].tolow < s[j].tolow
}
func (s Tolowlist) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func getbydes() {
fmt.Print("\033[2J")
for {
tolowlist := Tolowlist{}
blist.Range(func(key, i interface{}) bool {
tolowlist = append(tolowlist, Tolow{code: i.(util.Bargain).Code, tolow: i.(util.Bargain).Tolow})
return true
})
sort.Sort(tolowlist)
lineno := 2
fmt.Print("\033[1;0H\033[K股票代码\t 股票名称\t价格\t价变\t成交量 \t量变\t最低价\t 量中位数 \t周期/天\t更新时间")
for _, j := range tolowlist {
if now, ok := blist.Load(j.code); ok {
fmt.Print("\033[" + strconv.Itoa(lineno) + ";0H\033[K" + now.(util.Bargain).Tosting())
}
lineno++
if lineno >= 50 {
break
}
}
time.Sleep(time.Second)
}
}
func main() {
c = make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
for _, stockc := range util.Zz500 {
go ndaylow(stockc[0], 30)
}
go getbydes()
LOOP:
for {
select {
case s := <-c:
fmt.Println()
fmt.Println("interf", s)
break LOOP
default:
}
time.Sleep(500 * time.Millisecond)
}
}