Jump to content
Sign in to follow this  
smironov

Can't place order below the market - is there any restriction?

Recommended Posts

Hello,

I’m trying place orders on AUD/CHF market. Current bid/ask is 2.235/2.2413. When I ask for TriggeredPrice=2.5 all is OK, but for 2.1 I get StatusReason=25 which means “Trigger price is not correct given the order direction and type.” Is there a rule which prohibits place orders below market? Also, order type (stop/limit) as far as I understand should be calculated automatically by backend, shouldn’t it?

Share this post


Link to post

Are you passing in the BidPrice, OfferPrice and AuditId of the current price? At the moment you will need to supply this. A future optimisation might remove the requirement for this.

Share this post


Link to post

Are you passing in the BidPrice, OfferPrice and AuditId of the current price? At the moment you will need to supply this. A future optimisation might remove the requirement for this.

I do. Here is raw request:

 {“MarketId”:400481112,“Direction”:“sell”,“Quantity”:10000,“BidPrice”:2.235,“OfferPrice”:2.2413,“AuditId”:“20110427-G2PREPROD3-0339751”,“TradingAccountId”:400197672,“Applicability”:“GTC”,“ExpiryDateTimeUTC”:null,“Guaranteed”:false,“TriggerPrice”:2.1}

And, as I said early, I’m able to place an order above market with the same request (except TriggeredPrice)

Share this post


Link to post

Are you passing in the BidPrice, OfferPrice and AuditId of the current price? At the moment you will need to supply this. A future optimisation might remove the requirement for this.

@smironov the price for AUD/CHF is 0.9404 in the pre prod at the moment, the bid and offer prices you are passing look like prices for a market like EUR/TRY?

Share this post


Link to post

Are you passing in the BidPrice, OfferPrice and AuditId of the current price? At the moment you will need to supply this. A future optimisation might remove the requirement for this.

@timothy It’s AUD/CHF for user XX381270. Dispite the price, why I’m able to place order at 2.5 but can’t at 2.1?

Share this post


Link to post

it seems I'm having this problem too, when trying to open spread orders on the UK 100 DFT. Currently (at 23:30 on 31-05-2015) the market is OOH and trading at around 7000.

 

If i execute the following code it works perfectly to open a BUY order above the current price. I also tested it 1000 points lower (i.e. opening at 5950 and beneath the current market level) and it opens the orders correctly with no errors.

 

{
"MarketId":400616113,
"CurrencyId":6, 
"AutoRollover":false,
"TriggerPrice":7030.5,
"Direction":"buy",
"Quantity":7.9,
"OfferPrice":7030,
"TradingAccountId":XXXXXXXXX,
"Guaranteed":false,
"Applicability":"GTD",
"ExpiryDateTimeUTC":"2015-05-31 23:59:00"
}
 
 
If I try to open a sell order ABOVE the current market level it also works:
 
{
"MarketId":400616113,
"CurrencyId":6, 
"AutoRollover":false,
"TriggerPrice":7184,
"Direction":"sell",
"Quantity":7.9,
"BidPrice":7184,
"OfferPrice":7184,
"TradingAccountId":XXXXXXXXX,
"Guaranteed":false,
"Applicability":"GTD",
"ExpiryDateTimeUTC":"2015-05-31 23:59:00"
}
 

However, I get an error when I run exactly the same code but with an opening price of 6984 - i.e. below the current level:

 

{
"MarketId":400616113,
"CurrencyId":6, 
"AutoRollover":false,
"TriggerPrice":6984,
"Direction":"sell",
"Quantity":7.9,
"BidPrice":6984,
"OfferPrice":6984,
"TradingAccountId":XXXXXXXXX,
"Guaranteed":false,
"Applicability":"GTD",
"ExpiryDateTimeUTC":"2015-05-31 23:59:00"
}
 

then I get an Instruction red card, as well as an order error #25 - "Trigger price is not correct given the order direction and type."

 

Is it something to do with the combination of TriggerPrice / Bid Price / OfferPrice? It seems that not all might be necessary, however even after trying different combinations I was unable to get it to work...

 

Many thanks for any help you can provide!

Share this post


Link to post

Hello Cedric,

 

I checked your code against our Test Harness in the Live environment. The order request was accepted successfully and there were no errors.

 

