Jump to content

Recommended Posts

Hi Agent,

Yes, you should subscribe to the live prices stream (via Lightstreamer) for the markets you are interested in trading. This will provide you with a feed of live updating prices that you can then use for your trade request. 

Kind Regards, PM

Share this post


Link to post

 

On 5/14/2020 at 11:40 PM, Physicsman said:

Hi Agent,

Yes, you should subscribe to the live prices stream (via Lightstreamer) for the markets you are interested in trading. This will provide you with a feed of live updating prices that you can then use for your trade request. 

Kind Regards, PM

So does this API only support LIMIT orders and not MARKET orders? Because the order price is irrelevant for market orders but since it seems to be a required field only limit orders are supported?

Share this post


Link to post

Hello JPL,

The API supports both market and limit orders.

To send a market order, use the /newtradeorder endpoint http://docs.labs.gaincapital.com/#HTTP Services/Trade.htm%3FTocPath%3DCIAPI%20Reference|HTTP%20Services|Trades%20and%20Orders|_____16 where there is no mandatory order price field.

Limit orders use the /newstoplimitorder endpoint where the order price field is mandatory http://docs.labs.gaincapital.com/#HTTP Services/Order.htm%3FTocPath%3DCIAPI%20Reference|HTTP%20Services|Trades%20and%20Orders|_____15.

Kind Regards, PM

Share this post


Link to post
44 minutes ago, Physicsman said:

Hello JPL,

The API supports both market and limit orders.

To send a market order, use the /newtradeorder endpoint http://docs.labs.gaincapital.com/#HTTP Services/Trade.htm%3FTocPath%3DCIAPI%20Reference|HTTP%20Services|Trades%20and%20Orders|_____16 where there is no mandatory order price field.

Limit orders use the /newstoplimitorder endpoint where the order price field is mandatory http://docs.labs.gaincapital.com/#HTTP Services/Order.htm%3FTocPath%3DCIAPI%20Reference|HTTP%20Services|Trades%20and%20Orders|_____15.

Kind Regards, PM

Ok thats great but when POSTing to https://ciapi.cityindex.com/TradingAPI/order/newtradeorder there is BidPrice and OfferPrice in the request body, which seems to be mandatory because if I remove them BidPrice and OfferPrice fields I get "Status": 4, "StatusReason": 45.

How can I place a market order without filling in the price fields? Can you please describe by modifying the request body below for how to properly place a market order without any mandatory price fields, I do not understand how I can place a market order "where there is no mandatory order price field".

{"IfDone":[],"Direction":"buy","ExpiryDateTimeUTCDate":null,"LastChangedDateTimeUTCDate":null,
"OcoOrder":null,"Type":null,"ExpiryDateTimeUTC":null,"Applicability":null,"TriggerPrice"
:null,"BidPrice":1.226,"AuditId":"xxxx","AutoRollover":false,"MarketId":XYZ,"OfferPrice"
:1.226
,"OrderId":0,"Currency":null,"Quantity":1000,"QuoteId":null,"LastChangedDateTimeUTC":null,"PositionMethodId"
:1,"TradingAccountId":"XYZ","MarketName":null,"Status":null,"isTrade":true}
 

Thank you

Share this post


Link to post

Hello JPL,

The BidPrice and OfferPrice fields in the market order call are the current market bid/offer prices, not a Limit order price. 

You need to subscribe via Lightstreamer to receive the live stream of market prices for the market you are trading. You can then feed in the latest bid/offer prices received at the time you send the trade request. 

For an example, see the trade ticket on any of our trading platforms (which uses the API). The trade ticket displays the live market prices updating, and so will have and can send the market price at the time you send your trade request.

NOTE: I see in the POST body pasted in your reply that there is a "TriggerPrice" field. The call to place a market order does not have a "TriggerPrice" field. The permissable fields in a trade request are detailed at: http://docs.labs.gaincapital.com/#Data Types/NewTradeOrderRequestDTO.htm

Kind Reagrds, PM

Share this post


Link to post
3 hours ago, Physicsman said:

Hello JPL,

The BidPrice and OfferPrice fields in the market order call are the current market bid/offer prices, not a Limit order price. 

You need to subscribe via Lightstreamer to receive the live stream of market prices for the market you are trading. You can then feed in the latest bid/offer prices received at the time you send the trade request. 

For an example, see the trade ticket on any of our trading platforms (which uses the API). The trade ticket displays the live market prices updating, and so will have and can send the market price at the time you send your trade request.

NOTE: I see in the POST body pasted in your reply that there is a "TriggerPrice" field. The call to place a market order does not have a "TriggerPrice" field. The permissable fields in a trade request are detailed at: http://docs.labs.gaincapital.com/#Data Types/NewTradeOrderRequestDTO.htm

Kind Reagrds, PM

Ok thank you, so the Market order does not use the bid/offer prices for the order ticket but the the way the API is architected the BidPrice and OfferPrice values still need to be passed. And if I set two arbitrary values I noticed I could get StatusReason 158 if they exceed the price tolerance.

The app Im building is a server-side (Python) app which will only be responsible for order routing which is why I do not intend to implement Lightstreamer here. The buy and sell signals are abstracted into another client side Node.js app which manages the price stream and will connect to Lightstreamer.

But one function that I need to achieve in this sever-side app is a fail-safe that can execute a market trade (e.g. to urgently close a position at market) regardless of the price stream that is fed into the client side app. Since I cannot send an explicit market order without still adding BidPrice and OfferPrice within the price tolerance then:

TLDR: Which GCAPI endpoint can I call from my server-side app to get recent (not necessarily second fresh) prices for a market?

E.g. Im thinking I can just use

http://docs.labs.gaincapital.com/index.html#HTTP Services/GetLatestPriceTicks.htm%3FTocPath%3DCIAPI%20Reference|HTTP%20Services|Price%20History|_____5

or

http://docs.labs.gaincapital.com/index.html#HTTP Services/GetLatestPriceBars.htm%3FTocPath%3DCIAPI%20Reference|HTTP%20Services|Price%20History|_____1

Which of these or which other GCAPI endpoint could give the most recent prices when called?

Share this post


Link to post
3 hours ago, jpl said:

Ok thank you, so the Market order does not use the bid/offer prices for the order ticket but the the way the API is architected the BidPrice and OfferPrice values still need to be passed. And if I set two arbitrary values I noticed I could get StatusReason 158 if they exceed the price tolerance.

To clarify, the Market order (Trade) call uses the current market price at the time you send the trade request. 

The GetLatestPrice Ticks call will provide you the most recent price at the time you send the request (assuming network latency is in the milliseconds to reach the server). You can then use this most recent price in your server side crash close position call. Provided that markets are not moving very fast then they probably will not have moved past the Price Tolerance setting. 

What you could do is send a suitably large price tolerance value in your trade request so that you can ensure the trade request to close position is accepted and not rejected due to price tolerance exceeded. You can see that there is a PriceTolerance field in the NewTradeOrderReuquestDTO.

Kind Regards, PM

 

Share this post


Link to post
13 hours ago, Physicsman said:

What you could do is send a suitably large price tolerance value in your trade request so that you can ensure the trade request to close position is accepted and not rejected due to price tolerance exceeded. You can see that there is a PriceTolerance field in the NewTradeOrderReuquestDTO.

That's great thank you for explaining. Regarding the PriceTolerance value, is that value the amount of pips or the amount dollars or something else?

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
×