Jump to content
socalwill

Required parameters for Trade & format for currency pair names

Recommended Posts

Hi there, 

 

two quick questions about the required parameters for Trade. I tried to follow the instructions, but for some reason I keep getting a 401 unauthorized message

 

 

 

< HTTP/1.1 401 Unauthorized
< Date: Thu, 22 Oct 2015 04:06:25 GMT
< Server: PWS/8.1.20.22
< X-Px: nc h0-s1048.p7-lax ( h0-s1016.p12-sjc), nc h0-s1016.p12-sjc ( h0-s43.p6-lhr), nc h0-s43.p6-lhr ( origin)
< Cache-Control: no-cache
< Pragma: no-cache
< Expires: -1
< Content-Length: 73
< Content-Type: application/json; charset=utf-8
< X-AspNet-Version: 4.0.30319
< X-Powered-By: ASP.NET
< Connection: keep-alive
* Connection #0 to host ciapi.cityindex.com left intact
{"HttpStatus":401,"ErrorMessage":"Session is not valid","ErrorCode":4011}
 

 

 

 

 

when I try the following command that contains a valid Session Id as well as a valid Audit ID from the last tick I received:

curl -v "https://ciapi.cityindex.com/tradingapi/order/newtradeorder" -H 'Content-Type: application/json; charset=UTF-8' -d "{"IfDone":null,"Direction":"sell","ExpiryDateTimeUTCDate":null,"LastChangedDateTimeUTCDate":null,"OcoOrder":null,"Type":null,"ExpiryDateTimeUTC":null,"Applicability":null,"TriggerPrice":null,"BidPrice":1.13478,"AuditId":"GTX4213572_1","AutoRollover":false,"MarketId":154290,"OfferPrice":1.13490,"OrderId":0,"Currency":null,"Quantity":1,"QuoteId":null,"LastChangedDateTimeUTC":null,"PositionMethodId":1,"TradingAccountId":mytradinacct,"MarketName":"EUR USD","Status":null,"isTrade":true,"UserName":"myusername","Session":"mysessionid"}" -X POST

Several possibilities come to mind:

 

Is the format for EUR/USD correct or should I use EUR/USD? I tried both but neither worked. I read somewhere in the documentation that one has to use EUR USD when searching for the MarketId, so I am not sure.

 

Some of the other parameters could be wrong.

 

It could also be a slight idiosyncrasy with the way the POST command has to be used as a zero length request (we saw that for logging out).

 

So I am wondering if you could maybe provide server messages for a command that works for you and I will compare. I would be happy to sent credentials via pm should that facilitate the process.

 

Of course there is also the possibility that I am missing something very obvious :)

 

Thanks!

 

 

Share this post


Link to post

Hello Will,

 

When searching by name, then yes the "/" should be omitted. For example search for "EUR USD" rather than "EUR/USD".

 

However, when placing a trade you should use the market name exactly as it is. The market ID you are using is for the EUR/USD CFD market rather than the spot FX market. If you want the spot FX "EUR/USD" market, its ID is: 401091573.

 

If you want to continue using the EUR/USD CFD market, its full name is: "EUR/USD (per 0.0001)".

 

The authentication username and session ID should be in the query string and not in the trade request body. E.g.

https://ciapi.cityindex.com/TradingAPI/order/newtradeorder?UserName=dmXXX&Session=XXX'

The body will then be (parameter orders are different than yours but it will work in whatever order)

{"Type":null,"Applicability":null,"ExpiryDateTimeUTC":null,"OcoOrder":null,"Direction":"sell","isTrade":true,"TriggerPrice":null,"AuditId":"GTX5753178_3","Currency":null,"MarketName":"EUR/USD (per 0.0001) CFD","BidPrice":1.13126,"ExpiryDateTimeUTCDate":null,"PositionMethodId":1,"LastChangedDateTimeUTCDate":null,"AutoRollover":false,"Status":null,"MarketId":154290,"OfferPrice":1.13136,"LastChangedDateTimeUTC":null,"OrderId":0,"Quantity":1,"QuoteId":null,"IfDone":[],"TradingAccountId":XXX}

Kind Regards,

PM!

Share this post


Link to post

Hello there,

 

Thanks much, for some reason I was missing that the marketid I was using was not for Spot FX.

 

Now I am getting an error code 500, internal server error.

 

 

Two questions:

 

1. I noticed that , for the marketid 401091573 that you sent me, the market information I get with GetMarketInformation includes some information about the specific exchange:

 

"ExchangeId":400000057,"ExchangeName":"FX (GTS) FL MT4 Exchange"

 

Would that be the one I want to use here?

 

2. For the quantity, do I need to put in the number of lots (where the actual actual amount traded would depend on the specific lot size I am signed up with) or the actual amount traded?

 

Thanks so much!

Share this post


Link to post

Hi,

 

Answers to your questions below.

 

1) Yes, this is the spot FX market - the exchange code looks like an internal term to fill in the field since spot FX is not traded on a public exchange as such. 

 

2) For spot FX markets when entering trade sizes you enter the amount traded. For example: to trade 1 lot it would be 100,000, a mini-lot is 10,000 and a micro-lot is 1,000. 

 

Not sure what would cause the error apart from I used a trade size of 1 in my previous example! Ooops - sorry! Hopefully, if you enter correct trade sizes it will work.  :)

 

Kind Regards,

PM!

Share this post


Link to post

Hi there again,

 

I looks like I am still getting the internal server error message. Before we dig deeper and analyze the server log ,we could maybe try the following:

 

Could you place a trade, say buy or sell 10000 or 100000 EUR/USD spot and then post the body of the request that went through similarly to what you did above for EUR/USD CFD? That way I could make sure I am using parameters that should work.

 

Thanks!

Share this post


Link to post

Sure no problem.

 

I used our AT Pro trading platform to place a trade (successfully) and used Fiddler to capture the request header and body in the trade request. I shall send you a PM with the images attached when I finish this post.

 

I noticed that there is an additional field in the request body ("Reference") that isn't captured in the API documentation. I've looked in the source code for trade requests and I see that the development team have added some fields in and forgot to update the documentation. I've made a note to update the documentation. 

 

The Reference field is just a string used to identify the source of the trade request and is used internally only. Should you want to add this field to your request I suggest you use a value of: "CIAPI" to identify the request as an API call.

 

Kind Regards,

PM!

Share this post


Link to post

Success: I noticed that the example given in the documentation for Trade doesn't seem to be quite consistent with the list of parameters in http://docs.labs.cityindex.com/#Data Types/NewTradeOrderRequestDTO.htm as the latter contains fewer parameters. So I went ahead and just took the ones listed in NewTradeOrderRequestDTO (actually, I left out the last two there) and is works!

 

 

So there is no need to do what I suggested in the previous message.

 

Cheers!

 

William

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
×