Skip to content

Latest commit

 

History

History
634 lines (491 loc) · 43.7 KB

SWGOrderApi.md

File metadata and controls

634 lines (491 loc) · 43.7 KB

SWGOrderApi

All URIs are relative to https://www.bitmex.com/api/v1

Method HTTP request Description
orderAmend PUT /order Amend the quantity or price of an open order.
orderCancel DELETE /order Cancel order(s). Send multiple order IDs to cancel in bulk.
orderCancelAll DELETE /order/all Cancels all of your orders.
orderCancelAllAfter POST /order/cancelAllAfter Automatically cancel all your orders after a specified timeout.
orderClosePosition POST /order/closePosition Close a position. [Deprecated, use POST /order with execInst: 'Close']
orderGetOrders GET /order Get your orders.
orderNew POST /order Create a new order.

orderAmend

-(NSURLSessionTask*) orderAmendWithOrderID: (NSString*) orderID
    origClOrdID: (NSString*) origClOrdID
    clOrdID: (NSString*) clOrdID
    simpleOrderQty: (NSNumber*) simpleOrderQty
    orderQty: (NSNumber*) orderQty
    simpleLeavesQty: (NSNumber*) simpleLeavesQty
    leavesQty: (NSNumber*) leavesQty
    price: (NSNumber*) price
    stopPx: (NSNumber*) stopPx
    pegOffsetValue: (NSNumber*) pegOffsetValue
    text: (NSString*) text
        completionHandler: (void (^)(SWGOrder* output, NSError* error)) handler;

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. > A leavesQty can be used to make a "Filled" order live again, if it is received within 60 seconds of the fill.

Example

SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig];

// Configure API key authorization: (authentication scheme: apiExpires)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-expires"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-expires"];

// Configure API key authorization: (authentication scheme: apiKey)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-key"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-key"];

// Configure API key authorization: (authentication scheme: apiSignature)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-signature"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-signature"];


NSString* orderID = @"orderID_example"; // Order ID (optional)
NSString* origClOrdID = @"origClOrdID_example"; // Client Order ID. See POST /order. (optional)
NSString* clOrdID = @"clOrdID_example"; // Optional new Client Order ID, requires `origClOrdID`. (optional)
NSNumber* simpleOrderQty = @1.2; // Deprecated: simple orders are not supported after 2018/10/26 (optional)
NSNumber* orderQty = @56; // Optional order quantity in units of the instrument (i.e. contracts, for spot it is the base currency in minor currency (e.g. XBt quantity for XBT)). (optional)
NSNumber* simpleLeavesQty = @1.2; // Deprecated: simple orders are not supported after 2018/10/26 (optional)
NSNumber* leavesQty = @56; // Optional leaves quantity in units of the instrument (i.e. contracts, for spot it is the base currency in minor currency (e.g. XBt quantity for XBT)). Useful for amending partially filled orders. (optional)
NSNumber* price = @1.2; // Optional limit price for 'Limit', 'StopLimit', and 'LimitIfTouched' orders. (optional)
NSNumber* stopPx = @1.2; // 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. (optional)
NSNumber* pegOffsetValue = @1.2; // 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. (optional)
NSString* text = @"text_example"; // Optional amend annotation. e.g. 'Adjust skew'. (optional)

SWGOrderApi*apiInstance = [[SWGOrderApi alloc] init];

// Amend the quantity or price of an open order.
[apiInstance orderAmendWithOrderID:orderID
              origClOrdID:origClOrdID
              clOrdID:clOrdID
              simpleOrderQty:simpleOrderQty
              orderQty:orderQty
              simpleLeavesQty:simpleLeavesQty
              leavesQty:leavesQty
              price:price
              stopPx:stopPx
              pegOffsetValue:pegOffsetValue
              text:text
          completionHandler: ^(SWGOrder* output, NSError* error) {
                        if (output) {
                            NSLog(@"%@", output);
                        }
                        if (error) {
                            NSLog(@"Error calling SWGOrderApi->orderAmend: %@", error);
                        }
                    }];

