-
Notifications
You must be signed in to change notification settings - Fork 4
/
SpotModels.go
178 lines (155 loc) · 3.73 KB
/
SpotModels.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package goghostex
import (
"errors"
"net/http"
"time"
)
/*
models about account
*/
type Account struct {
Exchange string
Asset float64 //总资产
NetAsset float64 //净资产
SubAccounts map[string]SubAccount
}
type SubAccount struct {
Currency Currency
Amount float64
AmountFrozen float64
}
/**
* models about market
**/
type Kline struct {
Pair Pair `json:"symbol"`
Exchange string `json:"exchange"`
Timestamp int64 `json:"timestamp"`
Date string `json:"date"`
Open float64 `json:"open"`
Close float64 `json:"close"`
High float64 `json:"high"`
Low float64 `json:"low"`
Vol float64 `json:"vol"`
}
type OHLC struct {
Symbol string `json:"symbol"`
Exchange string `json:"exchange"`
Timestamp int64 `json:"timestamp"`
Date string `json:"date"`
Open float64 `json:"open"`
Close float64 `json:"close"`
High float64 `json:"high"`
Low float64 `json:"low"`
Vol float64 `json:"vol"`
}
type Ticker struct {
Pair Pair `json:"-"`
Last float64 `json:"last"`
Buy float64 `json:"buy"`
Sell float64 `json:"sell"`
High float64 `json:"high"`
Low float64 `json:"low"`
Vol float64 `json:"vol"`
Timestamp int64 `json:"timestamp"` // unit:ms
Date string `json:"date"` // date: format yyyy-mm-dd HH:MM:SS, the timezone define in apiconfig
}
// record
type Trade struct {
Tid int64 `json:"tid"`
Type TradeSide `json:"type"`
Amount float64 `json:"amount,string"`
Price float64 `json:"price,string"`
Timestamp int64 `json:"timestamp"`
Pair Pair `json:"-"`
}
type DepthRecord struct {
Price float64
Amount float64
}
type DepthRecords []DepthRecord
func (dr DepthRecords) Len() int {
return len(dr)
}
func (dr DepthRecords) Swap(i, j int) {
dr[i], dr[j] = dr[j], dr[i]
}
func (dr DepthRecords) Less(i, j int) bool {
return dr[i].Price < dr[j].Price
}
type Depth struct {
Pair Pair
Timestamp int64
Sequence int64 // The increasing sequence, cause the http return sequence is not sure.
Date string
AskList DepthRecords // Ascending order
BidList DepthRecords // Descending order
}
// Verify the depth data is right
func (depth *Depth) Verify() error {
AskCount := len(depth.AskList)
BidCount := len(depth.BidList)
if BidCount < 10 || AskCount < 10 {
return errors.New("The ask_list or bid_list not enough! ")
}
for i := 1; i < AskCount; i++ {
pre := depth.AskList[i-1]
last := depth.AskList[i]
if pre.Price >= last.Price {
return errors.New("The ask_list is not ascending ordered! ")
}
}
for i := 1; i < BidCount; i++ {
pre := depth.BidList[i-1]
last := depth.BidList[i]
if pre.Price <= last.Price {
return errors.New("The bid_list is not descending ordered! ")
}
}
return nil
}
/**
*
* models about trade
*
**/
type Order struct {
// cid is important, when the order api return wrong, you can find it in unfinished api
Cid string
Price float64
Amount float64
AvgPrice float64
DealAmount float64
Fee float64
OrderId string
OrderTimestamp int64
OrderDate string
Status TradeStatus
Pair Pair
Side TradeSide
//0:NORMAL,1:ONLY_MAKER,2:FOK,3:IOC
OrderType PlaceType
}
/**
*
* models about API config
*
**/
type APIConfig struct {
HttpClient *http.Client
LastTimestamp int64
Endpoint string
ApiKey string
ApiSecretKey string
ApiPassphrase string //for okex.com v3 api
ClientId string //for bitstamp.net , huobi.pro
Location *time.Location
}
type Rule struct {
Pair Pair
Base Currency
Counter Currency
BaseMinSize float64
BasePrecision int
CounterPrecision int
}