-
Notifications
You must be signed in to change notification settings - Fork 4
/
FutureModels.go
236 lines (207 loc) · 6.01 KB
/
FutureModels.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package goghostex
import (
"errors"
)
const (
CONTRACT_STATUS_PREPARE = "preopen"
CONTRACT_STATUS_LIVE = "live"
CONTRACT_STATUS_SUSPEND = "suspend"
CONTRACT_STATUS_CLOSE = "close"
)
/**
*
* models about account
*
**/
type FutureSubAccount struct {
Currency Currency
// The future margin 期货保证金 == marginFilled+ marginUnFilled
Margin float64
// The future is filled 已经成交的订单占用的期货保证金
MarginDealed float64
// The future is unfilled 未成交的订单占用的保证金
MarginUnDealed float64
// 保证金率
MarginRate float64
// 总值
BalanceTotal float64
// 净值
// BalanceNet = BalanceTotal + ProfitUnreal + ProfitReal
BalanceNet float64
// 可提取
// BalanceAvail = BalanceNet - Margin
BalanceAvail float64
//已实现盈亏
ProfitReal float64
// 未实现盈亏
ProfitUnreal float64
}
type FutureAccount struct {
SubAccount map[Currency]FutureSubAccount
Exchange string
}
/**
*
* models about market
*
**/
type FutureTicker struct {
Ticker
ContractType string `json:"contract_type"`
ContractName string `json:"contract_name"`
}
type FutureDepth struct {
ContractType string // for future
ContractName string // for future
Pair Pair
Timestamp int64
DueTimestamp int64
// The increasing sequence, cause the http return sequence is not sure.
Sequence int64
Date string
AskList DepthRecords // Ascending order
BidList DepthRecords // Descending order
}
// Do not trust the data from exchange, just verify it.
func (fd FutureDepth) Verify() error {
AskCount := len(fd.AskList)
BidCount := len(fd.BidList)
if BidCount < 10 || AskCount < 10 {
return errors.New("The ask_list or bid_list not enough! ")
}
for i := 1; i < AskCount; i++ {
pre := fd.AskList[i-1]
last := fd.AskList[i]
if pre.Price >= last.Price {
return errors.New("The ask_list is not ascending ordered! ")
}
}
for i := 1; i < BidCount; i++ {
pre := fd.BidList[i-1]
last := fd.BidList[i]
if pre.Price <= last.Price {
return errors.New("The bid_list is not descending ordered! ")
}
}
return nil
}
type FutureKline struct {
Kline `json:",-"` // 按照kline中的字段进行解析。
ContractType string `json:"contract_type"`
DueTimestamp int64 `json:"due_timestamp"`
DueDate string `json:"due_date"`
Vol2 float64 `json:"vol_2"` //个数
}
type FutureCandle 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"` // BASE 成交量
Vol2 float64 `json:"vol_2"` // 张数 OR COUNT 成交量
Type string `json:"type"`
DueTimestamp int64 `json:"due_timestamp"`
DueDate string `json:"due_date"`
}
/**
*
* models about trade
*
**/
type FutureOrder struct {
// cid is important, when the order api return wrong, you can find it in unfinished api
Cid string
OrderId string
Price float64
Amount int64
AvgPrice float64
DealAmount int64
PlaceTimestamp int64
PlaceDatetime string
DealTimestamp int64 // unit: ms
DealDatetime string
Status TradeStatus
PlaceType PlaceType // place order type 0:NORMAL 1:MAKER_ONLY 2:FOK 3:IOC
Type FutureType // type 1:OPEN_LONG 2:OPEN_SHORT 3:LIQUIDATE_LONG 4: LIQUIDATE_SHORT
LeverRate int64
Fee float64
Pair Pair
ContractType string
ContractName string // for future
Exchange string
}
type FuturePosition struct {
BuyAmount float64
BuyAvailable float64
BuyPriceAvg float64
BuyPriceCost float64
BuyProfitReal float64
CreateDate int64
LeverRate int
SellAmount float64
SellAvailable float64
SellPriceAvg float64
SellPriceCost float64
SellProfitReal float64
Symbol Pair //btc_usd:比特币,ltc_usd:莱特币
ContractType string
ContractId int64
ForceLiquidatePrice float64 //预估爆仓价
}
/**
*
* models about API config
*
*/
type FutureAPIConfig struct {
APIConfig
Lever int // lever number , for future
}
type FutureRule struct {
Rule `json:",-"` // 按照Rule里面的规则进行。
ContractVal float64 `json:"contract_val"` //合约一手价格
}
type FutureContract struct {
Pair Pair `json:"-"`
Symbol string `json:"symbol"`
Exchange string `json:"exchange"`
ContractType string `json:"contract_type"` // eg: this_week next_week quarter next_quarter
ContractName string `json:"contract_name"` // eg: BTC-USD-201025
SettleMode int64 `json:"settle_mode"` // 1: BASIS 2: COUNTER
Status string `json:"status"`
Type string `json:"type"` // linear or inverse
OpenTimestamp int64 `json:"open_timestamp"`
OpenDate string `json:"open_date"`
ListTimestamp int64 `json:"list_timestamp"`
ListDate string `json:"list_date"`
DueTimestamp int64 `json:"due_timestamp"`
DueDate string `json:"due_date"`
UnitAmount float64 `json:"unit_amount"`
TickSize float64 `json:"tick_size"`
PricePrecision int64 `json:"price_precision"`
AmountPrecision int64 `json:"amount_precision"`
MaxScalePriceLimit float64 `json:"max_scale_price_limit"`
MinScalePriceLimit float64 `json:"min_scale_price_limit"`
RawData string `json:"raw_data"`
}
type FutureContracts struct {
ContractTypeKV map[string]*FutureContract `json:"contract_type_kv"`
ContractNameKV map[string]*FutureContract `json:"contract_name_kv"`
DueTimestampKV map[string]*FutureContract `json:"due_timestamp_kv"`
}
type FutureAccountItem struct {
Pair Pair
ContractName string
Exchange string
Subject string
SettleMode int64 // 1: basis 2: counter
SettleCurrency Currency
Amount float64
Timestamp int64
DateTime string
Info string
}