The trigger price of 6960 is set below the current price of 6970. Just to check, you are using your TradingAccountId and not your trading account number used as part of your login credentials?

 

You can find your TradingAccountId if you don't already have it by using the GetClientAndTradingAccount call.

 

My Test harness code is just the code you posted, modified for price level and expiry time:  

doPost('/order/newstoplimitorder',{
"MarketId":400616113,
"CurrencyId":6, 
"AutoRollover":false,
"TriggerPrice":6960,
"Direction":"sell",
"Quantity":1,
"BidPrice":6970,
"OfferPrice":6970,
"TradingAccountId":400239061,
"Guaranteed":false,
"Applicability":"GTD",
"ExpiryDateTimeUTC":"2015-06-02 23:59:00"
});

Share this post


Link to post

Hey Physicsman - thank you for replying and for taking the time to investigate. In each of the 4 api calls I was using the same TradingAccountId, however it was just on the last one that it failed. Presumably if I had the wrong id it would cause the other 3 calls to fail too? I'm happy to DM you with the details, but was just not sure whether to post them openly in the forum...

 

That's weird/annoying that it works for you and not for me! I'll try again now with some revised api calls to check whether I can replicate the error.

 

Thanks again

Share this post


Link to post

(Edited to add: I'm investigating further as I've noticed I'm getting a red card too! Will post again once I have an update.)

 

Hello Cedric,

 

The next step in our investigation should be verifying that the API call can work with your account too, and then we can start eliminating false leads and red herrings.

 

I assume you are using a Live environment Test or demo account? The Live test harness has the same URL as the actual Live API where you are sending your calls: https://ciapi.cityindex.com/tradingapi

 

In the test harness there are some example API calls that you won't need - you can delete them to remove clutter (leave the login code though!). Replace the dummy login credentials with your test/demo account credentials. Then cut and paste your code to place a sell order below the market. After you press the [Execute] button do you receive a status code success? 

 

If you receive the success return then we know 3 things straight away:

1) the problem is not with your account,

2) there is nothing wrong with your code,

3) the API backend (order processing engine) is functioning normally without any problems.

 

We can then start thinking about where and what else is causing the problem.

 

Kind Regards,

PM!

Edited by Physicsman
I'm investigating further as I've noticed I'm getting a red card too! Will post again once I have an update.

Share this post


Link to post

Hi!

 

I've found the culprit!

In your code the property name is "CurrencyID" and not the correct name, which is "Currency". The value you can leave as null or "GBP" assuming you have a Sterling account. I'm not sure that your other orders you tested would have worked either? In your original post, your code looks like it is also using CurrencyID for the other orders too.

 

I've verified that the following code will work. A quick way to see if your code is working is to login to one of our platforms, for example our browser based Advantage Web and have the Active Orders panel open. When you send the API call, if the order is successful you should see the order appear almost instantaneously in the Active Orders panel. 

 

Please check that the following code also creates the sell entry order (and any other order) for you too and let us know. Thanks!

doPost('/order/newstoplimitorder',{
"Applicability":"GTD",
"ExpiryDateTimeUTC":"2015-06-03 23:59:00",
"OcoOrder":null,
"Direction":"sell",
"TriggerPrice":6901,
"Currency":null,
"BidPrice":6924.2,
"ExpiryDateTimeUTCDate":null,
"PositionMethodId":1,
"AutoRollover":false,
"MarketId":400616113,
"OfferPrice":6925.2,
"OrderId":0,
"Quantity":2,
"QuoteId":null,
"IfDone":[],
"TradingAccountId":400239062
});

Kind Regards,

PM!

Share this post


Link to post

HI PM and thanks for investigating! All the orders were using CurrencyId, however I've done as you said and switched them all to null. (very) unfortunately it doesn't seem to have fixed the problem. Even when I copy and paste your code (changing only the TracingAccountId, TriggerPrice, BidPrice, OfferPrice) I continue to get different outcomes depending on whether the trigger price is above or below the current market level.

 

So, right now the market is at 6838.6 / 6844 with a 6 pt spread and it's before 23:59. If I run the following code (i.e. where the trigger is above current):

 

