Jump to content
tscreators

TradingAPI/order/newtradetorder giving 404 page not found .

Recommended Posts

    i am using this url its giving 404 error .

var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://ciapi.cityindex.com/TradingAPI/order/newtradetorder");
            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method = "POST";
            httpWebRequest.Headers.Add("UserName", "DM943054");
            httpWebRequest.Headers.Add("Session", ConfigurationManager.AppSettings["sessionID"].ToString());

Share this post


Link to post

Hi,

When logging into the REST part of the API, or when sending account credentials to the REST API with any call - you use the account password. The call you are trying to make is to the REST API so will required your actual account password and not the SessionID.

It is only when logging into Lighstreamer, that the SessionID is used as the password. 

Kind Regards, PM!

Share this post


Link to post

hi ,

i am getting same error after using my actual password  . let me know if username password wrong then it will show page not found 404  ?  . as i know 404 mean url not located .

thanks

regards

tscreators

Share this post


Link to post

Hi,

I just spotted the problem - it's a pesky typo. In your pasted code you have: 

(HttpWebRequest)WebRequest.Create("https://ciapi.cityindex.com/TradingAPI/order/newtradetorder");

newtradeorder has an extra "t" after trade and before order. Deleting the extra "t" should resolve the problem.

Kind Regards, PM!

Share this post


Link to post

Hi,

A 401 HTTP status code usually indicates that the session token has expired. Please send a call to /session to "logon" to the API and read the new session token from the response. You can then use the new session token in your order call.

Kind Regards, PM!

Share this post


Link to post

hi ,

still showing same issue . 

when i use this url with get its working fine

https://ciapi.cityindex.com/TradingAPI/useraccount/ClientAndTradingAccount?UserName=DM943054&session=" + session

while i am using this url with post its showing 401 unauthorized


https://ciapi.cityindex.com/tradingapi/order/newtradeorder?UserName=DM943054&session=" + session

even i check with postman its showing error kindly check it on your end . its working or not .

regards

tscreators

Share this post


Link to post

Hi,

I used Postman to successfully place a trade using /newtradeorder. Details below.

Request Headers

image.png

 

Request Body

image.png

 

Response Body

image.png

 

Finally, I checked on our web platform for this account and can see the open position that was just placed using the API call via Postman as detailed above.

image.png

 

Share this post


Link to post

Hi, 

Streaming data changing so quickly due to this when i am giving order its not working.  Is there any parameter which i will use to select order on current bid if its not matched to my selected value 

Share this post


Link to post

Hi,

There is a PriceTolerance parameter in the NewTradeOrderRequestDTO that you send in the trade request. The parameter controls the amount of slippage you are willing to accept to successfully execute a trade. 

If you have code that automatically reads in the prices and then sends a trade request automatically, it should usually send it in time to have a valid price from the incoming stream. Obviously, this depends upon the market and how busy it is at that moment in time. 

Kind Regards, PM!

Share this post


Link to post

Hi,

Thank you for sending the screenshot - it helps greatly. 

The returned OrderStatusReasonCode of 10 is bizarre since that indicates the market is closed! However, you are trying to trade the spot USD/JPY market which is open 24hours during weekdays. The API lookup codes are documented at API Lookup Codes.

Using my account I've successfully placed a trade in that market. To help with troubleshooting:

1) Please send the entirety of your trade request body so I can see and check each of the properties and values you are using in your trade request. For example, the pasted image below is the trade request body I used to successfully place a trade in the USD/JPY spot market.

2) Send my by private message the credentials for your demo account that you are using. I want to use that account and see if I can place the trade again in that market and see what happens.

Kind Regards, PM!

image.png

Share this post


Link to post

hi there ,

i am using this json mention below

{
   "IfDone":null,
   "Direction":"buy",
   "ExpiryDateTimeUTCDate":null,
   "LastChangedDateTimeUTCDate":null,
   "OcoOrder":null,
   "Type":null,
   "TriggerPrice":null,
   "BidPrice":1.31728,
   "MarketId":401449254,
   "OfferPrice":1.31741,
   "OrderId":0,
   "Currency":null,
   "Quantity":1000,
   "LastChangedDateTimeUTC":null,
   "PositionMethodId":1,
   "TradingAccountId":401384419,
   "MarketName":"USD/JPY",
   "Status":null
}
 
regards
tscreators

Share this post


Link to post

Hi,

I found the error. Your bid and offer prices are not the current bid/offer prices for the USD/JPY market. It appears you have entered the prices for GBP/USD or some other market. I've successfully placed a trade using your account credentials and the entirety of the JSON you posted above, changing just the bid/offer prices to the current bid/offer (at the time of writing) for USD/JPY.

You can see the trade open and close in your account history now. 

Normally, you want to subscribe to the live streaming prices for the markets you are looking to trade (via Lightstreamer), read in the current bid/offer prices and use those values in the BidPrice and OfferPrice fields of your trade request. 


   "IfDone":null,
   "Direction":"buy",
   "ExpiryDateTimeUTCDate":null,
   "LastChangedDateTimeUTCDate":null,
   "OcoOrder":null,
   "Type":null,
   "TriggerPrice":null,
   "BidPrice":110.09,
   "MarketId":401449254,
   "OfferPrice":110.10,
   "OrderId":0,
   "Currency":null,
   "Quantity":1000,
   "LastChangedDateTimeUTC":null,
   "PositionMethodId":1,
   "TradingAccountId":401384419,
   "MarketName":"USD/JPY",
   "Status":null
}

Kind Regards, PM

 

Share this post


Link to post

Hi,

When i take a position manually and "Hedge" is set to yes as default on the demo, I can go long and short at the same time.

However when i take a position via the API it does not hedge so I can not go long and short and the same time. Even though the default setting on the account is set to yes.

I cannot see a field when taking a position for this.

Please can you advise where I need to change to ensure this will Hedge as per the account manually.

Thanks

Share this post


Link to post

Hello,

In your trade or order request, set the property PositionMethodId == 2. This enables hedge mode so that you can have simultaneous open long and short positions in the same market.

The default value of this property is 1, which is non-hedge mode allowing only long OR short positions in a market at one time. 

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
×