github.com/vmpartner/bitmex@v1.1.0/swagger/order_api.go (about)

     1  /* 
     2   * BitMEX API
     3   *
     4   * ## REST API for the BitMEX Trading Platform  [View 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.  ##### Swagger Specification  [⇩ Download Swagger JSON](swagger.json)    ## All API Endpoints  Click to expand a section. 
     5   *
     6   * OpenAPI spec version: 1.2.0
     7   * Contact: support@bitmex.com
     8   * Generated by: https://github.com/swagger-api/swagger-codegen.git
     9   */
    10  
    11  package swagger
    12  
    13  import (
    14  	"net/url"
    15  	"net/http"
    16  	"strings"
    17  	"golang.org/x/net/context"
    18  	"time"
    19  	"encoding/json"
    20  	"fmt"
    21  	"io/ioutil"
    22  )
    23  
    24  // Linger please
    25  var (
    26  	_ context.Context
    27  )
    28  
    29  type OrderApiService service
    30  
    31  /* OrderApiService Amend the quantity or price of an open order.
    32   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. 
    33   * @param ctx context.Context Authentication Context 
    34   @param optional (nil or map[string]interface{}) with one or more of:
    35       @param "orderID" (string) Order ID
    36       @param "origClOrdID" (string) Client Order ID. See POST /order.
    37       @param "clOrdID" (string) Optional new Client Order ID, requires `origClOrdID`.
    38       @param "simpleOrderQty" (float64) Optional order quantity in units of the underlying instrument (i.e. Bitcoin).
    39       @param "orderQty" (float32) Optional order quantity in units of the instrument (i.e. contracts).
    40       @param "simpleLeavesQty" (float64) Optional leaves quantity in units of the underlying instrument (i.e. Bitcoin). Useful for amending partially filled orders.
    41       @param "leavesQty" (float32) Optional leaves quantity in units of the instrument (i.e. contracts). Useful for amending partially filled orders.
    42       @param "price" (float64) Optional limit price for 'Limit', 'StopLimit', and 'LimitIfTouched' orders.
    43       @param "stopPx" (float64) 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.
    44       @param "pegOffsetValue" (float64) 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.
    45       @param "text" (string) Optional amend annotation. e.g. 'Adjust skew'.
    46   @return Order*/
    47  func (a *OrderApiService) OrderAmend(ctx context.Context, localVarOptionals map[string]interface{}) (Order, *http.Response, error) {
    48  	var (
    49  		localVarHttpMethod = strings.ToUpper("Put")
    50  		localVarPostBody   interface{}
    51  		localVarFileName   string
    52  		localVarFileBytes  []byte
    53  		successPayload     Order
    54  	)
    55  
    56  	// create path and map variables
    57  	localVarPath := a.client.cfg.BasePath + "/order"
    58  
    59  	localVarHeaderParams := make(map[string]string)
    60  	localVarQueryParams := url.Values{}
    61  	localVarFormParams := url.Values{}
    62  
    63  	if err := typeCheckParameter(localVarOptionals["orderID"], "string", "orderID"); err != nil {
    64  		return successPayload, nil, err
    65  	}
    66  	if err := typeCheckParameter(localVarOptionals["origClOrdID"], "string", "origClOrdID"); err != nil {
    67  		return successPayload, nil, err
    68  	}
    69  	if err := typeCheckParameter(localVarOptionals["clOrdID"], "string", "clOrdID"); err != nil {
    70  		return successPayload, nil, err
    71  	}
    72  	if err := typeCheckParameter(localVarOptionals["simpleOrderQty"], "float64", "simpleOrderQty"); err != nil {
    73  		return successPayload, nil, err
    74  	}
    75  	if err := typeCheckParameter(localVarOptionals["orderQty"], "float32", "orderQty"); err != nil {
    76  		return successPayload, nil, err
    77  	}
    78  	if err := typeCheckParameter(localVarOptionals["simpleLeavesQty"], "float64", "simpleLeavesQty"); err != nil {
    79  		return successPayload, nil, err
    80  	}
    81  	if err := typeCheckParameter(localVarOptionals["leavesQty"], "float32", "leavesQty"); err != nil {
    82  		return successPayload, nil, err
    83  	}
    84  	if err := typeCheckParameter(localVarOptionals["price"], "float64", "price"); err != nil {
    85  		return successPayload, nil, err
    86  	}
    87  	if err := typeCheckParameter(localVarOptionals["stopPx"], "float64", "stopPx"); err != nil {
    88  		return successPayload, nil, err
    89  	}
    90  	if err := typeCheckParameter(localVarOptionals["pegOffsetValue"], "float64", "pegOffsetValue"); err != nil {
    91  		return successPayload, nil, err
    92  	}
    93  	if err := typeCheckParameter(localVarOptionals["text"], "string", "text"); err != nil {
    94  		return successPayload, nil, err
    95  	}
    96  
    97  	// to determine the Content-Type header
    98  	localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",}
    99  
   100  	// set Content-Type header
   101  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
   102  	if localVarHttpContentType != "" {
   103  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
   104  	}
   105  
   106  	// to determine the Accept header
   107  	localVarHttpHeaderAccepts := []string{
   108  		"application/json",
   109  		"application/xml",
   110  		"text/xml",
   111  		"application/javascript",
   112  		"text/javascript",
   113  	}
   114  
   115  	// set Accept header
   116  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
   117  	if localVarHttpHeaderAccept != "" {
   118  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
   119  	}
   120  	if localVarTempParam, localVarOk := localVarOptionals["orderID"].(string); localVarOk {
   121  		localVarFormParams.Add("orderID", parameterToString(localVarTempParam, ""))
   122  	}
   123  	if localVarTempParam, localVarOk := localVarOptionals["origClOrdID"].(string); localVarOk {
   124  		localVarFormParams.Add("origClOrdID", parameterToString(localVarTempParam, ""))
   125  	}
   126  	if localVarTempParam, localVarOk := localVarOptionals["clOrdID"].(string); localVarOk {
   127  		localVarFormParams.Add("clOrdID", parameterToString(localVarTempParam, ""))
   128  	}
   129  	if localVarTempParam, localVarOk := localVarOptionals["simpleOrderQty"].(float64); localVarOk {
   130  		localVarFormParams.Add("simpleOrderQty", parameterToString(localVarTempParam, ""))
   131  	}
   132  	if localVarTempParam, localVarOk := localVarOptionals["orderQty"].(float32); localVarOk {
   133  		localVarFormParams.Add("orderQty", parameterToString(localVarTempParam, ""))
   134  	}
   135  	if localVarTempParam, localVarOk := localVarOptionals["simpleLeavesQty"].(float64); localVarOk {
   136  		localVarFormParams.Add("simpleLeavesQty", parameterToString(localVarTempParam, ""))
   137  	}
   138  	if localVarTempParam, localVarOk := localVarOptionals["leavesQty"].(float32); localVarOk {
   139  		localVarFormParams.Add("leavesQty", parameterToString(localVarTempParam, ""))
   140  	}
   141  	if localVarTempParam, localVarOk := localVarOptionals["price"].(float64); localVarOk {
   142  		localVarFormParams.Add("price", parameterToString(localVarTempParam, ""))
   143  	}
   144  	if localVarTempParam, localVarOk := localVarOptionals["stopPx"].(float64); localVarOk {
   145  		localVarFormParams.Add("stopPx", parameterToString(localVarTempParam, ""))
   146  	}
   147  	if localVarTempParam, localVarOk := localVarOptionals["pegOffsetValue"].(float64); localVarOk {
   148  		localVarFormParams.Add("pegOffsetValue", parameterToString(localVarTempParam, ""))
   149  	}
   150  	if localVarTempParam, localVarOk := localVarOptionals["text"].(string); localVarOk {
   151  		localVarFormParams.Add("text", parameterToString(localVarTempParam, ""))
   152  	}
   153  	if ctx != nil {
   154  		// API Key Authentication
   155  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   156  			var key string
   157  			if auth.Prefix != "" {
   158  				key = auth.Prefix + " " + auth.Key
   159  			} else {
   160  				key = auth.Key
   161  			}
   162  			localVarHeaderParams["api-key"] = key
   163  		}
   164  	}
   165  	if ctx != nil {
   166  		// API Key Authentication
   167  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   168  			var key string
   169  			if auth.Prefix != "" {
   170  				key = auth.Prefix + " " + auth.Key
   171  			} else {
   172  				key = auth.Key
   173  			}
   174  			localVarHeaderParams["api-nonce"] = key
   175  		}
   176  	}
   177  	if ctx != nil {
   178  		// API Key Authentication
   179  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   180  			var key string
   181  			if auth.Prefix != "" {
   182  				key = auth.Prefix + " " + auth.Key
   183  			} else {
   184  				key = auth.Key
   185  			}
   186  			localVarHeaderParams["api-signature"] = key
   187  		}
   188  	}
   189  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
   190  	if err != nil {
   191  		return successPayload, nil, err
   192  	}
   193  
   194  	localVarHttpResponse, err := a.client.callAPI(r)
   195  	if err != nil || localVarHttpResponse == nil {
   196  		return successPayload, localVarHttpResponse, err
   197  	}
   198  	defer localVarHttpResponse.Body.Close()
   199  	if localVarHttpResponse.StatusCode >= 300 {
   200  		return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status)
   201  	}
   202  
   203  	if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil {
   204  		return successPayload, localVarHttpResponse, err
   205  	}
   206  
   207  	return successPayload, localVarHttpResponse, err
   208  }
   209  
   210  /* OrderApiService Amend multiple orders for the same symbol.
   211   Similar to POST /amend, but with multiple orders. `application/json` only. Ratelimited at 50%.
   212   * @param ctx context.Context Authentication Context 
   213   @param optional (nil or map[string]interface{}) with one or more of:
   214       @param "orders" (string) An array of orders.
   215   @return []Order*/
   216  func (a *OrderApiService) OrderAmendBulk(ctx context.Context, localVarOptionals map[string]interface{}) ([]Order, *http.Response, error) {
   217  	var (
   218  		localVarHttpMethod = strings.ToUpper("Put")
   219  		localVarPostBody   interface{}
   220  		localVarFileName   string
   221  		localVarFileBytes  []byte
   222  		successPayload     []Order
   223  	)
   224  
   225  	// create path and map variables
   226  	localVarPath := a.client.cfg.BasePath + "/order/bulk"
   227  
   228  	localVarHeaderParams := make(map[string]string)
   229  	localVarQueryParams := url.Values{}
   230  	localVarFormParams := url.Values{}
   231  
   232  	if err := typeCheckParameter(localVarOptionals["orders"], "string", "orders"); err != nil {
   233  		return successPayload, nil, err
   234  	}
   235  
   236  	// to determine the Content-Type header
   237  	localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",}
   238  
   239  	// set Content-Type header
   240  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
   241  	if localVarHttpContentType != "" {
   242  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
   243  	}
   244  
   245  	// to determine the Accept header
   246  	localVarHttpHeaderAccepts := []string{
   247  		"application/json",
   248  		"application/xml",
   249  		"text/xml",
   250  		"application/javascript",
   251  		"text/javascript",
   252  	}
   253  
   254  	// set Accept header
   255  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
   256  	if localVarHttpHeaderAccept != "" {
   257  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
   258  	}
   259  	if localVarTempParam, localVarOk := localVarOptionals["orders"].(string); localVarOk {
   260  		localVarFormParams.Add("orders", parameterToString(localVarTempParam, ""))
   261  	}
   262  	if ctx != nil {
   263  		// API Key Authentication
   264  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   265  			var key string
   266  			if auth.Prefix != "" {
   267  				key = auth.Prefix + " " + auth.Key
   268  			} else {
   269  				key = auth.Key
   270  			}
   271  			localVarHeaderParams["api-key"] = key
   272  		}
   273  	}
   274  	if ctx != nil {
   275  		// API Key Authentication
   276  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   277  			var key string
   278  			if auth.Prefix != "" {
   279  				key = auth.Prefix + " " + auth.Key
   280  			} else {
   281  				key = auth.Key
   282  			}
   283  			localVarHeaderParams["api-nonce"] = key
   284  		}
   285  	}
   286  	if ctx != nil {
   287  		// API Key Authentication
   288  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   289  			var key string
   290  			if auth.Prefix != "" {
   291  				key = auth.Prefix + " " + auth.Key
   292  			} else {
   293  				key = auth.Key
   294  			}
   295  			localVarHeaderParams["api-signature"] = key
   296  		}
   297  	}
   298  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
   299  	if err != nil {
   300  		return successPayload, nil, err
   301  	}
   302  
   303  	localVarHttpResponse, err := a.client.callAPI(r)
   304  	if err != nil || localVarHttpResponse == nil {
   305  		return successPayload, localVarHttpResponse, err
   306  	}
   307  	defer localVarHttpResponse.Body.Close()
   308  	if localVarHttpResponse.StatusCode >= 300 {
   309  		return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status)
   310  	}
   311  
   312  	if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil {
   313  		return successPayload, localVarHttpResponse, err
   314  	}
   315  
   316  	return successPayload, localVarHttpResponse, err
   317  }
   318  
   319  /* OrderApiService Cancel order(s). Send multiple order IDs to cancel in bulk.
   320   Either an orderID or a clOrdID must be provided.
   321   * @param ctx context.Context Authentication Context 
   322   @param optional (nil or map[string]interface{}) with one or more of:
   323       @param "orderID" (string) Order ID(s).
   324       @param "clOrdID" (string) Client Order ID(s). See POST /order.
   325       @param "text" (string) Optional cancellation annotation. e.g. 'Spread Exceeded'.
   326   @return []Order*/
   327  func (a *OrderApiService) OrderCancel(ctx context.Context, localVarOptionals map[string]interface{}) ([]Order, *http.Response, error) {
   328  	var (
   329  		localVarHttpMethod = strings.ToUpper("Delete")
   330  		localVarPostBody   interface{}
   331  		localVarFileName   string
   332  		localVarFileBytes  []byte
   333  		successPayload     []Order
   334  	)
   335  
   336  	// create path and map variables
   337  	localVarPath := a.client.cfg.BasePath + "/order"
   338  
   339  	localVarHeaderParams := make(map[string]string)
   340  	localVarQueryParams := url.Values{}
   341  	localVarFormParams := url.Values{}
   342  
   343  	if err := typeCheckParameter(localVarOptionals["orderID"], "string", "orderID"); err != nil {
   344  		return successPayload, nil, err
   345  	}
   346  	if err := typeCheckParameter(localVarOptionals["clOrdID"], "string", "clOrdID"); err != nil {
   347  		return successPayload, nil, err
   348  	}
   349  	if err := typeCheckParameter(localVarOptionals["text"], "string", "text"); err != nil {
   350  		return successPayload, nil, err
   351  	}
   352  
   353  	// to determine the Content-Type header
   354  	localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",}
   355  
   356  	// set Content-Type header
   357  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
   358  	if localVarHttpContentType != "" {
   359  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
   360  	}
   361  
   362  	// to determine the Accept header
   363  	localVarHttpHeaderAccepts := []string{
   364  		"application/json",
   365  		"application/xml",
   366  		"text/xml",
   367  		"application/javascript",
   368  		"text/javascript",
   369  	}
   370  
   371  	// set Accept header
   372  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
   373  	if localVarHttpHeaderAccept != "" {
   374  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
   375  	}
   376  	if localVarTempParam, localVarOk := localVarOptionals["orderID"].(string); localVarOk {
   377  		localVarFormParams.Add("orderID", parameterToString(localVarTempParam, ""))
   378  	}
   379  	if localVarTempParam, localVarOk := localVarOptionals["clOrdID"].(string); localVarOk {
   380  		localVarFormParams.Add("clOrdID", parameterToString(localVarTempParam, ""))
   381  	}
   382  	if localVarTempParam, localVarOk := localVarOptionals["text"].(string); localVarOk {
   383  		localVarFormParams.Add("text", parameterToString(localVarTempParam, ""))
   384  	}
   385  	if ctx != nil {
   386  		// API Key Authentication
   387  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   388  			var key string
   389  			if auth.Prefix != "" {
   390  				key = auth.Prefix + " " + auth.Key
   391  			} else {
   392  				key = auth.Key
   393  			}
   394  			localVarHeaderParams["api-key"] = key
   395  		}
   396  	}
   397  	if ctx != nil {
   398  		// API Key Authentication
   399  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   400  			var key string
   401  			if auth.Prefix != "" {
   402  				key = auth.Prefix + " " + auth.Key
   403  			} else {
   404  				key = auth.Key
   405  			}
   406  			localVarHeaderParams["api-nonce"] = key
   407  		}
   408  	}
   409  	if ctx != nil {
   410  		// API Key Authentication
   411  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   412  			var key string
   413  			if auth.Prefix != "" {
   414  				key = auth.Prefix + " " + auth.Key
   415  			} else {
   416  				key = auth.Key
   417  			}
   418  			localVarHeaderParams["api-signature"] = key
   419  		}
   420  	}
   421  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
   422  	if err != nil {
   423  		return successPayload, nil, err
   424  	}
   425  
   426  	localVarHttpResponse, err := a.client.callAPI(r)
   427  	if err != nil || localVarHttpResponse == nil {
   428  		return successPayload, localVarHttpResponse, err
   429  	}
   430  	defer localVarHttpResponse.Body.Close()
   431  	if localVarHttpResponse.StatusCode >= 300 {
   432  		return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status)
   433  	}
   434  
   435  	if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil {
   436  		return successPayload, localVarHttpResponse, err
   437  	}
   438  
   439  	return successPayload, localVarHttpResponse, err
   440  }
   441  
   442  /* OrderApiService Cancels all of your orders.
   443   * @param ctx context.Context Authentication Context 
   444   @param optional (nil or map[string]interface{}) with one or more of:
   445       @param "symbol" (string) Optional symbol. If provided, only cancels orders for that symbol.
   446       @param "filter" (string) Optional filter for cancellation. Use to only cancel some orders, e.g. `{\"side\": \"Buy\"}`.
   447       @param "text" (string) Optional cancellation annotation. e.g. 'Spread Exceeded'
   448   @return interface{}*/
   449  func (a *OrderApiService) OrderCancelAll(ctx context.Context, localVarOptionals map[string]interface{}) (interface{}, *http.Response, error) {
   450  	var (
   451  		localVarHttpMethod = strings.ToUpper("Delete")
   452  		localVarPostBody   interface{}
   453  		localVarFileName   string
   454  		localVarFileBytes  []byte
   455  		successPayload     interface{}
   456  	)
   457  
   458  	// create path and map variables
   459  	localVarPath := a.client.cfg.BasePath + "/order/all"
   460  
   461  	localVarHeaderParams := make(map[string]string)
   462  	localVarQueryParams := url.Values{}
   463  	localVarFormParams := url.Values{}
   464  
   465  	if err := typeCheckParameter(localVarOptionals["symbol"], "string", "symbol"); err != nil {
   466  		return successPayload, nil, err
   467  	}
   468  	if err := typeCheckParameter(localVarOptionals["filter"], "string", "filter"); err != nil {
   469  		return successPayload, nil, err
   470  	}
   471  	if err := typeCheckParameter(localVarOptionals["text"], "string", "text"); err != nil {
   472  		return successPayload, nil, err
   473  	}
   474  
   475  	// to determine the Content-Type header
   476  	localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",}
   477  
   478  	// set Content-Type header
   479  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
   480  	if localVarHttpContentType != "" {
   481  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
   482  	}
   483  
   484  	// to determine the Accept header
   485  	localVarHttpHeaderAccepts := []string{
   486  		"application/json",
   487  		"application/xml",
   488  		"text/xml",
   489  		"application/javascript",
   490  		"text/javascript",
   491  	}
   492  
   493  	// set Accept header
   494  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
   495  	if localVarHttpHeaderAccept != "" {
   496  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
   497  	}
   498  	if localVarTempParam, localVarOk := localVarOptionals["symbol"].(string); localVarOk {
   499  		localVarFormParams.Add("symbol", parameterToString(localVarTempParam, ""))
   500  	}
   501  	if localVarTempParam, localVarOk := localVarOptionals["filter"].(string); localVarOk {
   502  		localVarFormParams.Add("filter", parameterToString(localVarTempParam, ""))
   503  	}
   504  	if localVarTempParam, localVarOk := localVarOptionals["text"].(string); localVarOk {
   505  		localVarFormParams.Add("text", parameterToString(localVarTempParam, ""))
   506  	}
   507  	if ctx != nil {
   508  		// API Key Authentication
   509  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   510  			var key string
   511  			if auth.Prefix != "" {
   512  				key = auth.Prefix + " " + auth.Key
   513  			} else {
   514  				key = auth.Key
   515  			}
   516  			localVarHeaderParams["api-key"] = key
   517  		}
   518  	}
   519  	if ctx != nil {
   520  		// API Key Authentication
   521  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   522  			var key string
   523  			if auth.Prefix != "" {
   524  				key = auth.Prefix + " " + auth.Key
   525  			} else {
   526  				key = auth.Key
   527  			}
   528  			localVarHeaderParams["api-nonce"] = key
   529  		}
   530  	}
   531  	if ctx != nil {
   532  		// API Key Authentication
   533  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   534  			var key string
   535  			if auth.Prefix != "" {
   536  				key = auth.Prefix + " " + auth.Key
   537  			} else {
   538  				key = auth.Key
   539  			}
   540  			localVarHeaderParams["api-signature"] = key
   541  		}
   542  	}
   543  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
   544  	if err != nil {
   545  		return successPayload, nil, err
   546  	}
   547  
   548  	localVarHttpResponse, err := a.client.callAPI(r)
   549  	if err != nil || localVarHttpResponse == nil {
   550  		return successPayload, localVarHttpResponse, err
   551  	}
   552  	defer localVarHttpResponse.Body.Close()
   553  	if localVarHttpResponse.StatusCode >= 300 {
   554  		return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status)
   555  	}
   556  
   557  	if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil {
   558  		return successPayload, localVarHttpResponse, err
   559  	}
   560  
   561  	return successPayload, localVarHttpResponse, err
   562  }
   563  
   564  /* OrderApiService Automatically cancel all your orders after a specified timeout.
   565   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-). 
   566   * @param ctx context.Context Authentication Context 
   567   @param timeout Timeout in ms. Set to 0 to cancel this timer. 
   568   @return interface{}*/
   569  func (a *OrderApiService) OrderCancelAllAfter(ctx context.Context, timeout float64) (interface{}, *http.Response, error) {
   570  	var (
   571  		localVarHttpMethod = strings.ToUpper("Post")
   572  		localVarPostBody   interface{}
   573  		localVarFileName   string
   574  		localVarFileBytes  []byte
   575  		successPayload     interface{}
   576  	)
   577  
   578  	// create path and map variables
   579  	localVarPath := a.client.cfg.BasePath + "/order/cancelAllAfter"
   580  
   581  	localVarHeaderParams := make(map[string]string)
   582  	localVarQueryParams := url.Values{}
   583  	localVarFormParams := url.Values{}
   584  
   585  	// to determine the Content-Type header
   586  	localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",}
   587  
   588  	// set Content-Type header
   589  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
   590  	if localVarHttpContentType != "" {
   591  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
   592  	}
   593  
   594  	// to determine the Accept header
   595  	localVarHttpHeaderAccepts := []string{
   596  		"application/json",
   597  		"application/xml",
   598  		"text/xml",
   599  		"application/javascript",
   600  		"text/javascript",
   601  	}
   602  
   603  	// set Accept header
   604  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
   605  	if localVarHttpHeaderAccept != "" {
   606  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
   607  	}
   608  	localVarFormParams.Add("timeout", parameterToString(timeout, ""))
   609  	if ctx != nil {
   610  		// API Key Authentication
   611  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   612  			var key string
   613  			if auth.Prefix != "" {
   614  				key = auth.Prefix + " " + auth.Key
   615  			} else {
   616  				key = auth.Key
   617  			}
   618  			localVarHeaderParams["api-key"] = key
   619  		}
   620  	}
   621  	if ctx != nil {
   622  		// API Key Authentication
   623  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   624  			var key string
   625  			if auth.Prefix != "" {
   626  				key = auth.Prefix + " " + auth.Key
   627  			} else {
   628  				key = auth.Key
   629  			}
   630  			localVarHeaderParams["api-nonce"] = key
   631  		}
   632  	}
   633  	if ctx != nil {
   634  		// API Key Authentication
   635  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   636  			var key string
   637  			if auth.Prefix != "" {
   638  				key = auth.Prefix + " " + auth.Key
   639  			} else {
   640  				key = auth.Key
   641  			}
   642  			localVarHeaderParams["api-signature"] = key
   643  		}
   644  	}
   645  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
   646  	if err != nil {
   647  		return successPayload, nil, err
   648  	}
   649  
   650  	localVarHttpResponse, err := a.client.callAPI(r)
   651  	if err != nil || localVarHttpResponse == nil {
   652  		return successPayload, localVarHttpResponse, err
   653  	}
   654  	defer localVarHttpResponse.Body.Close()
   655  	if localVarHttpResponse.StatusCode >= 300 {
   656  		return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status)
   657  	}
   658  
   659  	if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil {
   660  		return successPayload, localVarHttpResponse, err
   661  	}
   662  
   663  	return successPayload, localVarHttpResponse, err
   664  }
   665  
   666  /* OrderApiService Close a position. [Deprecated, use POST /order with execInst: 'Close']
   667   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.
   668   * @param ctx context.Context Authentication Context 
   669   @param symbol Symbol of position to close.
   670   @param optional (nil or map[string]interface{}) with one or more of:
   671       @param "price" (float64) Optional limit price.
   672   @return Order*/
   673  func (a *OrderApiService) OrderClosePosition(ctx context.Context, symbol string, localVarOptionals map[string]interface{}) (Order, *http.Response, error) {
   674  	var (
   675  		localVarHttpMethod = strings.ToUpper("Post")
   676  		localVarPostBody   interface{}
   677  		localVarFileName   string
   678  		localVarFileBytes  []byte
   679  		successPayload     Order
   680  	)
   681  
   682  	// create path and map variables
   683  	localVarPath := a.client.cfg.BasePath + "/order/closePosition"
   684  
   685  	localVarHeaderParams := make(map[string]string)
   686  	localVarQueryParams := url.Values{}
   687  	localVarFormParams := url.Values{}
   688  
   689  	if err := typeCheckParameter(localVarOptionals["price"], "float64", "price"); err != nil {
   690  		return successPayload, nil, err
   691  	}
   692  
   693  	// to determine the Content-Type header
   694  	localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",}
   695  
   696  	// set Content-Type header
   697  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
   698  	if localVarHttpContentType != "" {
   699  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
   700  	}
   701  
   702  	// to determine the Accept header
   703  	localVarHttpHeaderAccepts := []string{
   704  		"application/json",
   705  		"application/xml",
   706  		"text/xml",
   707  		"application/javascript",
   708  		"text/javascript",
   709  	}
   710  
   711  	// set Accept header
   712  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
   713  	if localVarHttpHeaderAccept != "" {
   714  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
   715  	}
   716  	localVarFormParams.Add("symbol", parameterToString(symbol, ""))
   717  	if localVarTempParam, localVarOk := localVarOptionals["price"].(float64); localVarOk {
   718  		localVarFormParams.Add("price", parameterToString(localVarTempParam, ""))
   719  	}
   720  	if ctx != nil {
   721  		// API Key Authentication
   722  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   723  			var key string
   724  			if auth.Prefix != "" {
   725  				key = auth.Prefix + " " + auth.Key
   726  			} else {
   727  				key = auth.Key
   728  			}
   729  			localVarHeaderParams["api-key"] = key
   730  		}
   731  	}
   732  	if ctx != nil {
   733  		// API Key Authentication
   734  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   735  			var key string
   736  			if auth.Prefix != "" {
   737  				key = auth.Prefix + " " + auth.Key
   738  			} else {
   739  				key = auth.Key
   740  			}
   741  			localVarHeaderParams["api-nonce"] = key
   742  		}
   743  	}
   744  	if ctx != nil {
   745  		// API Key Authentication
   746  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   747  			var key string
   748  			if auth.Prefix != "" {
   749  				key = auth.Prefix + " " + auth.Key
   750  			} else {
   751  				key = auth.Key
   752  			}
   753  			localVarHeaderParams["api-signature"] = key
   754  		}
   755  	}
   756  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
   757  	if err != nil {
   758  		return successPayload, nil, err
   759  	}
   760  
   761  	localVarHttpResponse, err := a.client.callAPI(r)
   762  	if err != nil || localVarHttpResponse == nil {
   763  		return successPayload, localVarHttpResponse, err
   764  	}
   765  	defer localVarHttpResponse.Body.Close()
   766  	if localVarHttpResponse.StatusCode >= 300 {
   767  		return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status)
   768  	}
   769  
   770  	if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil {
   771  		return successPayload, localVarHttpResponse, err
   772  	}
   773  
   774  	return successPayload, localVarHttpResponse, err
   775  }
   776  
   777  /* OrderApiService Get your orders.
   778   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.
   779   * @param ctx context.Context Authentication Context 
   780   @param optional (nil or map[string]interface{}) with one or more of:
   781       @param "symbol" (string) 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`.
   782       @param "filter" (string) 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.
   783       @param "columns" (string) 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.
   784       @param "count" (float32) Number of results to fetch.
   785       @param "start" (float32) Starting point for results.
   786       @param "reverse" (bool) If true, will sort results newest first.
   787       @param "startTime" (time.Time) Starting date filter for results.
   788       @param "endTime" (time.Time) Ending date filter for results.
   789   @return []Order*/
   790  func (a *OrderApiService) OrderGetOrders(ctx context.Context, localVarOptionals map[string]interface{}) ([]Order, *http.Response, error) {
   791  	var (
   792  		localVarHttpMethod = strings.ToUpper("Get")
   793  		localVarPostBody   interface{}
   794  		localVarFileName   string
   795  		localVarFileBytes  []byte
   796  		successPayload     []Order
   797  	)
   798  
   799  	// create path and map variables
   800  	localVarPath := a.client.cfg.BasePath + "/order"
   801  
   802  	localVarHeaderParams := make(map[string]string)
   803  	localVarQueryParams := url.Values{}
   804  	localVarFormParams := url.Values{}
   805  
   806  	if err := typeCheckParameter(localVarOptionals["symbol"], "string", "symbol"); err != nil {
   807  		return successPayload, nil, err
   808  	}
   809  	if err := typeCheckParameter(localVarOptionals["filter"], "string", "filter"); err != nil {
   810  		return successPayload, nil, err
   811  	}
   812  	if err := typeCheckParameter(localVarOptionals["columns"], "string", "columns"); err != nil {
   813  		return successPayload, nil, err
   814  	}
   815  	if err := typeCheckParameter(localVarOptionals["count"], "float32", "count"); err != nil {
   816  		return successPayload, nil, err
   817  	}
   818  	if err := typeCheckParameter(localVarOptionals["start"], "float32", "start"); err != nil {
   819  		return successPayload, nil, err
   820  	}
   821  	if err := typeCheckParameter(localVarOptionals["reverse"], "bool", "reverse"); err != nil {
   822  		return successPayload, nil, err
   823  	}
   824  	if err := typeCheckParameter(localVarOptionals["startTime"], "time.Time", "startTime"); err != nil {
   825  		return successPayload, nil, err
   826  	}
   827  	if err := typeCheckParameter(localVarOptionals["endTime"], "time.Time", "endTime"); err != nil {
   828  		return successPayload, nil, err
   829  	}
   830  
   831  	if localVarTempParam, localVarOk := localVarOptionals["symbol"].(string); localVarOk {
   832  		localVarQueryParams.Add("symbol", parameterToString(localVarTempParam, ""))
   833  	}
   834  	if localVarTempParam, localVarOk := localVarOptionals["filter"].(string); localVarOk {
   835  		localVarQueryParams.Add("filter", parameterToString(localVarTempParam, ""))
   836  	}
   837  	if localVarTempParam, localVarOk := localVarOptionals["columns"].(string); localVarOk {
   838  		localVarQueryParams.Add("columns", parameterToString(localVarTempParam, ""))
   839  	}
   840  	if localVarTempParam, localVarOk := localVarOptionals["count"].(float32); localVarOk {
   841  		localVarQueryParams.Add("count", parameterToString(localVarTempParam, ""))
   842  	}
   843  	if localVarTempParam, localVarOk := localVarOptionals["start"].(float32); localVarOk {
   844  		localVarQueryParams.Add("start", parameterToString(localVarTempParam, ""))
   845  	}
   846  	if localVarTempParam, localVarOk := localVarOptionals["reverse"].(bool); localVarOk {
   847  		localVarQueryParams.Add("reverse", parameterToString(localVarTempParam, ""))
   848  	}
   849  	if localVarTempParam, localVarOk := localVarOptionals["startTime"].(time.Time); localVarOk {
   850  		localVarQueryParams.Add("startTime", parameterToString(localVarTempParam, ""))
   851  	}
   852  	if localVarTempParam, localVarOk := localVarOptionals["endTime"].(time.Time); localVarOk {
   853  		localVarQueryParams.Add("endTime", parameterToString(localVarTempParam, ""))
   854  	}
   855  	// to determine the Content-Type header
   856  	localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",}
   857  
   858  	// set Content-Type header
   859  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
   860  	if localVarHttpContentType != "" {
   861  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
   862  	}
   863  
   864  	// to determine the Accept header
   865  	localVarHttpHeaderAccepts := []string{
   866  		"application/json",
   867  		"application/xml",
   868  		"text/xml",
   869  		"application/javascript",
   870  		"text/javascript",
   871  	}
   872  
   873  	// set Accept header
   874  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
   875  	if localVarHttpHeaderAccept != "" {
   876  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
   877  	}
   878  	if ctx != nil {
   879  		// API Key Authentication
   880  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   881  			var key string
   882  			if auth.Prefix != "" {
   883  				key = auth.Prefix + " " + auth.Key
   884  			} else {
   885  				key = auth.Key
   886  			}
   887  			localVarHeaderParams["api-key"] = key
   888  		}
   889  	}
   890  	if ctx != nil {
   891  		// API Key Authentication
   892  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   893  			var key string
   894  			if auth.Prefix != "" {
   895  				key = auth.Prefix + " " + auth.Key
   896  			} else {
   897  				key = auth.Key
   898  			}
   899  			localVarHeaderParams["api-nonce"] = key
   900  		}
   901  	}
   902  	if ctx != nil {
   903  		// API Key Authentication
   904  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   905  			var key string
   906  			if auth.Prefix != "" {
   907  				key = auth.Prefix + " " + auth.Key
   908  			} else {
   909  				key = auth.Key
   910  			}
   911  			localVarHeaderParams["api-signature"] = key
   912  		}
   913  	}
   914  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
   915  	if err != nil {
   916  		return successPayload, nil, err
   917  	}
   918  
   919  	localVarHttpResponse, err := a.client.callAPI(r)
   920  	if err != nil || localVarHttpResponse == nil {
   921  		return successPayload, localVarHttpResponse, err
   922  	}
   923  	defer localVarHttpResponse.Body.Close()
   924  	if localVarHttpResponse.StatusCode >= 300 {
   925  		return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status)
   926  	}
   927  
   928  	if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil {
   929  		return successPayload, localVarHttpResponse, err
   930  	}
   931  
   932  	return successPayload, localVarHttpResponse, err
   933  }
   934  
   935  /* OrderApiService Create a new order.
   936   ## Placing Orders  This endpoint is used for placing orders. See individual fields below for more details on their use.  #### Order Types  All orders require a `symbol`. All other fields are optional except when otherwise specified.  These are the valid `ordType`s:  * **Limit**: The default order type. Specify an `orderQty` and `price`. * **Market**: A traditional Market order. A Market order will execute until filled or your bankruptcy price is reached, at   which point it will cancel. * **MarketWithLeftOverAsLimit**: A market order that, after eating through the order book as far as   permitted by available margin, will become a limit order. The difference between this type and `Market` only   affects the behavior in thin books. Upon reaching the deepest possible price, if there is quantity left over,   a `Market` order will cancel the remaining quantity. `MarketWithLeftOverAsLimit` will keep the remaining   quantity in the books as a `Limit`. * **Stop**: A Stop Market order. Specify an `orderQty` and `stopPx`. When the `stopPx` is reached, the order will be entered   into the book.   * On sell orders, the order will trigger if the triggering price is lower than the `stopPx`. On buys, higher.   * Note: Stop orders do not consume margin until triggered. Be sure that the required margin is available in your     account so that it may trigger fully.   * `Close` Stops don't require an `orderQty`. See Execution Instructions below. * **StopLimit**: Like a Stop Market, but enters a Limit order instead of a Market order. Specify an `orderQty`, `stopPx`,   and `price`. * **MarketIfTouched**: Similar to a Stop, but triggers are done in the opposite direction. Useful for Take Profit orders. * **LimitIfTouched**: As above; use for Take Profit Limit orders.  #### Execution Instructions  The following `execInst`s are supported. If using multiple, separate with a comma (e.g. `LastPrice,Close`).  * **ParticipateDoNotInitiate**: Also known as a Post-Only order. If this order would have executed on placement,   it will cancel instead. * **AllOrNone**: Valid only for hidden orders (`displayQty: 0`). Use to only execute if the entire order would fill. * **MarkPrice, LastPrice, IndexPrice**: Used by stop and if-touched orders to determine the triggering price.   Use only one. By default, `'MarkPrice'` is used. Also used for Pegged orders to define the value of `'LastPeg'`. * **ReduceOnly**: A `'ReduceOnly'` order can only reduce your position, not increase it. If you have a `'ReduceOnly'`   limit order that rests in the order book while the position is reduced by other orders, then its order quantity will   be amended down or canceled. If there are multiple `'ReduceOnly'` orders the least agresssive will be amended first. * **Close**: `'Close'` implies `'ReduceOnly'`. A `'Close'` order will cancel other active limit orders with the same side   and symbol if the open quantity exceeds the current position. This is useful for stops: by canceling these orders, a   `'Close'` Stop is ensured to have the margin required to execute, and can only execute up to the full size of your   position. If not specified, a `'Close'` order has an `orderQty` equal to your current position's size.  #### Linked Orders  Linked Orders are an advanced capability. It is very powerful, but its use requires careful coding and testing. Please follow this document carefully and use the [Testnet Exchange](https://testnet.bitmex.com) while developing.  BitMEX offers four advanced Linked Order types:  * **OCO**: *One Cancels the Other*. A very flexible version of the standard Stop / Take Profit technique.   Multiple orders may be linked together using a single `clOrdLinkID`. Send a `contingencyType` of   `OneCancelsTheOther` on the orders. The first order that fully or partially executes (or activates   for `Stop` orders) will cancel all other orders with the same `clOrdLinkID`. * **OTO**: *One Triggers the Other*. Send a `contingencyType` of `'OneTriggersTheOther'` on the primary order and   then subsequent orders with the same `clOrdLinkID` will be not be triggered until the primary order fully executes. * **OUOA**: *One Updates the Other Absolute*. Send a `contingencyType` of `'OneUpdatesTheOtherAbsolute'` on the orders. Then   as one order has a execution, other orders with the same `clOrdLinkID` will have their order quantity amended   down by the execution quantity. * **OUOP**: *One Updates the Other Proportional*. Send a `contingencyType` of `'OneUpdatesTheOtherProportional'` on the orders. Then   as one order has a execution, other orders with the same `clOrdLinkID` will have their order quantity reduced proportionally   by the fill percentage.  #### Trailing Stops  You may use `pegPriceType` of `'TrailingStopPeg'` to create Trailing Stops. The pegged `stopPx` will move as the market moves away from the peg, and freeze as the market moves toward it.  To use, combine with `pegOffsetValue` to set the `stopPx` of your order. The peg is set to the triggering price specified in the `execInst` (default `'MarkPrice'`). Use a negative offset for stop-sell and buy-if-touched orders.  Requires `ordType`: `'Stop', 'StopLimit', 'MarketIfTouched', 'LimitIfTouched'`.  #### Simple Quantities  Send a `simpleOrderQty` instead of an `orderQty` to create an order denominated in the underlying currency. This is useful for opening up a position with 1 XBT of exposure without having to calculate how many contracts it is.  #### Rate Limits  See the [Bulk Order Documentation](#!/Order/Order_newBulk) if you need to place multiple orders at the same time. Bulk orders require fewer risk checks in the trading engine and thus are ratelimited at **1/10** the normal rate.  You can also improve your reactivity to market movements while staying under your ratelimit by using the [Amend](#!/Order/Order_amend) and [Amend Bulk](#!/Order/Order_amendBulk) endpoints. This allows you to stay in the market and avoids the cancel/replace cycle.  #### Tracking Your Orders  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. 
   937   * @param ctx context.Context Authentication Context 
   938   @param symbol Instrument symbol. e.g. 'XBTUSD'.
   939   @param optional (nil or map[string]interface{}) with one or more of:
   940       @param "side" (string) Order side. Valid options: Buy, Sell. Defaults to 'Buy' unless `orderQty` or `simpleOrderQty` is negative.
   941       @param "simpleOrderQty" (float64) Order quantity in units of the underlying instrument (i.e. Bitcoin).
   942       @param "quantity" (float32) Deprecated: use `orderQty`.
   943       @param "orderQty" (float32) Order quantity in units of the instrument (i.e. contracts).
   944       @param "price" (float64) Optional limit price for 'Limit', 'StopLimit', and 'LimitIfTouched' orders.
   945       @param "displayQty" (float32) Optional quantity to display in the book. Use 0 for a fully hidden order.
   946       @param "stopPrice" (float64) Deprecated: use `stopPx`.
   947       @param "stopPx" (float64) 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.
   948       @param "clOrdID" (string) Optional Client Order ID. This clOrdID will come back on the order and any related executions.
   949       @param "clOrdLinkID" (string) Optional Client Order Link ID for contingent orders.
   950       @param "pegOffsetValue" (float64) 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.
   951       @param "pegPriceType" (string) Optional peg price type. Valid options: LastPeg, MidPricePeg, MarketPeg, PrimaryPeg, TrailingStopPeg.
   952       @param "type_" (string) Deprecated: use `ordType`.
   953       @param "ordType" (string) 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.
   954       @param "timeInForce" (string) Time in force. Valid options: Day, GoodTillCancel, ImmediateOrCancel, FillOrKill. Defaults to 'GoodTillCancel' for 'Limit', 'StopLimit', 'LimitIfTouched', and 'MarketWithLeftOverAsLimit' orders.
   955       @param "execInst" (string) Optional execution instructions. Valid options: ParticipateDoNotInitiate, AllOrNone, MarkPrice, IndexPrice, LastPrice, Close, ReduceOnly, Fixed. 'AllOrNone' instruction requires `displayQty` to be 0. 'MarkPrice', 'IndexPrice' or 'LastPrice' instruction valid for 'Stop', 'StopLimit', 'MarketIfTouched', and 'LimitIfTouched' orders.
   956       @param "contingencyType" (string) Optional contingency type for use with `clOrdLinkID`. Valid options: OneCancelsTheOther, OneTriggersTheOther, OneUpdatesTheOtherAbsolute, OneUpdatesTheOtherProportional.
   957       @param "text" (string) Optional order annotation. e.g. 'Take profit'.
   958   @return Order*/
   959  func (a *OrderApiService) OrderNew(ctx context.Context, symbol string, localVarOptionals map[string]interface{}) (Order, *http.Response, error) {
   960  	var (
   961  		localVarHttpMethod = strings.ToUpper("Post")
   962  		localVarPostBody   interface{}
   963  		localVarFileName   string
   964  		localVarFileBytes  []byte
   965  		successPayload     Order
   966  	)
   967  
   968  	// create path and map variables
   969  	localVarPath := a.client.cfg.BasePath + "/order"
   970  
   971  	localVarHeaderParams := make(map[string]string)
   972  	localVarQueryParams := url.Values{}
   973  	localVarFormParams := url.Values{}
   974  
   975  	if err := typeCheckParameter(localVarOptionals["side"], "string", "side"); err != nil {
   976  		return successPayload, nil, err
   977  	}
   978  	if err := typeCheckParameter(localVarOptionals["simpleOrderQty"], "float64", "simpleOrderQty"); err != nil {
   979  		return successPayload, nil, err
   980  	}
   981  	if err := typeCheckParameter(localVarOptionals["quantity"], "float32", "quantity"); err != nil {
   982  		return successPayload, nil, err
   983  	}
   984  	if err := typeCheckParameter(localVarOptionals["orderQty"], "float32", "orderQty"); err != nil {
   985  		return successPayload, nil, err
   986  	}
   987  	if err := typeCheckParameter(localVarOptionals["price"], "float64", "price"); err != nil {
   988  		return successPayload, nil, err
   989  	}
   990  	if err := typeCheckParameter(localVarOptionals["displayQty"], "float32", "displayQty"); err != nil {
   991  		return successPayload, nil, err
   992  	}
   993  	if err := typeCheckParameter(localVarOptionals["stopPrice"], "float64", "stopPrice"); err != nil {
   994  		return successPayload, nil, err
   995  	}
   996  	if err := typeCheckParameter(localVarOptionals["stopPx"], "float64", "stopPx"); err != nil {
   997  		return successPayload, nil, err
   998  	}
   999  	if err := typeCheckParameter(localVarOptionals["clOrdID"], "string", "clOrdID"); err != nil {
  1000  		return successPayload, nil, err
  1001  	}
  1002  	if err := typeCheckParameter(localVarOptionals["clOrdLinkID"], "string", "clOrdLinkID"); err != nil {
  1003  		return successPayload, nil, err
  1004  	}
  1005  	if err := typeCheckParameter(localVarOptionals["pegOffsetValue"], "float64", "pegOffsetValue"); err != nil {
  1006  		return successPayload, nil, err
  1007  	}
  1008  	if err := typeCheckParameter(localVarOptionals["pegPriceType"], "string", "pegPriceType"); err != nil {
  1009  		return successPayload, nil, err
  1010  	}
  1011  	if err := typeCheckParameter(localVarOptionals["type_"], "string", "type_"); err != nil {
  1012  		return successPayload, nil, err
  1013  	}
  1014  	if err := typeCheckParameter(localVarOptionals["ordType"], "string", "ordType"); err != nil {
  1015  		return successPayload, nil, err
  1016  	}
  1017  	if err := typeCheckParameter(localVarOptionals["timeInForce"], "string", "timeInForce"); err != nil {
  1018  		return successPayload, nil, err
  1019  	}
  1020  	if err := typeCheckParameter(localVarOptionals["execInst"], "string", "execInst"); err != nil {
  1021  		return successPayload, nil, err
  1022  	}
  1023  	if err := typeCheckParameter(localVarOptionals["contingencyType"], "string", "contingencyType"); err != nil {
  1024  		return successPayload, nil, err
  1025  	}
  1026  	if err := typeCheckParameter(localVarOptionals["text"], "string", "text"); err != nil {
  1027  		return successPayload, nil, err
  1028  	}
  1029  
  1030  	// to determine the Content-Type header
  1031  	localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",}
  1032  
  1033  	// set Content-Type header
  1034  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
  1035  	if localVarHttpContentType != "" {
  1036  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
  1037  	}
  1038  
  1039  	// to determine the Accept header
  1040  	localVarHttpHeaderAccepts := []string{
  1041  		"application/json",
  1042  		"application/xml",
  1043  		"text/xml",
  1044  		"application/javascript",
  1045  		"text/javascript",
  1046  	}
  1047  
  1048  	// set Accept header
  1049  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
  1050  	if localVarHttpHeaderAccept != "" {
  1051  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
  1052  	}
  1053  	localVarFormParams.Add("symbol", parameterToString(symbol, ""))
  1054  	if localVarTempParam, localVarOk := localVarOptionals["side"].(string); localVarOk {
  1055  		localVarFormParams.Add("side", parameterToString(localVarTempParam, ""))
  1056  	}
  1057  	if localVarTempParam, localVarOk := localVarOptionals["simpleOrderQty"].(float64); localVarOk {
  1058  		localVarFormParams.Add("simpleOrderQty", parameterToString(localVarTempParam, ""))
  1059  	}
  1060  	if localVarTempParam, localVarOk := localVarOptionals["quantity"].(float32); localVarOk {
  1061  		localVarFormParams.Add("quantity", parameterToString(localVarTempParam, ""))
  1062  	}
  1063  	if localVarTempParam, localVarOk := localVarOptionals["orderQty"].(float32); localVarOk {
  1064  		localVarFormParams.Add("orderQty", parameterToString(localVarTempParam, ""))
  1065  	}
  1066  	if localVarTempParam, localVarOk := localVarOptionals["price"].(float64); localVarOk {
  1067  		localVarFormParams.Add("price", parameterToString(localVarTempParam, ""))
  1068  	}
  1069  	if localVarTempParam, localVarOk := localVarOptionals["displayQty"].(float32); localVarOk {
  1070  		localVarFormParams.Add("displayQty", parameterToString(localVarTempParam, ""))
  1071  	}
  1072  	if localVarTempParam, localVarOk := localVarOptionals["stopPrice"].(float64); localVarOk {
  1073  		localVarFormParams.Add("stopPrice", parameterToString(localVarTempParam, ""))
  1074  	}
  1075  	if localVarTempParam, localVarOk := localVarOptionals["stopPx"].(float64); localVarOk {
  1076  		localVarFormParams.Add("stopPx", parameterToString(localVarTempParam, ""))
  1077  	}
  1078  	if localVarTempParam, localVarOk := localVarOptionals["clOrdID"].(string); localVarOk {
  1079  		localVarFormParams.Add("clOrdID", parameterToString(localVarTempParam, ""))
  1080  	}
  1081  	if localVarTempParam, localVarOk := localVarOptionals["clOrdLinkID"].(string); localVarOk {
  1082  		localVarFormParams.Add("clOrdLinkID", parameterToString(localVarTempParam, ""))
  1083  	}
  1084  	if localVarTempParam, localVarOk := localVarOptionals["pegOffsetValue"].(float64); localVarOk {
  1085  		localVarFormParams.Add("pegOffsetValue", parameterToString(localVarTempParam, ""))
  1086  	}
  1087  	if localVarTempParam, localVarOk := localVarOptionals["pegPriceType"].(string); localVarOk {
  1088  		localVarFormParams.Add("pegPriceType", parameterToString(localVarTempParam, ""))
  1089  	}
  1090  	if localVarTempParam, localVarOk := localVarOptionals["type_"].(string); localVarOk {
  1091  		localVarFormParams.Add("type", parameterToString(localVarTempParam, ""))
  1092  	}
  1093  	if localVarTempParam, localVarOk := localVarOptionals["ordType"].(string); localVarOk {
  1094  		localVarFormParams.Add("ordType", parameterToString(localVarTempParam, ""))
  1095  	}
  1096  	if localVarTempParam, localVarOk := localVarOptionals["timeInForce"].(string); localVarOk {
  1097  		localVarFormParams.Add("timeInForce", parameterToString(localVarTempParam, ""))
  1098  	}
  1099  	if localVarTempParam, localVarOk := localVarOptionals["execInst"].(string); localVarOk {
  1100  		localVarFormParams.Add("execInst", parameterToString(localVarTempParam, ""))
  1101  	}
  1102  	if localVarTempParam, localVarOk := localVarOptionals["contingencyType"].(string); localVarOk {
  1103  		localVarFormParams.Add("contingencyType", parameterToString(localVarTempParam, ""))
  1104  	}
  1105  	if localVarTempParam, localVarOk := localVarOptionals["text"].(string); localVarOk {
  1106  		localVarFormParams.Add("text", parameterToString(localVarTempParam, ""))
  1107  	}
  1108  
  1109  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
  1110  	if err != nil {
  1111  		return successPayload, nil, err
  1112  	}
  1113  
  1114  	DebugHttpRequest(r)
  1115  
  1116  	localVarHttpResponse, err := a.client.callAPI(r)
  1117  	if err != nil || localVarHttpResponse == nil {
  1118  		return successPayload, localVarHttpResponse, err
  1119  	}
  1120  	defer localVarHttpResponse.Body.Close()
  1121  	if localVarHttpResponse.StatusCode >= 300 {
  1122  		bodyBytes, _ := ioutil.ReadAll(localVarHttpResponse.Body)
  1123  		fmt.Printf("%s\n", string(bodyBytes))
  1124  		return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status)
  1125  	}
  1126  
  1127  	if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil {
  1128  		return successPayload, localVarHttpResponse, err
  1129  	}
  1130  
  1131  	return successPayload, localVarHttpResponse, err
  1132  }
  1133  
  1134  /* OrderApiService Create multiple new orders for the same symbol.
  1135   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.1 * orders)`. Submitting 10 orders via a bulk order call will only count as 1 request, 15 as 2, 32 as 4, and so on.  For now, only `application/json` is supported on this endpoint. 
  1136   * @param ctx context.Context Authentication Context 
  1137   @param optional (nil or map[string]interface{}) with one or more of:
  1138       @param "orders" (string) An array of orders.
  1139   @return []Order*/
  1140  func (a *OrderApiService) OrderNewBulk(ctx context.Context, localVarOptionals map[string]interface{}) ([]Order, *http.Response, error) {
  1141  	var (
  1142  		localVarHttpMethod = strings.ToUpper("Post")
  1143  		localVarPostBody   interface{}
  1144  		localVarFileName   string
  1145  		localVarFileBytes  []byte
  1146  		successPayload     []Order
  1147  	)
  1148  
  1149  	// create path and map variables
  1150  	localVarPath := a.client.cfg.BasePath + "/order/bulk"
  1151  
  1152  	localVarHeaderParams := make(map[string]string)
  1153  	localVarQueryParams := url.Values{}
  1154  	localVarFormParams := url.Values{}
  1155  
  1156  	if err := typeCheckParameter(localVarOptionals["orders"], "string", "orders"); err != nil {
  1157  		return successPayload, nil, err
  1158  	}
  1159  
  1160  	// to determine the Content-Type header
  1161  	localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",}
  1162  
  1163  	// set Content-Type header
  1164  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
  1165  	if localVarHttpContentType != "" {
  1166  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
  1167  	}
  1168  
  1169  	// to determine the Accept header
  1170  	localVarHttpHeaderAccepts := []string{
  1171  		"application/json",
  1172  		"application/xml",
  1173  		"text/xml",
  1174  		"application/javascript",
  1175  		"text/javascript",
  1176  	}
  1177  
  1178  	// set Accept header
  1179  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
  1180  	if localVarHttpHeaderAccept != "" {
  1181  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
  1182  	}
  1183  	if localVarTempParam, localVarOk := localVarOptionals["orders"].(string); localVarOk {
  1184  		localVarFormParams.Add("orders", parameterToString(localVarTempParam, ""))
  1185  	}
  1186  	if ctx != nil {
  1187  		// API Key Authentication
  1188  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
  1189  			var key string
  1190  			if auth.Prefix != "" {
  1191  				key = auth.Prefix + " " + auth.Key
  1192  			} else {
  1193  				key = auth.Key
  1194  			}
  1195  			localVarHeaderParams["api-key"] = key
  1196  		}
  1197  	}
  1198  	if ctx != nil {
  1199  		// API Key Authentication
  1200  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
  1201  			var key string
  1202  			if auth.Prefix != "" {
  1203  				key = auth.Prefix + " " + auth.Key
  1204  			} else {
  1205  				key = auth.Key
  1206  			}
  1207  			localVarHeaderParams["api-nonce"] = key
  1208  		}
  1209  	}
  1210  	if ctx != nil {
  1211  		// API Key Authentication
  1212  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
  1213  			var key string
  1214  			if auth.Prefix != "" {
  1215  				key = auth.Prefix + " " + auth.Key
  1216  			} else {
  1217  				key = auth.Key
  1218  			}
  1219  			localVarHeaderParams["api-signature"] = key
  1220  		}
  1221  	}
  1222  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
  1223  	if err != nil {
  1224  		return successPayload, nil, err
  1225  	}
  1226  
  1227  	localVarHttpResponse, err := a.client.callAPI(r)
  1228  	if err != nil || localVarHttpResponse == nil {
  1229  		return successPayload, localVarHttpResponse, err
  1230  	}
  1231  	defer localVarHttpResponse.Body.Close()
  1232  	if localVarHttpResponse.StatusCode >= 300 {
  1233  		return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status)
  1234  	}
  1235  
  1236  	if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil {
  1237  		return successPayload, localVarHttpResponse, err
  1238  	}
  1239  
  1240  	return successPayload, localVarHttpResponse, err
  1241  }