Parameters

Name Type Description Notes
orderID NSString* Order ID [optional]
origClOrdID NSString* Client Order ID. See POST /order. [optional]
clOrdID NSString* Optional new Client Order ID, requires `origClOrdID`. [optional]
simpleOrderQty NSNumber* Deprecated: simple orders are not supported after 2018/10/26 [optional]
orderQty NSNumber* Optional order quantity in units of the instrument (i.e. contracts, for spot it is the base currency in minor currency (e.g. XBt quantity for XBT)). [optional]
simpleLeavesQty NSNumber* Deprecated: simple orders are not supported after 2018/10/26 [optional]
leavesQty NSNumber* Optional leaves quantity in units of the instrument (i.e. contracts, for spot it is the base currency in minor currency (e.g. XBt quantity for XBT)). Useful for amending partially filled orders. [optional]
price NSNumber* Optional limit price for 'Limit', 'StopLimit', and 'LimitIfTouched' orders. [optional]
stopPx NSNumber* 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. [optional]
pegOffsetValue NSNumber* 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. [optional]
text NSString* Optional amend annotation. e.g. 'Adjust skew'. [optional]

Return type

SWGOrder*

Authorization

apiExpires, apiKey, apiSignature

HTTP request headers

  • Content-Type: application/json, application/x-www-form-urlencoded
  • Accept: application/json, application/xml, text/xml, application/javascript, text/javascript

[Back to top] [Back to API list] [Back to Model list] [Back to README]

orderCancel

-(NSURLSessionTask*) orderCancelWithOrderID: (NSString*) orderID
    clOrdID: (NSString*) clOrdID
    text: (NSString*) text
        completionHandler: (void (^)(NSArray<SWGOrder>* output, NSError* error)) handler;

Cancel order(s). Send multiple order IDs to cancel in bulk.

Either an orderID or a clOrdID must be provided.

Example

SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig];

// Configure API key authorization: (authentication scheme: apiExpires)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-expires"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-expires"];

// Configure API key authorization: (authentication scheme: apiKey)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-key"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-key"];

// Configure API key authorization: (authentication scheme: apiSignature)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-signature"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-signature"];


NSString* orderID = @"orderID_example"; // Order ID(s). (optional)
NSString* clOrdID = @"clOrdID_example"; // Client Order ID(s). See POST /order. (optional)
NSString* text = @"text_example"; // Optional cancellation annotation. e.g. 'Spread Exceeded'. (optional)

SWGOrderApi*apiInstance = [[SWGOrderApi alloc] init];

// Cancel order(s). Send multiple order IDs to cancel in bulk.
[apiInstance orderCancelWithOrderID:orderID
              clOrdID:clOrdID
              text:text
          completionHandler: ^(NSArray<SWGOrder>* output, NSError* error) {
                        if (output) {
                            NSLog(@"%@", output);
                        }
                        if (error) {
                            NSLog(@"Error calling SWGOrderApi->orderCancel: %@", error);
                        }
                    }];

Parameters

Name Type Description Notes
orderID NSString* Order ID(s). [optional]
clOrdID NSString* Client Order ID(s). See POST /order. [optional]
text NSString* Optional cancellation annotation. e.g. 'Spread Exceeded'. [optional]

Return type

NSArray*

Authorization

apiExpires, apiKey, apiSignature

HTTP request headers

  • Content-Type: application/json, application/x-www-form-urlencoded
  • Accept: application/json, application/xml, text/xml, application/javascript, text/javascript

[Back to top] [Back to API list] [Back to Model list] [Back to README]

orderCancelAll

-(NSURLSessionTask*) orderCancelAllWithTargetAccountIds: (NSString*) targetAccountIds
    symbol: (NSString*) symbol
    filter: (NSString*) filter
    text: (NSString*) text
        completionHandler: (void (^)(NSArray<SWGOrder>* output, NSError* error)) handler;

Cancels all of your orders.

Example

SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig];

// Configure API key authorization: (authentication scheme: apiExpires)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-expires"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-expires"];

