forked from BitMEX/api-connectors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder_api.go
683 lines (587 loc) · 31.2 KB
/
order_api.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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
/*
* BitMEX API
*
* ## REST API for the BitMEX Trading Platform [Changelog](/app/apiChangelog) #### Getting Started ##### Fetching Data All REST endpoints are documented below. You can try out any query right from this interface. Most table queries accept `count`, `start`, and `reverse` params. Set `reverse=true` to get rows newest-first. Additional documentation regarding filters, timestamps, and authentication is available in [the main API documentation](https://www.bitmex.com/app/restAPI). *All* table data is available via the [Websocket](/app/wsAPI). We highly recommend using the socket if you want to have the quickest possible data without being subject to ratelimits. ##### Return Types By default, all data is returned as JSON. Send `?_format=csv` to get CSV data or `?_format=xml` to get XML data. ##### Trade Data Queries *This is only a small subset of what is available, to get you started.* Fill in the parameters and click the `Try it out!` button to try any of these queries. * [Pricing Data](#!/Quote/Quote_get) * [Trade Data](#!/Trade/Trade_get) * [OrderBook Data](#!/OrderBook/OrderBook_getL2) * [Settlement Data](#!/Settlement/Settlement_get) * [Exchange Statistics](#!/Stats/Stats_history) Every function of the BitMEX.com platform is exposed here and documented. Many more functions are available. - ## All API Endpoints Click to expand a section.
*
* OpenAPI spec version: 1.2.0
* Contact: [email protected]
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package swagger
import (
"strings"
"fmt"
"errors"
"net/url"
"time"
"encoding/json"
)
type OrderApi struct {
Configuration Configuration
}
func NewOrderApi() *OrderApi {
configuration := NewConfiguration()
return &OrderApi{
Configuration: *configuration,
}
}
func NewOrderApiWithBasePath(basePath string) *OrderApi {
configuration := NewConfiguration()
configuration.BasePath = basePath
return &OrderApi{
Configuration: *configuration,
}
}
/**
* Amend the quantity or price of an open order.
* Send an `orderID` or `origClOrdID` to identify the order you wish to amend. Both order quantity and price can be amended. Only one `qty` field can be used to amend. Use the `leavesQty` field to specify how much of the order you wish to remain open. This can be useful if you want to adjust your position's delta by a certain amount, regardless of how much of the order has already filled. Use the `simpleOrderQty` and `simpleLeavesQty` fields to specify order size in Bitcoin, rather than contracts. These fields will round up to the nearest contract. Like order placement, amending can be done in bulk. Simply send a request to `PUT /api/v1/order/bulk` with a JSON body of the shape: `{\"orders\": [{...}, {...}]}`, each object containing the fields used in this endpoint.
*
* @param orderID Order ID
* @param origClOrdID Client Order ID. See POST /order.
* @param clOrdID Optional new Client Order ID, requires `origClOrdID`.
* @param simpleOrderQty Optional order quantity in units of the underlying instrument (i.e. Bitcoin).
* @param orderQty Optional order quantity in units of the instrument (i.e. contracts).
* @param simpleLeavesQty Optional leaves quantity in units of the underlying instrument (i.e. Bitcoin). Useful for amending partially filled orders.
* @param leavesQty Optional leaves quantity in units of the instrument (i.e. contracts). Useful for amending partially filled orders.
* @param price Optional limit price for 'Limit', 'StopLimit', and 'LimitIfTouched' orders.
* @param stopPx Optional trigger price for 'Stop', 'StopLimit', 'MarketIfTouched', and 'LimitIfTouched' orders. Use a price below the current price for stop-sell orders and buy-if-touched orders.
* @param pegOffsetValue Optional trailing offset from the current price for 'Stop', 'StopLimit', 'MarketIfTouched', and 'LimitIfTouched' orders; use a negative offset for stop-sell orders and buy-if-touched orders. Optional offset from the peg price for 'Pegged' orders.
* @param text Optional amend annotation. e.g. 'Adjust skew'.
* @return *Order
*/
func (a OrderApi) OrderAmend(orderID string, origClOrdID string, clOrdID string, simpleOrderQty float64, orderQty float32, simpleLeavesQty float64, leavesQty float32, price float64, stopPx float64, pegOffsetValue float64, text string) (*Order, *APIResponse, error) {
var httpMethod = "Put"
// create path and map variables
path := a.Configuration.BasePath + "/order"
headerParams := make(map[string]string)
queryParams := url.Values{}
formParams := make(map[string]string)
var postBody interface{}
var fileName string
var fileBytes []byte
// add default headers if any
for key := range a.Configuration.DefaultHeader {
headerParams[key] = a.Configuration.DefaultHeader[key]
}
// to determine the Content-Type header
localVarHttpContentTypes := []string{ "application/json", "application/x-www-form-urlencoded", }
// set Content-Type header
localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string{
"application/json",
"application/xml",
"text/xml",
"application/javascript",
"text/javascript",
}
// set Accept header
localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
headerParams["Accept"] = localVarHttpHeaderAccept
}
formParams["orderID"] = orderID
formParams["origClOrdID"] = origClOrdID
formParams["clOrdID"] = clOrdID
formParams["simpleOrderQty"] = simpleOrderQty
formParams["orderQty"] = orderQty
formParams["simpleLeavesQty"] = simpleLeavesQty
formParams["leavesQty"] = leavesQty
formParams["price"] = price
formParams["stopPx"] = stopPx
formParams["pegOffsetValue"] = pegOffsetValue
formParams["text"] = text
var successPayload = new(Order)
httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil {
return successPayload, NewAPIResponse(httpResponse.RawResponse), err
}
err = json.Unmarshal(httpResponse.Body(), &successPayload)
return successPayload, NewAPIResponse(httpResponse.RawResponse), err
}
/**
* Amend multiple orders.
* Similar to POST /amend, but with multiple orders. `application/json` only. Ratelimited at 50%.
*
* @param orders An array of orders.
* @return []Order
*/
func (a OrderApi) OrderAmendBulk(orders string) ([]Order, *APIResponse, error) {
var httpMethod = "Put"
// create path and map variables
path := a.Configuration.BasePath + "/order/bulk"
headerParams := make(map[string]string)
queryParams := url.Values{}
formParams := make(map[string]string)
var postBody interface{}
var fileName string
var fileBytes []byte
// add default headers if any
for key := range a.Configuration.DefaultHeader {
headerParams[key] = a.Configuration.DefaultHeader[key]
}
// to determine the Content-Type header
localVarHttpContentTypes := []string{ "application/json", "application/x-www-form-urlencoded", }
// set Content-Type header
localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string{
"application/json",
"application/xml",
"text/xml",
"application/javascript",
"text/javascript",
}
// set Accept header
localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
headerParams["Accept"] = localVarHttpHeaderAccept
}
formParams["orders"] = orders
var successPayload = new([]Order)
httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil {
return *successPayload, NewAPIResponse(httpResponse.RawResponse), err
}
err = json.Unmarshal(httpResponse.Body(), &successPayload)
return *successPayload, NewAPIResponse(httpResponse.RawResponse), err
}
/**
* Cancel order(s). Send multiple order IDs to cancel in bulk.
* Either an orderID or a clOrdID must be provided.
*
* @param orderID Order ID(s).
* @param clOrdID Client Order ID(s). See POST /order.
* @param text Optional cancellation annotation. e.g. 'Spread Exceeded'.
* @return []Order
*/
func (a OrderApi) OrderCancel(orderID string, clOrdID string, text string) ([]Order, *APIResponse, error) {
var httpMethod = "Delete"
// create path and map variables
path := a.Configuration.BasePath + "/order"
headerParams := make(map[string]string)
queryParams := url.Values{}
formParams := make(map[string]string)
var postBody interface{}
var fileName string
var fileBytes []byte
// add default headers if any
for key := range a.Configuration.DefaultHeader {
headerParams[key] = a.Configuration.DefaultHeader[key]
}
// to determine the Content-Type header
localVarHttpContentTypes := []string{ "application/json", "application/x-www-form-urlencoded", }
// set Content-Type header
localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string{
"application/json",
"application/xml",
"text/xml",
"application/javascript",
"text/javascript",
}
// set Accept header
localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
headerParams["Accept"] = localVarHttpHeaderAccept
}
formParams["orderID"] = orderID
formParams["clOrdID"] = clOrdID
formParams["text"] = text
var successPayload = new([]Order)
httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil {
return *successPayload, NewAPIResponse(httpResponse.RawResponse), err
}
err = json.Unmarshal(httpResponse.Body(), &successPayload)
return *successPayload, NewAPIResponse(httpResponse.RawResponse), err
}
/**
* Cancels all of your orders.
*
* @param symbol Optional symbol. If provided, only cancels orders for that symbol.
* @param filter Optional filter for cancellation. Use to only cancel some orders, e.g. `{\"side\": \"Buy\"}`.
* @param text Optional cancellation annotation. e.g. 'Spread Exceeded'
* @return *Object
*/
func (a OrderApi) OrderCancelAll(symbol string, filter string, text string) (*Object, *APIResponse, error) {
var httpMethod = "Delete"
// create path and map variables
path := a.Configuration.BasePath + "/order/all"
headerParams := make(map[string]string)
queryParams := url.Values{}
formParams := make(map[string]string)
var postBody interface{}
var fileName string
var fileBytes []byte
// add default headers if any
for key := range a.Configuration.DefaultHeader {
headerParams[key] = a.Configuration.DefaultHeader[key]
}
// to determine the Content-Type header
localVarHttpContentTypes := []string{ "application/json", "application/x-www-form-urlencoded", }
// set Content-Type header
localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string{
"application/json",
"application/xml",
"text/xml",
"application/javascript",
"text/javascript",
}
// set Accept header
localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
headerParams["Accept"] = localVarHttpHeaderAccept
}
formParams["symbol"] = symbol
formParams["filter"] = filter
formParams["text"] = text
var successPayload = new(Object)
httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil {
return successPayload, NewAPIResponse(httpResponse.RawResponse), err
}
err = json.Unmarshal(httpResponse.Body(), &successPayload)
return successPayload, NewAPIResponse(httpResponse.RawResponse), err
}
/**
* Automatically cancel all your orders after a specified timeout.
* Useful as a dead-man's switch to ensure your orders are canceled in case of an outage. If called repeatedly, the existing offset will be canceled and a new one will be inserted in its place. Example usage: call this route at 15s intervals with an offset of 60000 (60s). If this route is not called within 60 seconds, all your orders will be automatically canceled. This is also available via [WebSocket](https://www.bitmex.com/app/wsAPI#dead-man-s-switch-auto-cancel-).
*
* @param timeout Timeout in ms. Set to 0 to cancel this timer.
* @return *Object
*/
func (a OrderApi) OrderCancelAllAfter(timeout float64) (*Object, *APIResponse, error) {
var httpMethod = "Post"
// create path and map variables
path := a.Configuration.BasePath + "/order/cancelAllAfter"
// verify the required parameter 'timeout' is set
if &timeout == nil {
return new(Object), nil, errors.New("Missing required parameter 'timeout' when calling OrderApi->OrderCancelAllAfter")
}
headerParams := make(map[string]string)
queryParams := url.Values{}
formParams := make(map[string]string)
var postBody interface{}
var fileName string
var fileBytes []byte
// add default headers if any
for key := range a.Configuration.DefaultHeader {
headerParams[key] = a.Configuration.DefaultHeader[key]
}
// to determine the Content-Type header
localVarHttpContentTypes := []string{ "application/json", "application/x-www-form-urlencoded", }
// set Content-Type header
localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string{
"application/json",
"application/xml",
"text/xml",
"application/javascript",
"text/javascript",
}
// set Accept header
localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
headerParams["Accept"] = localVarHttpHeaderAccept
}
formParams["timeout"] = timeout
var successPayload = new(Object)
httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil {
return successPayload, NewAPIResponse(httpResponse.RawResponse), err
}
err = json.Unmarshal(httpResponse.Body(), &successPayload)
return successPayload, NewAPIResponse(httpResponse.RawResponse), err
}
/**
* Close a position. [Deprecated, use POST /order with execInst: 'Close']
* If no `price` is specified, a market order will be submitted to close the whole of your position. This will also close all other open orders in this symbol.
*
* @param symbol Symbol of position to close.
* @param price Optional limit price.
* @return *Order
*/
func (a OrderApi) OrderClosePosition(symbol string, price float64) (*Order, *APIResponse, error) {
var httpMethod = "Post"
// create path and map variables
path := a.Configuration.BasePath + "/order/closePosition"
// verify the required parameter 'symbol' is set
if &symbol == nil {
return new(Order), nil, errors.New("Missing required parameter 'symbol' when calling OrderApi->OrderClosePosition")
}
headerParams := make(map[string]string)
queryParams := url.Values{}
formParams := make(map[string]string)
var postBody interface{}
var fileName string
var fileBytes []byte
// add default headers if any
for key := range a.Configuration.DefaultHeader {
headerParams[key] = a.Configuration.DefaultHeader[key]
}
// to determine the Content-Type header
localVarHttpContentTypes := []string{ "application/json", "application/x-www-form-urlencoded", }
// set Content-Type header
localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string{
"application/json",
"application/xml",
"text/xml",
"application/javascript",
"text/javascript",
}
// set Accept header
localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
headerParams["Accept"] = localVarHttpHeaderAccept
}
formParams["symbol"] = symbol
formParams["price"] = price
var successPayload = new(Order)
httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil {
return successPayload, NewAPIResponse(httpResponse.RawResponse), err
}
err = json.Unmarshal(httpResponse.Body(), &successPayload)
return successPayload, NewAPIResponse(httpResponse.RawResponse), err
}
/**
* Get your orders.
* To get open orders only, send {\"open\": true} in the filter param. See <a href=\"http://www.onixs.biz/fix-dictionary/5.0.SP2/msgType_D_68.html\">the FIX Spec</a> for explanations of these fields.
*
* @param symbol Instrument symbol. Send a bare series (e.g. XBU) to get data for the nearest expiring contract in that series. You can also send a timeframe, e.g. `XBU:monthly`. Timeframes are `daily`, `weekly`, `monthly`, `quarterly`, and `biquarterly`.
* @param filter Generic table filter. Send JSON key/value pairs, such as `{\"key\": \"value\"}`. You can key on individual fields, and do more advanced querying on timestamps. See the [Timestamp Docs](https://www.bitmex.com/app/restAPI#timestamp-filters) for more details.
* @param columns Array of column names to fetch. If omitted, will return all columns. Note that this method will always return item keys, even when not specified, so you may receive more columns that you expect.
* @param count Number of results to fetch.
* @param start Starting point for results.
* @param reverse If true, will sort results newest first.
* @param startTime Starting date filter for results.
* @param endTime Ending date filter for results.
* @return []Order
*/
func (a OrderApi) OrderGetOrders(symbol string, filter string, columns string, count float32, start float32, reverse bool, startTime time.Time, endTime time.Time) ([]Order, *APIResponse, error) {
var httpMethod = "Get"
// create path and map variables
path := a.Configuration.BasePath + "/order"
headerParams := make(map[string]string)
queryParams := url.Values{}
formParams := make(map[string]string)
var postBody interface{}
var fileName string
var fileBytes []byte
// add default headers if any
for key := range a.Configuration.DefaultHeader {
headerParams[key] = a.Configuration.DefaultHeader[key]
}
queryParams.Add("symbol", a.Configuration.APIClient.ParameterToString(symbol, ""))
queryParams.Add("filter", a.Configuration.APIClient.ParameterToString(filter, ""))
queryParams.Add("columns", a.Configuration.APIClient.ParameterToString(columns, ""))
queryParams.Add("count", a.Configuration.APIClient.ParameterToString(count, ""))
queryParams.Add("start", a.Configuration.APIClient.ParameterToString(start, ""))
queryParams.Add("reverse", a.Configuration.APIClient.ParameterToString(reverse, ""))
queryParams.Add("startTime", a.Configuration.APIClient.ParameterToString(startTime, ""))
queryParams.Add("endTime", a.Configuration.APIClient.ParameterToString(endTime, ""))
// to determine the Content-Type header
localVarHttpContentTypes := []string{ "application/json", "application/x-www-form-urlencoded", }
// set Content-Type header
localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string{
"application/json",
"application/xml",
"text/xml",
"application/javascript",
"text/javascript",
}
// set Accept header
localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
headerParams["Accept"] = localVarHttpHeaderAccept
}
var successPayload = new([]Order)
httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil {
return *successPayload, NewAPIResponse(httpResponse.RawResponse), err
}
err = json.Unmarshal(httpResponse.Body(), &successPayload)
return *successPayload, NewAPIResponse(httpResponse.RawResponse), err
}
/**
* Create a new order.
* This endpoint is used for placing orders. Valid order types are Market, Limit, Stop, StopLimit, MarketIfTouched, LimitIfTouched, MarketWithLeftOverAsLimit, and Pegged. If no order type is provided, BitMEX will assume 'Limit'. Be very careful with 'Market' and 'Stop' orders as you may be filled at an unfavourable price. You can submit bulk orders by POSTing an array of orders to `/api/v1/order/bulk`. Send a JSON payload with the shape: `{\"orders\": [{...}, {...}]}`, with each inner object containing the same fields that would be sent to this endpoint. A note on API tools: if you want to keep track of order IDs yourself, set a unique clOrdID per order. This clOrdID will come back as a property on the order and any related executions (including on the WebSocket), and can be used to get or cancel the order. Max length is 36 characters. To generate a clOrdID, consider setting a prefix, and incrementing a counter or generating a UUID. Some UUIDs are longer than 36 characters, so use a url-safe base64 encoding. For example, the prefix `'bmex_mm_'` and the UUID `'7fbd6545-bb0c-11e4-a273-6003088a7c04'` creates `'bmex_mm_f71lRbsMEeSic2ADCIp8BA'`. See the [BitMEX Reference Market Maker](https://github.com/BitMEX/market-maker/blob/22c75a2b6db63e20212813e9afdb845db1b09b2a/bitmex.py#L152) for an example of how to use and generate clOrdIDs.
*
* @param symbol Instrument symbol. e.g. 'XBT24H'.
* @param side Order side. Valid options: Buy, Sell. Defaults to 'Buy' unless `orderQty` or `simpleOrderQty` is negative.
* @param simpleOrderQty Order quantity in units of the underlying instrument (i.e. Bitcoin).
* @param quantity Deprecated: use `orderQty`.
* @param orderQty Order quantity in units of the instrument (i.e. contracts).
* @param price Optional limit price for 'Limit', 'StopLimit', and 'LimitIfTouched' orders.
* @param displayQty Optional quantity to display in the book. Use 0 for a hidden order.
* @param stopPrice Deprecated: use `stopPx`.
* @param stopPx Optional trigger price for 'Stop', 'StopLimit', 'MarketIfTouched', and 'LimitIfTouched' orders. Use a price below the current price for stop-sell orders and buy-if-touched orders. Use `execInst` of 'MarkPrice' or 'LastPrice' to define the current price used for triggering.
* @param clOrdID Optional Client Order ID. This clOrdID will come back on the order and any related executions.
* @param clOrdLinkID Optional Client Order Link ID for contingent orders.
* @param pegOffsetValue Optional trailing offset from the current price for 'Stop', 'StopLimit', 'MarketIfTouched', and 'LimitIfTouched' orders; use a negative offset for stop-sell orders and buy-if-touched orders. Optional offset from the peg price for 'Pegged' orders.
* @param pegPriceType Optional peg price type. Valid options: LastPeg, MidPricePeg, MarketPeg, PrimaryPeg, TrailingStopPeg, TrailingStopPeg.
* @param type_ Deprecated: use `ordType`.
* @param ordType Order type. Valid options: Market, Limit, Stop, StopLimit, MarketIfTouched, LimitIfTouched, MarketWithLeftOverAsLimit, Pegged. Defaults to 'Limit' when `price` is specified. Defaults to 'Stop' when `stopPx` is specified. Defaults to 'StopLimit' when `price` and `stopPx` are specified.
* @param timeInForce Time in force. Valid options: Day, GoodTillCancel, ImmediateOrCancel, FillOrKill. Defaults to 'GoodTillCancel' for 'Limit', 'StopLimit', 'LimitIfTouched', and 'MarketWithLeftOverAsLimit' orders.
* @param execInst Optional execution instructions. Valid options: ParticipateDoNotInitiate, AllOrNone, MarkPrice, IndexPrice, LastPrice, Close, ReduceOnly, Fixed. 'AllOrNone' instruction requires `displayQty` to be 0. 'MarkPrice' or 'LastPrice' instruction valid for 'Stop', 'StopLimit', 'MarketIfTouched', and 'LimitIfTouched' orders.
* @param contingencyType Optional contingency type for use with `clOrdLinkID`. Valid options: OneCancelsTheOther, OneTriggersTheOther, OneUpdatesTheOtherAbsolute, OneUpdatesTheOtherProportional.
* @param text Optional order annotation. e.g. 'Take profit'.
* @return *Order
*/
func (a OrderApi) OrderNew(symbol string, side string, simpleOrderQty float64, quantity float32, orderQty float32, price float64, displayQty float32, stopPrice float64, stopPx float64, clOrdID string, clOrdLinkID string, pegOffsetValue float64, pegPriceType string, type_ string, ordType string, timeInForce string, execInst string, contingencyType string, text string) (*Order, *APIResponse, error) {
var httpMethod = "Post"
// create path and map variables
path := a.Configuration.BasePath + "/order"
// verify the required parameter 'symbol' is set
if &symbol == nil {
return new(Order), nil, errors.New("Missing required parameter 'symbol' when calling OrderApi->OrderNew")
}
headerParams := make(map[string]string)
queryParams := url.Values{}
formParams := make(map[string]string)
var postBody interface{}
var fileName string
var fileBytes []byte
// add default headers if any
for key := range a.Configuration.DefaultHeader {
headerParams[key] = a.Configuration.DefaultHeader[key]
}
// to determine the Content-Type header
localVarHttpContentTypes := []string{ "application/json", "application/x-www-form-urlencoded", }
// set Content-Type header
localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string{
"application/json",
"application/xml",
"text/xml",
"application/javascript",
"text/javascript",
}
// set Accept header
localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
headerParams["Accept"] = localVarHttpHeaderAccept
}
formParams["symbol"] = symbol
formParams["side"] = side
formParams["simpleOrderQty"] = simpleOrderQty
formParams["quantity"] = quantity
formParams["orderQty"] = orderQty
formParams["price"] = price
formParams["displayQty"] = displayQty
formParams["stopPrice"] = stopPrice
formParams["stopPx"] = stopPx
formParams["clOrdID"] = clOrdID
formParams["clOrdLinkID"] = clOrdLinkID
formParams["pegOffsetValue"] = pegOffsetValue
formParams["pegPriceType"] = pegPriceType
formParams["type_"] = type_
formParams["ordType"] = ordType
formParams["timeInForce"] = timeInForce
formParams["execInst"] = execInst
formParams["contingencyType"] = contingencyType
formParams["text"] = text
var successPayload = new(Order)
httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil {
return successPayload, NewAPIResponse(httpResponse.RawResponse), err
}
err = json.Unmarshal(httpResponse.Body(), &successPayload)
return successPayload, NewAPIResponse(httpResponse.RawResponse), err
}
/**
* Create multiple new orders.
* This endpoint is used for placing bulk orders. Valid order types are Market, Limit, Stop, StopLimit, MarketIfTouched, LimitIfTouched, MarketWithLeftOverAsLimit, and Pegged. Each individual order object in the array should have the same properties as an individual POST /order call. This endpoint is much faster for getting many orders into the book at once. Because it reduces load on BitMEX systems, this endpoint is ratelimited at `ceil(0.5 * orders)`. Submitting 10 orders via a bulk order call will only count as 5 requests. For now, only `application/json` is supported on this endpoint.
*
* @param orders An array of orders.
* @return []Order
*/
func (a OrderApi) OrderNewBulk(orders string) ([]Order, *APIResponse, error) {
var httpMethod = "Post"
// create path and map variables
path := a.Configuration.BasePath + "/order/bulk"
headerParams := make(map[string]string)
queryParams := url.Values{}
formParams := make(map[string]string)
var postBody interface{}
var fileName string
var fileBytes []byte
// add default headers if any
for key := range a.Configuration.DefaultHeader {
headerParams[key] = a.Configuration.DefaultHeader[key]
}
// to determine the Content-Type header
localVarHttpContentTypes := []string{ "application/json", "application/x-www-form-urlencoded", }
// set Content-Type header
localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
headerParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string{
"application/json",
"application/xml",
"text/xml",
"application/javascript",
"text/javascript",
}
// set Accept header
localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
headerParams["Accept"] = localVarHttpHeaderAccept
}
formParams["orders"] = orders
var successPayload = new([]Order)
httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil {
return *successPayload, NewAPIResponse(httpResponse.RawResponse), err
}
err = json.Unmarshal(httpResponse.Body(), &successPayload)
return *successPayload, NewAPIResponse(httpResponse.RawResponse), err
}