Jump to content
Sign in to follow this  
Eric

How to Cancel/ View/ Close Simulated Trades

Recommended Posts

I was able to place a market order, but now I want to figure out how to close/ view/ cancel that open position. I tried:

r = requests.post('https://ciapi.cityindex.com/TradingAPI/order/simulate/updatetradeorder?'+SESSION_BUNDLE, json = bodyUpdate)

where the bodyUpdate = {"OrderId": 0, "TradingAccountId": TRADING_ACCOUNT_ID , "CloseByOrderId":null}    # trading account id worked for placing an order

I know the SESSION_BUNDLE and TRADING_ACCOUNT_ID work, but I'm receiving a Reponse [500] for both this operation and a similar looking cancel order call.

Where am I going wrong/ how do I delve into fixing the problem.

 

Also, I'm having trouble with making an actual market order, even though everything is the same as the simulated market order (except the /simulated in the url is gone). Is there anything else I need to do for actual market order over simulated market order? I'm getting a 75 (red card) and an 81 (missing quote). I don't know what a quote is but I think it's the key.

Thanks, Eric

Share this post


Link to post

Hi Eric,

Going through the 2 things you want to do once you have an open position.

1) View open position. You can use the ListOpenPositions call to see all your open positions. 

2) Close open position. You should still use the same /newtradeorder call, but to close the position you set the Close property with the Order ID of the opening trade. The UpdateTrade call you are using is used to modify an open position, such as attaching new closing stop loss / take profit limit orders to the open position, or for amending details of already attached closing orders.

Kind Regards, PM

 

Share this post


Link to post

Hi Eric,

It just occurred to me a quick way to figure out how to use the API is to observe the API calls/responses when using our Web Trading platform. All our trading platforms use the API so they will use the same calls you will be using to perform each trading action

Please use a demo/test account when placing trades / orders so no real money is lost.

For example, login to the Web Trader platform and open the browser developer console. You can then perform the trading operations such as placing a trade, closing an open position, adding orders etc. and observe the API calls / response the platform sends / receives. 

That way, you can figure out what API call to use in order to perform each trading operation. 

Kind Regards, PM

Share this post


Link to post

Hi PM,

I was able to open a position on my demo account [not simulated], but unable to close it. We closed it manually (with the source opened) but were unable to see the API call you were referring to. In the console it outputted {"Successful":true}. Where can we find the API calls you were referring to?

Thanks, Eric  

(Edited: because I figured part of it out)

 

Share this post


Link to post

Hi Eric,

Assuming you are using the Chrome browser with the DevTools open at the same time as the Web Trader platform.

It is the Network tab of the DevTools you need to look at. When you close the trade on the platform, you can see the API traffic sent by the platform. Hover the mouse pointer over the call to see the endpoint the call was sent to, and click on the call to open up the panel on the right showing the payload. 

Kind Regards, PM

image.png

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  
×