// Configure API key authorization: (authentication scheme: apiKey)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-key"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-key"];

// Configure API key authorization: (authentication scheme: apiSignature)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-signature"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-signature"];


NSString* targetAccountIds = @"targetAccountIds_example"; // AccountIds to cancel all orders, must be a paired account with main user. Also accepts wildcard, [*], this will cancel all orders for all accounts. the authenticated user has order write permissions for. (optional)
NSString* symbol = @"symbol_example"; // Optional symbol. If provided, only cancels orders for that symbol. (optional)
NSString* filter = @"filter_example"; // Optional filter for cancellation. Use to only cancel some orders, e.g. `{\"side\": \"Buy\"}`. (optional)
NSString* text = @"text_example"; // Optional cancellation annotation. e.g. 'Spread Exceeded' (optional)

SWGOrderApi*apiInstance = [[SWGOrderApi alloc] init];

// Cancels all of your orders.
[apiInstance orderCancelAllWithTargetAccountIds:targetAccountIds
              symbol:symbol
              filter:filter
              text:text
          completionHandler: ^(NSArray<SWGOrder>* output, NSError* error) {
                        if (output) {
                            NSLog(@"%@", output);
                        }
                        if (error) {
                            NSLog(@"Error calling SWGOrderApi->orderCancelAll: %@", error);
                        }
                    }];

Parameters

Name Type Description Notes
targetAccountIds NSString* AccountIds to cancel all orders, must be a paired account with main user. Also accepts wildcard, [*], this will cancel all orders for all accounts. the authenticated user has order write permissions for. [optional]
symbol NSString* Optional symbol. If provided, only cancels orders for that symbol. [optional]
filter NSString* Optional filter for cancellation. Use to only cancel some orders, e.g. `{&quot;side&quot;: &quot;Buy&quot;}`. [optional]
text NSString* Optional cancellation annotation. e.g. 'Spread Exceeded' [optional]

Return type

NSArray*

Authorization

apiExpires, apiKey, apiSignature

HTTP request headers

  • Content-Type: application/json, application/x-www-form-urlencoded
  • Accept: application/json, application/xml, text/xml, application/javascript, text/javascript

[Back to top] [Back to API list] [Back to Model list] [Back to README]

orderCancelAllAfter

-(NSURLSessionTask*) orderCancelAllAfterWithTimeout: (NSNumber*) timeout
        completionHandler: (void (^)(NSObject* output, NSError* error)) handler;

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.

Example

SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig];

// Configure API key authorization: (authentication scheme: apiExpires)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-expires"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-expires"];

// Configure API key authorization: (authentication scheme: apiKey)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-key"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-key"];

// Configure API key authorization: (authentication scheme: apiSignature)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-signature"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-signature"];


NSNumber* timeout = @1.2; // Timeout in ms. Set to 0 to cancel this timer. 

SWGOrderApi*apiInstance = [[SWGOrderApi alloc] init];

// Automatically cancel all your orders after a specified timeout.
[apiInstance orderCancelAllAfterWithTimeout:timeout
          completionHandler: ^(NSObject* output, NSError* error) {
                        if (output) {
                            NSLog(@"%@", output);
                        }
                        if (error) {
                            NSLog(@"Error calling SWGOrderApi->orderCancelAllAfter: %@", error);
                        }
                    }];

Parameters

Name Type Description Notes
timeout NSNumber* Timeout in ms. Set to 0 to cancel this timer.

Return type

NSObject*

Authorization

apiExpires, apiKey, apiSignature

HTTP request headers

  • Content-Type: application/json, application/x-www-form-urlencoded
  • Accept: application/json, application/xml, text/xml, application/javascript, text/javascript

[Back to top] [Back to API list] [Back to Model list] [Back to README]

orderClosePosition

-(NSURLSessionTask*) orderClosePositionWithSymbol: (NSString*) symbol
    price: (NSNumber*) price
        completionHandler: (void (^)(SWGOrder* output, NSError* error)) handler;

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.

Example

SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig];