{
"Applicability":"GTD",
"ExpiryDateTimeUTC":"2015-06-04 23:59:00",
"OcoOrder":null,
"Direction":"sell",
"TriggerPrice":6900,
"Currency":null,
"BidPrice":6899.0,
"ExpiryDateTimeUTCDate":null,
"PositionMethodId":1,
"AutoRollover":false,
"MarketId":400616113,
"OfferPrice":6901.0,
"OrderId":0,
"Quantity":2,
"QuoteId":null,
"IfDone":[],
"TradingAccountId":400388457
}
 
it works and I can see the order correctly appear in the live platform. However, if I drop the trigger/bid/offer values by 100 points to below the current level (which is the code below) it returns the error
 
{
"Applicability":"GTD",
"ExpiryDateTimeUTC":"2015-06-04 23:59:00",
"OcoOrder":null,
"Direction":"sell",
"TriggerPrice":6800.0,
"Currency":null,
"BidPrice":6799.0,
"ExpiryDateTimeUTCDate":null,
"PositionMethodId":1,
"AutoRollover":false,
"MarketId":400616113,
"OfferPrice":6801.0,
"OrderId":0,
"Quantity":2,
"QuoteId":null,
"IfDone":[],
"TradingAccountId":400388457
}
 
returns:
 
{"Status":2,"StatusReason":75,"OrderId":0,"Orders":[{"OrderId":0,"StatusReason":25,"Status":10,"OrderTypeId":3,"Price":0.0,"Quantity":2.0,"TriggerPrice":6800.0,
"CommissionCharge":0.0,"IfDone":[],"GuaranteedPremium":0.0,"OCO":null}],"Quote":null,"Actions":[],"ErrorMessage":null}
 
 
Could this be to do with the Bid/Offer values? I've not quite figured how they are interpreted by the API because when opening a "buy" order I only seem to need to supply a TriggerPrice and an OfferValue. However, it seems that for a "sell" position I need to supply all three for it to have any chance of working. However, given that the spread would change throughout the day, I'm not sure exactly which values I am meant to be plugging in to the bid/offer slots. I would have thought that if I supply the trigger price and a direction (i.e. buy/sell) the platform should be able to calculate the appropriate bid/offer values at the time so I'm not sure if they're actually redundant?
 
Thanks again for your help... I really am grateful because I had pretty much accepted that I was going mad

Share this post


Link to post

Hello Cedric,

 

I see a couple of things wrong.

 

1) With regards to the BidPrice and OfferPrice. Your code should subscribe to the price stream for this market so that the program receives real time updating live prices. At the time you place your order, the program should read in what the current bid/offer prices are and use those values in your order submission. 

 

Therefore, in your code for testing orders above/below the market you should not be adding/subtracting 100 from the BidPrice and OfferPrice, but using the current values of the Bid/Ask.

 

2) I noticed that both in the sell above and sell below code, your order trigger price is in between the bid/ask spread. Order trigger prices must always be *outside* the bid/ask spread. I'm surprised you received an order success when you tried to place your sell above order. I've tried placing an order in between the spread and always get rejected. The second I move the order trigger price outside the spread then it is fine.

 

Therefore, using your example of the current prices being 6838 / 6844. In your code to test for selling above the current price (all other properties removed for clarity)

{
...
"TriggerPrice":6850.0,
"BidPrice":6838.0,
"OfferPrice":6844.0,
...

}

That is the TriggerPrice must be > 6844.

 

Similarly, when testing for a sell order below the market price, the code should look like:

{
...
"TriggerPrice":6830.0,
"BidPrice":6838.0,
"OfferPrice":6844.0,
...
}

That is the TriggerPrice must be

 

Fingers crossed we finally get success at third time lucky!  :) Please let us know if it works! 

 

Kind Regards,

PM!

Share this post


Link to post

I seems to work! It looks like it was the Bid / Offer values after all... I'd assumed that they referred to the Bid/Offer values as they would be once the trigger price had been hit as opposed to at the point of submitting the call. Out of interest, what purpose does it serve supplying them in the api call at all? How does it use them? In any case, it appears to work.

 

I've only managed to test it during a closed market so far, but all the combinations I tried worked first time. I'll try it again on Monday morning and let you know how it goes.

 

Thank you so much for your help! I really hope we nailed it this time.

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
Sign in to follow this  
×