forked from nntaoli-project/goex
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Models.go
313 lines (272 loc) · 7.99 KB
/
Models.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
package goex
import (
"fmt"
"net/http"
"time"
)
type Order struct {
Price float64
Amount float64
AvgPrice float64
DealAmount float64
Fee float64
Cid string //客户端自定义ID
OrderID2 string
OrderID int //deprecated
Status TradeStatus
Currency CurrencyPair
Side TradeSide
Type string //limit / market
OrderType int //0:default,1:maker,2:fok,3:ioc
OrderTime int // create timestamp
FinishedTime int64 //finished timestamp
}
type Trade struct {
Tid int64 `json:"tid"`
Type TradeSide `json:"type"`
Amount float64 `json:"amount,string"`
Price float64 `json:"price,string"`
Date int64 `json:"date_ms"`
Pair CurrencyPair `json:"omitempty"`
}
type SubAccount struct {
Currency Currency
Amount float64
ForzenAmount float64
LoanAmount float64
}
type MarginSubAccount struct {
Balance float64
Frozen float64
Available float64
CanWithdraw float64
Loan float64
LendingFee float64
}
type MarginAccount struct {
Sub map[Currency]MarginSubAccount
LiquidationPrice float64
RiskRate float64
MarginRatio float64
}
type Account struct {
Exchange string
Asset float64 //总资产
NetAsset float64 //净资产
SubAccounts map[Currency]SubAccount
}
type Ticker struct {
Pair CurrencyPair `json:"omitempty"`
Last float64 `json:"last,string"`
Buy float64 `json:"buy,string"`
Sell float64 `json:"sell,string"`
High float64 `json:"high,string"`
Low float64 `json:"low,string"`
Vol float64 `json:"vol,string"`
Date uint64 `json:"date"` // 单位:ms
}
type FutureTicker struct {
*Ticker
ContractType string `json:"omitempty"`
ContractId string `json:"contractId"`
LimitHigh float64 `json:"limitHigh,string"`
LimitLow float64 `json:"limitLow,string"`
HoldAmount float64 `json:"hold_amount,string"`
UnitAmount float64 `json:"unitAmount,string"`
}
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 {
ContractType string `json:"contract_type,omitempty"` //for futures
ContractId string `json:"contract_id,omitempty"` // for futures
Pair CurrencyPair
UTime time.Time
AskList DepthRecords // Descending order
BidList DepthRecords // Descending order
}
type APIConfig struct {
HttpClient *http.Client
Endpoint string
ApiKey string
ApiSecretKey string
ApiPassphrase string //for okx.com v3 api
ClientId string //for bitstamp.net , huobi.pro
Lever float64 //杠杆倍数 , for future
}
type Kline struct {
Pair CurrencyPair
Timestamp int64
Open float64
Close float64
High float64
Low float64
Vol float64
}
type FutureKline struct {
*Kline
Vol2 float64 //个数
}
type FutureSubAccount struct {
Currency Currency
AccountRights float64 //账户权益
KeepDeposit float64 //保证金
ProfitReal float64 //已实现盈亏
ProfitUnreal float64
RiskRate float64 //保证金率
}
type FutureAccount struct {
FutureSubAccounts map[Currency]FutureSubAccount
}
type FutureOrder struct {
ClientOid string //自定义ID,GoEx内部自动生成
OrderID2 string //请尽量用这个字段替代OrderID字段
Price float64
Amount float64
AvgPrice float64
DealAmount float64
OrderID int64 //deprecated
OrderTime int64
Status TradeStatus
Currency CurrencyPair
OrderType int //ORDINARY=0 POST_ONLY=1 FOK= 2 IOC= 3
OType int //1:开多 2:开空 3:平多 4: 平空
LeverRate float64 //倍数
Fee float64 //手续费
ContractName string
FinishedTime int64 // finished timestamp
//策略委托单
TriggerPrice float64
AlgoType int //1:限价 2:市场价;触发价格类型,默认是限价;为市场价时,委托价格不必填;
}
type FuturePosition struct {
BuyAmount float64
BuyAvailable float64
BuyPriceAvg float64
BuyPriceCost float64
BuyProfitReal float64
BuyProfit float64
CreateDate int64
LeverRate float64
SellAmount float64
SellAvailable float64
SellPriceAvg float64
SellPriceCost float64
SellProfitReal float64
SellProfit float64
Symbol CurrencyPair //btc_usd:比特币,ltc_usd:莱特币
ContractType string
ContractId int64
ForceLiquPrice float64 //预估爆仓价
ShortPnlRatio float64 //空仓收益率
LongPnlRatio float64 //多仓收益率
}
type HistoricalFunding struct {
InstrumentId string `json:"instrument_id"`
RealizedRate float64 `json:"realized_rate,string"`
FundingTime time.Time `json:"funding_time"`
}
type TickSize struct {
InstrumentID string
UnderlyingIndex string
QuoteCurrency string
PriceTickSize float64 //下单价格精度
AmountTickSize float64 //数量精度
}
type FuturesContractInfo struct {
*TickSize
ContractVal float64 //合约面值(美元)
Delivery string //交割日期
ContractType string // 本周 this_week 次周 next_week 季度 quarter
}
//api parameter struct
type BorrowParameter struct {
CurrencyPair CurrencyPair
Currency Currency
Amount float64
}
type RepaymentParameter struct {
BorrowParameter
BorrowId string
}
type TransferParameter struct {
Currency string `json:"currency"`
From int `json:"from"`
To int `json:"to"`
Amount float64 `json:"amount"`
SubAccount string `json:"sub_account"`
InstrumentId string `json:"instrument_id"`
ToInstrumentId string `json:"to_instrument_id"`
}
type WithdrawParameter struct {
Currency string `json:"currency"`
Amount float64 `json:"amount,string"`
Destination int `json:"destination"` //提币到(2:OKCoin国际 3:OKEx 4:数字货币地址)
ToAddress string `json:"to_address"`
TradePwd string `json:"trade_pwd"`
Fee string `json:"fee"`
}
type DepositWithdrawHistory struct {
WithdrawalId string `json:"withdrawal_id,omitempty"`
Currency string `json:"currency"`
Txid string `json:"txid"`
Amount float64 `json:"amount,string"`
From string `json:"from,omitempty"`
To string `json:"to"`
Memo string `json:"memo,omitempty"`
Fee string `json:"fee"`
Status int `json:"status,string"`
Timestamp time.Time `json:"timestamp"`
}
type PoloniexCurrency struct {
ID int `json:"id"`
Name string `json:"name"`
HumanType string `json:"humanType"`
CurrencyType string `json:"currencyType"`
TxFee string `json:"txFee"`
MinConf int `json:"minConf"`
DepositAddress string `json:"depositAddress"`
Disabled int `json:"disabled"` //Designates whether (1) or not (0) deposits and withdrawals are disabled.
Frozen int `json:"frozen"` //Designates whether (1) or not (0) trading for this currency is disabled for trading.
Blockchain string `json:"blockchain"`
Delisted int `json:"delisted"`
IsGeofenced int `json:"isGeofenced"`
}
type OptionalParameter map[string]interface{}
func (optional OptionalParameter) Optional(name string, value interface{}) OptionalParameter {
optional[name] = value
return optional
}
func (optional OptionalParameter) GetString(name string) string {
return fmt.Sprint(optional[name])
}
func (optional OptionalParameter) GetInt(name string) int {
return ToInt(optional[name])
}
func (optional OptionalParameter) GetInt64(name string) int64 {
return ToInt64(optional[name])
}
func (optional OptionalParameter) GetFloat64(name string) float64 {
return ToFloat64(optional[name])
}
func (optional OptionalParameter) GetTime(name string) *time.Time {
val := optional[name]
if val != nil {
t, ok := val.(time.Time)
if ok {
return &t
}
}
return nil
}