// Configure API key authorization: (authentication scheme: apiExpires)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-expires"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-expires"];

// Configure API key authorization: (authentication scheme: apiKey)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-key"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-key"];

// Configure API key authorization: (authentication scheme: apiSignature)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-signature"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-signature"];


NSString* symbol = @"symbol_example"; // Symbol of position to close.
NSNumber* price = @1.2; // Optional limit price. (optional)

SWGOrderApi*apiInstance = [[SWGOrderApi alloc] init];

// Close a position. [Deprecated, use POST /order with execInst: 'Close']
[apiInstance orderClosePositionWithSymbol:symbol
              price:price
          completionHandler: ^(SWGOrder* output, NSError* error) {
                        if (output) {
                            NSLog(@"%@", output);
                        }
                        if (error) {
                            NSLog(@"Error calling SWGOrderApi->orderClosePosition: %@", error);
                        }
                    }];

Parameters

Name Type Description Notes
symbol NSString* Symbol of position to close.
price NSNumber* Optional limit price. [optional]

Return type

SWGOrder*

Authorization

apiExpires, apiKey, apiSignature

HTTP request headers

  • Content-Type: application/json, application/x-www-form-urlencoded
  • Accept: application/json, application/xml, text/xml, application/javascript, text/javascript

[Back to top] [Back to API list] [Back to Model list] [Back to README]

orderGetOrders

-(NSURLSessionTask*) orderGetOrdersWithSymbol: (NSString*) symbol
    filter: (NSString*) filter
    columns: (NSString*) columns
    count: (NSNumber*) count
    start: (NSNumber*) start
    reverse: (NSNumber*) reverse
    startTime: (NSDate*) startTime
    endTime: (NSDate*) endTime
        completionHandler: (void (^)(NSArray<SWGOrder>* output, NSError* error)) handler;

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 for explanations of these fields.

Example

SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig];

// Configure API key authorization: (authentication scheme: apiExpires)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-expires"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-expires"];

// Configure API key authorization: (authentication scheme: apiKey)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-key"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-key"];

// Configure API key authorization: (authentication scheme: apiSignature)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-signature"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-signature"];


NSString* symbol = @"symbol_example"; // Instrument symbol. Send a bare series (e.g. XBT) to get data for the nearest expiring contract in that series.  You can also send a timeframe, e.g. `XBT:quarterly`. Timeframes are `nearest`, `daily`, `weekly`, `monthly`, `quarterly`, `biquarterly`, and `perpetual`.  Symbols are case-insensitive. (optional)
NSString* filter = @"filter_example"; // 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. (optional)
NSString* columns = @"columns_example"; // 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. (optional)
NSNumber* count = @100; // Number of results to fetch. Must be a positive integer. (optional) (default to 100)
NSNumber* start = @0; // Starting point for results. (optional) (default to 0)
NSNumber* reverse = @false; // If true, will sort results newest first. (optional) (default to false)
NSDate* startTime = @"2013-10-20T19:20:30+01:00"; // Starting date filter for results. (optional)
NSDate* endTime = @"2013-10-20T19:20:30+01:00"; // Ending date filter for results. (optional)

SWGOrderApi*apiInstance = [[SWGOrderApi alloc] init];

// Get your orders.
[apiInstance orderGetOrdersWithSymbol:symbol
              filter:filter
              columns:columns
              count:count
              start:start
              reverse:reverse
              startTime:startTime
              endTime:endTime
          completionHandler: ^(NSArray<SWGOrder>* output, NSError* error) {
                        if (output) {
                            NSLog(@"%@", output);
                        }
                        if (error) {
                            NSLog(@"Error calling SWGOrderApi->orderGetOrders: %@", error);
                        }
                    }];

Parameters

