Jump to content

Recommended Posts

var stop = {

"OrderId": state.activeOrders[1],

"AutoRollover": false,

"AuditId": "xxxx",

"Currency": null,

"Direction": tradeUnits > 0 ? 'buy' : 'sell',

"LastChangedDateTimeUTC": null,

"MarketName": currency,

"BidPrice": state[currency].bidPrice,

"PositionMethodId": 1,

"ExpiryDateTimeUTCDate": null,

"Status": null,

"MarketId": state[currency].marketId,

"LastChangedDateTimeUTCDate": null,

"Reference": null,

"OfferPrice": state[currency].askPrice,

"Quantity": Math.abs(tradeUnits),

"QuoteId": null,

"TradingAccountId": state.config.TradingAccountId,

"Type": null,

"Applicability": "GTC",

"ExpiryDateTimeUTC": null,

"TriggerPrice": avgPrice - state.config.stopLoss

}, limit = {

"OrderId": state.activeOrders[0],

"isTrade": false,

"AutoRollover": false,

"AuditId": "xxxx",

"Currency": null,

"Direction": tradeUnits > 0 ? 'buy' : 'sell',

"LastChangedDateTimeUTC": null,

"MarketName": currency,

"BidPrice": state[currency].bidPrice,

"PositionMethodId": 1,

"ExpiryDateTimeUTCDate": null,

"Status": null,

"MarketId": state[currency].marketId,

"LastChangedDateTimeUTCDate": null,

"Reference": null,

"OfferPrice": state[currency].askPrice,

"Quantity": Math.abs(tradeUnits),

"QuoteId": null,

"TradingAccountId": state.config.TradingAccountId,

"OcoOrder": stop,

"Type": null,

"Applicability": "GTC",

"ExpiryDateTimeUTC": null,

"TriggerPrice": triggerPrice

};



axios.post(state.config.baseURL +

"/order/" + (state.activeOrders[0] ? 'updatestoplimitorder' : 'newstoplimitorder') +

"?UserName=" + state.config.UserName + "&Session=" + state.Session, limit

)

 

I am trying to create/modify an OcoOrder using NodeJS as above. Everything in the code above works and the order is created/modified. However, I have observed that when the Stop is executed, the position is closed but the Limit order is not cancelled. Ideally, I expect that when Stop is executed, the Limit is cancelled and vica-versa. Any idea what am I doing wrong here?

Share this post


Link to post

Hello Ken,

The payload does not appear to be formatted in the correct way to send an OCO. Below is a working example of how an OCO payload should appear.

{
    "MarketId": 401155662,
    "OrderId": 0,
    "Direction": "buy",
    "Applicability": "gtc",
    "ExpiryDateTimeUTC": null,
    "Quantity": 1000,
    "BidPrice": 0.90108,
    "OfferPrice": 0.90128,
    "AuditId": "EF83031443",
    "TradingAccountId": 401843563,
    "TriggerPrice": 1.05,
    "PositionMethodId": 1,
    "IfDone": [],
    "OcoOrder": {
        "MarketId": 401155662,
        "OrderId": 0,
        "Direction": "sell",
        "Applicability": "gtc",
        "ExpiryDateTimeUTC": null,
        "Quantity": 1000,
        "BidPrice": 0.90108,
        "OfferPrice": 0.90128,
        "AuditId": "EF83031443",
        "TradingAccountId": 401843563,
        "TriggerPrice": 0.85,
        "PositionMethodId": 1,
        "IfDone": [],
        "OcoOrder": null,
        "TriggerLevelCalculationTypeId": null,
        "TriggerLevelCalculationValue": null,
        "Reference": "Origin608"
    },
    "TriggerLevelCalculationTypeId": null,
    "TriggerLevelCalculationValue": null,
    "Reference": "Origin608"
}

Kind Regards, PM

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×