-
Notifications
You must be signed in to change notification settings - Fork 6
/
account.go
288 lines (250 loc) · 9.85 KB
/
account.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
// Account Data Endpoints (https://bybit-exchange.github.io/docs/spot/v1/#t-accountdata)
package spot
type OrderBase struct {
AccountID string `json:"accountId"`
OrderID string `json:"orderId"`
OrderLinkID string `json:"orderLinkId"`
Symbol string `json:"symbol"`
SymbolName string `json:"symbolName"`
Price string `json:"price"`
OrigQty string `json:"origQty"`
ExecutedQty string `json:"executedQty"`
OrderType OrderType `json:"type"`
OrderStatus OrderStatus `json:"status"`
TimeInForce TimeInForce `json:"timeInForce"`
}
// Place Active Order (https://bybit-exchange.github.io/docs/spot/v1/#t-placeactive)
//
// symbol Required string Name of the trading pair
// qty Required number Order quantity (for market orders: when side is Buy, this is in the quote currency.
// Otherwise, qty is in the base currency. For example, on BTCUSDT a Buy order is in USDT, otherwise it's in BTC.
// For limit orders, the qty is always in the base currency.)
// side Required string Order direction
// type Required string Order type
// timeInForce string Time in force
// price number Order price. When the type field is MARKET, the price field is optional. When the type field is LIMIT or LIMIT_MAKER,
// the price field is required
// orderLinkId string User-generated order ID
type PlaceOrder struct {
Symbol string `param:"symbol"`
Qty int `param:"qty"`
Side Side `param:"side"`
Type OrderType `param:"type"`
TimeInForce *TimeInForce `param:"timeInForce"`
Price *Price `param:"price"`
OrderLinkID *string `param:"orderLinkId"`
}
func (this PlaceOrder) Do(client *Client) (OrderCreated, error) {
return Post[OrderCreated](client, "order", this)
}
type OrderCreated struct {
OrderBase
TransactTime string `json:"transactTime"`
}
func (this *Client) PlaceOrder(v PlaceOrder) (OrderCreated, error) {
return v.Do(this)
}
// Get Active Order (https://bybit-exchange.github.io/docs/spot/v1/#t-getactive)
//
// orderId string Order ID. Required if not passing orderLinkId
// orderLinkId string Unique user-set order ID. Required if not passing orderId
type GetOrder struct {
OrderID *string `param:"orderId"`
OrderLinkID *string `param:"orderLinkId"`
}
func (this GetOrder) Do(client *Client) (Order, error) {
return Get[Order](client, "order", this)
}
type Order struct {
OrderHistoryResult
Locked string `json:"locked"`
}
func (this *Client) GetOrder(v GetOrder) (Order, error) {
return v.Do(this)
}
// Cancel Active Order (https://bybit-exchange.github.io/docs/spot/v1/#t-cancelactive)
//
// orderId string Order ID. Required if not passing orderLinkId
// orderLinkId string Unique user-set order ID. Required if not passing orderId
type CancelOrder struct {
OrderID *string `param:"orderId"`
OrderLinkID *string `param:"orderLinkId"`
}
func (this CancelOrder) Do(client *Client) (OrderCancelled, error) {
return Delete[OrderCancelled](client, "order", this)
}
type OrderCancelled struct {
OrderCreated
Side string `json:"side"`
}
func (this *Client) CancelOrder(v CancelOrder) (OrderCancelled, error) {
return v.Do(this)
}
// Fast Cancel Active Order (https://bybit-exchange.github.io/docs/spot/v1/#t-fastcancelactiveorder)
//
// symbolId Required string Name of the trading pair
// orderId string Order ID. Required if not passing orderLinkId
// orderLinkId string Unique user-set order ID. Required if not passing orderId
type FastCancelOrder struct {
Symbol string `param:"symbolId"`
OrderID *string `param:"orderId"`
OrderLinkID *string `param:"orderLinkId"`
}
func (this FastCancelOrder) Do(client *Client) (bool, error) {
type result struct {
IsCancelled bool `json:"isCancelled"`
}
r, err := Delete[result](client, "order/fast", this)
return r.IsCancelled, err
}
func (this *Client) FastCancelOrder(v FastCancelOrder) (bool, error) {
return v.Do(this)
}
// Batch Cancel Active Order (https://bybit-exchange.github.io/docs/spot/v1/#t-batchcancelactiveorder)
//
// symbol Required string Name of the trading pair
// side string Order direction
// orderTypes string Order type. Use commas to indicate multiple order types, eg LIMIT,LIMIT_MAKER. Default: LIMIT
type BatchCancelOrder struct {
Symbol string `param:"symbol"`
Side *Side `param:"side"`
Type *OrderType `param:"orderTypes"`
}
func (this BatchCancelOrder) Do(client *Client) (bool, error) {
type result struct {
Success bool `json:"success"`
}
r, err := Delete[result](client, "order/batch-cancel", this)
return r.Success, err
}
func (this *Client) BatchCancelOrder(v BatchCancelOrder) (bool, error) {
return v.Do(this)
}
// Batch Fast Cancel Active Order (https://bybit-exchange.github.io/docs/spot/v1/#t-batchfastcancelactiveorder)
type BatchFastCancelOrder struct {
Symbol string `param:"symbol"`
Side *Side `param:"side"`
Type *OrderType `param:"orderTypes"`
}
func (this BatchFastCancelOrder) Do(client *Client) (bool, error) {
type result struct {
Success bool `json:"success"`
}
r, err := Delete[result](client, "order/batch-fast-cancel", this)
return r.Success, err
}
func (this *Client) BatchFastCancelOrder(v BatchFastCancelOrder) (bool, error) {
return v.Do(this)
}
// Batch Cancel Active Order By IDs (https://bybit-exchange.github.io/docs/spot/v1/#t-batchcancelactiveorderbyids)
//
// orderIds Required string Order ID, use commas to indicate multiple orderIds. Maximum of 100 ids.
type BatchCancelOrderByID struct {
ID []string `param:"orderIds"`
}
func (this BatchCancelOrderByID) Do(client *Client) ([]CancelOrderID, error) {
return Delete[[]CancelOrderID](client, "order/batch-cancel-by-ids", this)
}
type CancelOrderID struct {
OrderID string `json:"orderId"`
Code int `json:"code"`
}
func (this *Client) BatchCancelOrderByID(ID []string) ([]CancelOrderID, error) {
return BatchCancelOrderByID{ID: ID}.Do(this)
}
// Open Orders (https://bybit-exchange.github.io/docs/spot/v1/#t-openorders)
//
// symbol string Name of the trading pair
// orderId string Specify orderId to return all the orders that orderId of which are smaller than this particular one for pagination purpose
// limit integer Default value is 500, max 500
type OpenOrders struct {
Symbol *string `param:"symbol"`
OrderID *string `param:"orderId"`
Limit *int `param:"limit"`
}
func (this OpenOrders) Do(client *Client) ([]OrderBase, error) {
return Get[[]OrderBase](client, "open-orders", this)
}
func (this *Client) OpenOrders(v OpenOrders) ([]OrderBase, error) {
return v.Do(this)
}
// Order History (https://bybit-exchange.github.io/docs/spot/v1/#t-orderhistory)
//
// symbol string Name of the trading pair
// orderId string Specify orderId to return all the orders that orderId of which are smaller than this particular one for pagination purpose
// limit integer Default value is 500, max 500
// startTime long Start time, unit in millisecond
// endTime long End time, unit in millisecond
type OrderHistory struct {
Symbol *string `param:"symbol"`
OrderID *string `param:"orderId"`
Limit *int `param:"limit"`
StartTime *uint64 `param:"startTime"`
EndTime *uint64 `param:"endTime"`
}
func (this OrderHistory) Do(client *Client) ([]OrderHistoryResult, error) {
return Get[[]OrderHistoryResult](client, "history-orders", this)
}
type OrderHistoryResult struct {
OrderBase
ExchangeId string `json:"exchangeId"`
CummulativeQuoteQty string `json:"cummulativeQuoteQty"`
AvgPrice string `json:"avgPrice"`
StopPrice string `json:"stopPrice"`
IcebergQty string `json:"icebergQty"`
Time string `json:"time"`
UpdateTime string `json:"updateTime"`
IsWorking bool `json:"isWorking"`
}
func (this *Client) OrderHistory(v OrderHistory) ([]OrderHistoryResult, error) {
return v.Do(this)
}
// Trade History (https://bybit-exchange.github.io/docs/spot/v1/#t-tradehistory)
//
// symbol string Name of the trading pair
// limit integer Default value is 50, max 50
// fromTicketId integer Query greater than the trade ID. (fromTicketId < trade ID)
// toTicketId integer Query smaller than the trade ID. (trade ID < toTicketId)
// orderId integer Order ID
// startTime long Start time, unit in millisecond
// endTime long End time, unit in millisecond
type TradeHistory struct {
Symbol *string `param:"symbol"`
Limit *int `param:"limit"`
FromTicketID *int `param:"fromTicketId"`
ToTicketID *int `param:"toTicketId"`
OrderID *string `param:"orderId"`
StartTime *uint64 `param:"startTime"`
EndTime *uint64 `param:"endTime"`
}
func (this TradeHistory) Do(client *Client) ([]Trade, error) {
return Get[[]Trade](client, "myTrades", this)
}
type Trade struct {
ID string `json:"id"`
Symbol string `json:"symbol"`
SymbolName string `json:"symbolName"`
OrderID string `json:"orderId"`
TicketID string `json:"ticketId"`
MatchOrderID string `json:"matchOrderId"`
Price string `json:"price"`
Qty string `json:"qty"`
Commission string `json:"commission"`
CommissionAsset string `json:"commissionAsset"`
Time string `json:"time"`
IsBuyer bool `json:"isBuyer"`
IsMaker bool `json:"isMaker"`
Fee TradeFee `json:"fee"`
FeeTokenID string `json:"feeTokenId"`
FeeAmount string `json:"feeAmount"`
MakerRebate string `json:"makerRebate"`
ExecutionTime string `json:"executionTime"`
}
type TradeFee struct {
TokenID string `json:"feeTokenId"`
TokenName string `json:"feeTokenName"`
Fee string `json:"fee"`
}
func (this *Client) TradeHistory(v TradeHistory) ([]Trade, error) {
return v.Do(this)
}