Name Type Description Notes
symbol NSString* Instrument symbol. Send a bare series (e.g. XBT) to get data for the nearest expiring contract in that series. You can also send a timeframe, e.g. `XBT:quarterly`. Timeframes are `nearest`, `daily`, `weekly`, `monthly`, `quarterly`, `biquarterly`, and `perpetual`. Symbols are case-insensitive. [optional]
filter NSString* Generic table filter. Send JSON key/value pairs, such as `{&quot;key&quot;: &quot;value&quot;}`. You can key on individual fields, and do more advanced querying on timestamps. See the Timestamp Docs for more details. [optional]
columns NSString* 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. [optional]
count NSNumber* Number of results to fetch. Must be a positive integer. [optional] [default to 100]
start NSNumber* Starting point for results. [optional] [default to 0]
reverse NSNumber* If true, will sort results newest first. [optional] [default to false]
startTime NSDate* Starting date filter for results. [optional]
endTime NSDate* Ending date filter for results. [optional]

Return type

NSArray*

Authorization

apiExpires, apiKey, apiSignature

HTTP request headers

  • Content-Type: application/json, application/x-www-form-urlencoded
  • Accept: application/json, application/xml, text/xml, application/javascript, text/javascript

[Back to top] [Back to API list] [Back to Model list] [Back to README]

orderNew

-(NSURLSessionTask*) orderNewWithSymbol: (NSString*) symbol
    side: (NSString*) side
    simpleOrderQty: (NSNumber*) simpleOrderQty
    orderQty: (NSNumber*) orderQty
    price: (NSNumber*) price
    displayQty: (NSNumber*) displayQty
    stopPx: (NSNumber*) stopPx
    clOrdID: (NSString*) clOrdID
    clOrdLinkID: (NSString*) clOrdLinkID
    pegOffsetValue: (NSNumber*) pegOffsetValue
    pegPriceType: (NSString*) pegPriceType
    ordType: (NSString*) ordType
    timeInForce: (NSString*) timeInForce
    execInst: (NSString*) execInst
    contingencyType: (NSString*) contingencyType
    text: (NSString*) text
        completionHandler: (void (^)(SWGOrder* output, NSError* error)) handler;

Create a new order.

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 ordTypes: - 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. - 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. - Pegged: Pegged orders allow users to submit a limit price relative to the current market price. Specify a pegPriceType, and pegOffsetValue. - Pegged orders must have an execInst of Fixed. This means the limit price is set at the time the order is accepted and does not change as the reference price changes. - PrimaryPeg: Price is set relative to near touch price. - MarketPeg: Price is set relative to far touch price. - A pegPriceType submitted with no ordType is treated as a Pegged order. #### Execution Instructions The following execInsts 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. This is intended to protect you from the far touch moving towards you while the order is in transit. It is not intended for speculating on the far touch moving away after submission - we consider such behaviour abusive and monitor for it. - 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. IndexPrice is not applicable to spot trading symbols. - 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 aggressive will be amended first. Not applicable to spot trading symbols. - 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 orderQty is not specified, a Close order has an orderQty equal to your current position's size. Not applicable to spot trading symbols. - Note that a Close order without an orderQty requires a side, so that BitMEX knows if it should trigger above or below the stopPx. - LastWithinMark: Used by stop orders with LastPrice to allow stop triggers only when: - For Sell Stop Market / Stop Limit Order - Last Price &lt= Stop Price - Last Price &gt= Mark Price × (1 - 5%) - For Buy Stop Market / Stop Limit Order: - Last Price &gt= Stop Price - Last Price &lt= Mark Price × (1 + 5%) - Not applicable to spot trading symbols. - Fixed: Pegged orders must have an execInst of Fixed. This means the limit price is set at the time the order is accepted and does not change as the reference price changes. #### Pegged Orders Pegged orders allow users to submit a limit price relative to the current market price. The limit price is set once when the order is submitted and does not change with the reference price. This order type is not intended for speculating on the far touch moving away after submission - we consider such behaviour abusive and monitor for it. Pegged orders have an ordType of Pegged, and an execInst of Fixed. A pegPriceType and pegOffsetValue must also be submitted: - PrimaryPeg - price is set relative to the near touch price - MarketPeg - price is set relative to the far touch price #### Trailing Stop Pegged Orders Use pegPriceType of TrailingStopPeg to create Trailing Stops. The price is set at submission and updates once per second if the underlying price (last/mark/index) has moved by more than 0.1%. stopPx then moves as the market moves away from the peg, and freezes as the market moves toward it. Use 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. #### 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 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. #### 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 Simple Quantities are deprecated as of 2018/10/26 #### Rate Limits You can improve your reactivity to market movements while staying under your rate limit by using the Amend endpoint (PUT /order). 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. You can also change the clOrdID by amending an order, supplying an origClOrdID, and your desired new ID as the clOrdID param, like so: # Amends an order's leavesQty, and updates its clOrdID to \"def-456\" PUT /api/v1/order {\"origClOrdID\": \"abc-123\", \"clOrdID\": \"def-456\", \"leavesQty\": 1000}

Example

SWGDefaultConfiguration *apiConfig = [SWGDefaultConfiguration sharedConfig];

// Configure API key authorization: (authentication scheme: apiExpires)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-expires"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-expires"];

// Configure API key authorization: (authentication scheme: apiKey)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-key"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-key"];

// Configure API key authorization: (authentication scheme: apiSignature)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"api-signature"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"api-signature"];


NSString* symbol = @"symbol_example"; // Instrument symbol. e.g. 'XBTUSD'.
NSString* side = @"side_example"; // Order side. Valid options: Buy, Sell. Defaults to 'Buy' unless `orderQty` is negative. (optional)
NSNumber* simpleOrderQty = @1.2; // Deprecated: simple orders are not supported after 2018/10/26 (optional)
NSNumber* orderQty = @56; // Order quantity in units of the instrument (i.e. contracts, for spot it is base currency in minor currency for spot (e.g. XBt quantity for XBT)). (optional)
NSNumber* price = @1.2; // Optional limit price for 'Limit', 'StopLimit', and 'LimitIfTouched' orders. (optional)
NSNumber* displayQty = @56; // Optional quantity to display in the book. Use 0 for a fully hidden order. (optional)
NSNumber* stopPx = @1.2; // 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. (optional)
NSString* clOrdID = @"clOrdID_example"; // Optional Client Order ID. This clOrdID will come back on the order and any related executions. (optional)
NSString* clOrdLinkID = @"clOrdLinkID_example"; // Optional Client Order Link ID for contingent orders (optional)
NSNumber* pegOffsetValue = @1.2; // 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. (optional)
NSString* pegPriceType = @"pegPriceType_example"; // Optional peg price type. Valid options: MarketPeg, PrimaryPeg, TrailingStopPeg. (optional)
NSString* ordType = @"Limit"; // Order type. Valid options: Market, Limit, Stop, StopLimit, MarketIfTouched, LimitIfTouched, Pegged. Defaults to 'Limit' when `price` is specified. Defaults to 'Stop' when `stopPx` is specified. Defaults to 'StopLimit' when `price` and `stopPx` are specified. (optional) (default to Limit)
NSString* timeInForce = @"timeInForce_example"; // Time in force. Valid options: Day, GoodTillCancel, ImmediateOrCancel, FillOrKill. Defaults to 'GoodTillCancel' for 'Limit', 'StopLimit', and 'LimitIfTouched' orders. (optional)
NSString* execInst = @"execInst_example"; // Optional execution instructions. Valid options: ParticipateDoNotInitiate, AllOrNone, MarkPrice, IndexPrice, LastPrice, Close, ReduceOnly, Fixed, LastWithinMark. 'AllOrNone' instruction requires `displayQty` to be 0. 'MarkPrice', 'IndexPrice' or 'LastPrice' instruction valid for 'Stop', 'StopLimit', 'MarketIfTouched', and 'LimitIfTouched' orders. 'LastWithinMark' instruction valid for 'Stop' and 'StopLimit' with instruction 'LastPrice'. IndexPrice, LastWithMark, Close and ReduceOnly are not applicable to spot trading symbols. (optional)
NSString* contingencyType = @"contingencyType_example"; // Optional contingency type for use with `clOrdLinkID`. Valid options: OneCancelsTheOther, OneTriggersTheOther. (optional)
NSString* text = @"text_example"; // Optional order annotation. e.g. 'Take profit'. (optional)

SWGOrderApi*apiInstance = [[SWGOrderApi alloc] init];

// Create a new order.
[apiInstance orderNewWithSymbol:symbol
              side:side
              simpleOrderQty:simpleOrderQty
              orderQty:orderQty
              price:price
              displayQty:displayQty
              stopPx:stopPx
              clOrdID:clOrdID
              clOrdLinkID:clOrdLinkID
              pegOffsetValue:pegOffsetValue
              pegPriceType:pegPriceType
              ordType:ordType
              timeInForce:timeInForce
              execInst:execInst
              contingencyType:contingencyType
              text:text
          completionHandler: ^(SWGOrder* output, NSError* error) {
                        if (output) {
                            NSLog(@"%@", output);
                        }
                        if (error) {
                            NSLog(@"Error calling SWGOrderApi->orderNew: %@", error);
                        }
                    }];

Parameters

Name Type Description Notes
symbol NSString* Instrument symbol. e.g. 'XBTUSD'.
side NSString* Order side. Valid options: Buy, Sell. Defaults to 'Buy' unless `orderQty` is negative. [optional]
simpleOrderQty NSNumber* Deprecated: simple orders are not supported after 2018/10/26 [optional]
orderQty NSNumber* Order quantity in units of the instrument (i.e. contracts, for spot it is base currency in minor currency for spot (e.g. XBt quantity for XBT)). [optional]
price NSNumber* Optional limit price for 'Limit', 'StopLimit', and 'LimitIfTouched' orders. [optional]
displayQty NSNumber* Optional quantity to display in the book. Use 0 for a fully hidden order. [optional]
stopPx NSNumber* 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. [optional]
clOrdID NSString* Optional Client Order ID. This clOrdID will come back on the order and any related executions. [optional]
clOrdLinkID NSString* Optional Client Order Link ID for contingent orders [optional]
pegOffsetValue NSNumber* 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. [optional]
pegPriceType NSString* Optional peg price type. Valid options: MarketPeg, PrimaryPeg, TrailingStopPeg. [optional]
ordType NSString* Order type. Valid options: Market, Limit, Stop, StopLimit, MarketIfTouched, LimitIfTouched, Pegged. Defaults to 'Limit' when `price` is specified. Defaults to 'Stop' when `stopPx` is specified. Defaults to 'StopLimit' when `price` and `stopPx` are specified. [optional] [default to Limit]
timeInForce NSString* Time in force. Valid options: Day, GoodTillCancel, ImmediateOrCancel, FillOrKill. Defaults to 'GoodTillCancel' for 'Limit', 'StopLimit', and 'LimitIfTouched' orders. [optional]
execInst NSString* Optional execution instructions. Valid options: ParticipateDoNotInitiate, AllOrNone, MarkPrice, IndexPrice, LastPrice, Close, ReduceOnly, Fixed, LastWithinMark. 'AllOrNone' instruction requires `displayQty` to be 0. 'MarkPrice', 'IndexPrice' or 'LastPrice' instruction valid for 'Stop', 'StopLimit', 'MarketIfTouched', and 'LimitIfTouched' orders. 'LastWithinMark' instruction valid for 'Stop' and 'StopLimit' with instruction 'LastPrice'. IndexPrice, LastWithMark, Close and ReduceOnly are not applicable to spot trading symbols. [optional]
contingencyType NSString* Optional contingency type for use with `clOrdLinkID`. Valid options: OneCancelsTheOther, OneTriggersTheOther. [optional]
text NSString* Optional order annotation. e.g. 'Take profit'. [optional]

Return type

SWGOrder*

Authorization

apiExpires, apiKey, apiSignature

HTTP request headers

  • Content-Type: application/json, application/x-www-form-urlencoded
  • Accept: application/json, application/xml, text/xml, application/javascript, text/javascript

[Back to top] [Back to API list] [Back to Model list] [Back to README]