Jump to content

Recommended Posts

Hi,

I am relatively new to this GCAPI development.  I read the Trades and Orders section of the REST API documentation and I have several questions:

1 - I see this note "Note: the authentication UserName and Session token are not shown in the example for the purposes of clarity, but they are required in the actual query string."
Well, that's dandy however, can you provide a sample query string that shows the structure and format of these required parameters.  Also, when the above makes reference to the "Query String" is it literally in the Post Request Query String or somewhere in the Post Request Body.  Please clarify.

2 - I am a "U.S." customer (if that matters), I see a couple of parameters in the Post Request Body called "MarkitId" and "MarketName".  Are both of these required or just one of them.  Please clarify this.

3 - If required, is the MarketId stated above a constant value or does it change periodically.

4 - It seems that if one wants to simply submit a market order at the currently available price, that price needs to be specified along with slip tolerance.  This seems odd (this seems like having to specify a stop or limit order at the current price).  How does one simply submit a market order at the current price level.

5 - Further to point 4 above, if the target entry price for a market order is needed, (and one is not using the lightstreamer), would I first then have to obtain recent price data using a "GetLatestPriceTicks" function first.

6 - I am currently developing and testing using a demo account on the live environment.  One of the required POST parameters is a "TradingAccountId".  I was not given one when I was emailed a response to create a demo account ( I was emailed the Username, PW, AppKey).  Given that point 1 above already requires a Username and session token, what and why is a TradingAccountId even needed?  If indeed required, where do I get this information from?

Thanks and Best Regards.

Share this post


Link to post

Hi,

1) The particular note you quoted requires an update in that you can supply the authentication data in the query string OR in the request header. An example of the authentication information in the query string is:

https://ciapi.cityindex.com/TradingApi/order/newtradeorder?Session=xxxxx-xxxx-xxxx-xxxx&Username=xxxxxxx

2) The MarketID is required but MarketName can be optional in a trade / order request.

3)  MarketIDs don't normally change except under exceptional circumstances. 

4) To submit a market order to buy or sell at the current market price use the NewTradeOrder request as described in Trade. That page provides an example request. You don't need to specify the price tolerance in the market order call, the example doesn't show the call using the price tolerance at all.

5) The system is designed assuming that the user has subscribed to live market prices via Lightstreamer so that the current market price can be submitted in the trade request.

6) The TradingAccountID is the unique identifier that ties the account making a particular request such as a trade or order request. You can find the TradingAccountId by making a GetClientAndTradingAccount call.

Kind Regards, PM

Share this post


Link to post

Thank-you for your reply from above.

Submitting Market Orders-

1 - I am looking at the NewTradeOrderRequestDTO -> AuditId parameter and it seems to be associated with a price tick coming through the lightstreamer interface.  Is this parameter really necessary or is there another way to get around this "linked" relationship.  I am not currently using the lightstreamer interface but using another tick data source. In other words, is there ANY way to submit a market order without referencing the "AuditId" or any other data coming through the lightstream price feed.

You mentioned above "The system is designed assuming that the user has subscribed to live market prices via Lightstreamer so that the current market price can be submitted in the trade request."  Is this an assumption or an absolute requirement (in order to get the AuditIDs)?

2 - I am looking at the NewTradeOrderRequestDTO parameter list versus the sample Post Request Body on the Trade page.  In the NewTradeOrderRequestDTO list there is no "TriggerPrice" parameter noted, however in the sample Post Request Body, there is and it is set to NULL.  Can you please clarify this discrepancy.

3 - I have reviewed some lightstreamer information.  That entire infrastructure seems very extensive with many elements, many purposes, moving parts, etc.  If I need to, all I want to do is establish a price feed from your servers.  What is the simplest approach to getting this done and integrating a minimum reference or code base into my project.  For example, do I need just one lightstreamer class object included in my project with a simple instantiation.  If so, can you point me to an abbreviated step by step process for integrating the lighstreamer rate stream object into my project as simply as possible.

4 - Further to point 3 above:
A - Is this what I need and still being used "
Lightstreamer 5.1.2 build 20140722"
B - Which edition do I need (
Allegro/Presto/Vivace or Moderato)
C - Is there sample code anywhere on this forum that shows a lightstreamer inclusion and sample code for receiving rates.

As always, thank-you for your concise answers.

 

 

Share this post


Link to post

Hello,

In answer to your questions.

1) You can submit a market order request without the AudiID parameter. Provided the other parameter values are valid the request will be accepted and filled as usual. It does mean however, we are unable to determine what price your system had received or "seen"  at the time you sent your order request. 

It is assumed you are using our Lightstreamer price feed but not an absolute requirement. 

2) TriggerPrice is a parameter that was deprecated and is no longer used/required. The documentation update missed an occurrence of the paramter in the example block. Thanks for pointing it out.

3) Our servers are using the older Lightstreamer 5. You can download the appropriate Lightstreamer SDK for your programming lanagiage from: https://lightstreamer.com/download/#ls5. Essentially, all you need to use are the Connect method to login and authenticate, and then Subscribe to the appropriate Market ID to receive the live price stream for that market.   

4a) Yes, we are still using LS 5.1.2. 

4b) You don't need to download the LS server software on your end, which are the Allegro/ Vivace... editions you mentioned. It's the Client/Adapter SDKs for your programming language that you need.

4c) There are sample code snippets from users on other threads in this forum when those users had queries related to LS. However, they may not be in the programaming language that you are using. Having said that, the LS documentation link is next to the appropriate SDK download at https://lightstreamer.com/download/#ls5. That should help you get started.

Kind Regards, PM

Share this post


Link to post

Thank-you for your reply from above.

Re: Lightstreamer:
I am a dotnet developer and found what I needed for the LS_Client thing was not even on the Lightstreamer website.  This was driving me nuts as I suppose others are too.  I did a google search and found It was available as a nuget package.  To help other dotnet developers, here is the link to the Lightstreamer.DotNetStandard.Client 4.0.0.
https://www.nuget.org/packages/Lightstreamer.DotNetStandard.Client/

Submitting Market Orders-

I have tried many variations to submit a simple market order and they are all failing with the same results.  Further to your note above, the AuditId is not necessarily required, so I have tried something like the following (which doesn't work)

URL: https://ciapi.cityindex.com/tradingapi/order/newtradeorder?Session=8a000170-adee-462c-bf72-b16b67a65835&Username=username
PostData: 
{
  "MarketID": 401484347,
  "MarketName": "EUR/USD",
  "Direction": "buy",
  "BidPrice": 1.1417,
  "OfferPrice": 1.14183,
  "Quantity": 1.0,
  "TradingAccountId": mytradingaccountID,
  "IsTrade": true,
  "AuditId": null,
  "PriceTolerance": 5,
  "OrderId": 0,
  "Close": 0,
  "PositionMethodId": 1,
  "QuoteId": null,
  "Reference": "GCAPI",
  "OrderReference": null,
  "Source": null,
  "Currency": null,
  "Status": null,
  "OcoOrder": null,
  "Type": null,
  "AutoRollover": false,
  "AllocationProfileId": null,
  "ExpiryDateTimeUTC": null,
  "ExpiryDateTimeUTCDate": null,
  "LastChangedDateTimeUTCDate": null,
  "IfDone": null
}

I always receive the following response:

{
  "Status": 2,
  "StatusReason": 75,
  "OrderId": 0,
  "Orders": [
    {
      "OrderId": 0,
      "StatusReason": 81,
      "Status": 10,
      "OrderTypeId": 1,
      "Price": 0.0,
      "Quantity": 1.0,
      "TriggerPrice": 0.0,
      "CommissionCharge": 0.0,
      "IfDone": [],
      "GuaranteedPremium": 0.0,
      "OCO": null,
      "AssociatedOrders": {
        "Stop": null,
        "Limit": null
      },
      "Associated": false
    }
  ],
  "Quote": null,
  "Actions": [],
  "ErrorMessage": null
}

*** I notice when I pull back data from a GetAccountDetails call, among all the other things, I get
"TradingAccountType": "CFD" ***  This is supposed to be a standard FX account.  Is this a potential problem?

Can you please advise me what my issue is from above?

As always, thank-you for your concise answers.

 

 

Share this post


Link to post

Hi,

Thank you for adding the link to the DotNet client on Nuget - I'm sure other DotNet users will appreicate it. :)

The response OrderStatusreasonCode of 81 indicates insufficient funds in your account. Are you using a demo/test account or your Live account? Demo/Test accounts should have at least 10,000 of "play" money to enable testing. 

You can find the API lookup codes on the following page for future reference: http://docs.labs.cityindex.com/#APICodesList.htm%3FTocPath%3DGetting%20Started|Lookup%20Values|_____1

Kind Regards, PM 

Share this post


Link to post

Thank-you for your reply from above.

Yes, I am, aware of the Status codes and reviewed the status codes for the above response.  So, when I see "Insufficient funds", I am having a hard time believing that to be the case.  Perhaps my understanding of Quantity = "1.0" isn't what I think it is.  Can you direct me to further information on what this Quantity specifier represents.  i.e. am I specifying 1.0 full lots or just 1 unit?  For test purposes, I am just trying to specify 1 dollar per pip or even 10 cents per pip.

It is a demo account with 50k USD in it.  Moreover, in the example above, I am only specifying 1 unit to buy.

Please clarify this for me.  As always, thank-you for your concise answers.

EDIT: I was using a quantity of "1.0".  I changed the Quantity to 1000 and it finally works.  I think some documentation on this issue is needed as the examples on your Trade area indicate that a Quantity of 1.0 is used for the example and it apparently (should) work.  Again, could you  please clarify the usage of the Quantity parameter.

 

 

Edited by OldWiseAndExperienced
Updated information

Share this post


Link to post

Hi,

I was about to reply with the same as you have already found out.

All our spot Forex markets use actual dollar amounts as quantities. For example, 100,000 is what is entered to trade 1 lot, 10,000 for a mini-lot, and 1000 is a micro-lot. 

Additionally, I have to apologise for you being sent on a wild goose chase. The API dev team updated the OrderStatusReason codes but forget to inform me. Code 81 now represents: Position below Web Min Size, which would have enabled us to solve the issue immediately. 

I've made a note to have the lookup codes in the API documentation updated ASAP to prevent this confusion going forwards.

Kind Regards, PM

Share this post


Link to post

Thank-you for your reply from above.

Documentation / Housekeeping Issue:
1 - The documentation for the parameters in the NewTradeOrderRequestDTO in the Trade section, versus the examples provided on the Trade page / POST Request Body do not agree.  The POST Body examples include some fields and values not specified in the NewTradeOrderRequestDTO and vice versa.  This is very disorienting and requires some trial and error to stumble across a minimum set of parameters that seem to successfully initiate a market order.  It's also hard to know which (correct) parameters are required and which ones are optional, further, if optional are they supposed to be preset to some value or set to NULL.  (Just sayin).  BTW - I did manage to craft up a working market order request, but heck, extra clarity and granularity in the online documentation would be great.

2 - It's nice that you provide a "Print" button on the top left of the documentation pages.  It's handy to print some things for note-taking.  However, I spotted an issue with this when I chose to print http://docs.labs.cityindex.com/index.html#Data Types/NewTradeOrderRequestDTO.htm , it printed the pages nicely but entirely missed printing the lines associated with the IfDone paramater.  Hmmm, FYI.

Closing a previously opened Market Order-
3 - I have tried to close a previously opened Market Order using the following directions provided in the Trade section
"Place a trade to close an open position. In this case, set the Close property with the Order ID of the opening trade."

However, it seems additional parameters are also needed to close the trade.  Through permutation testing, it seems you need as a minimum, BID,ASK, Direction, PriceTolerance, MarketID, Quantity, OrderID, PositionMethodID, TradingAccountID.  Please provide confirmation of this or added thoughts.

A - At the moment one wants to close an existing trade, does the BID/ASK parameter need to match the original BID/ASK when the Market Order was originally submitted or the currently known BID/ASK.

B - PriceTolerance seems to have role in the above.  I observed in one of the forum posts that PriceTolerance was (stated as) not supported/needed or something to that effect.  Can you please specify if it is absolutely required in the MarketOrder request AND/OR in the MarketOrder->CloseTrade action.  It appears to be needed at a very minimum in the MarketOrder->CloseTrade action.

4 - Specifying a TP and SL for the Market Order (when submitted together with the original Market Order) - 
When closing a trade with a previously established TP+SL, are those 2 orders automatically cancelled along with the closure of the original Market Order?

5 - Let's say 2 identical Buy MarketOrders on same Market had been submitted for 1000 units each.  What would be the procedure to "CloseAllPositions", ie those 2 MarketOrders?  There seems to be some "amalgamating" going on...
 

 

Edited by OldWiseAndExperienced
Added 1 more question

Share this post


Link to post

Hello,

1) Many thanks for providing constructive feedback on the API documentation. We can use this information to improve the documentation in the next update pass. We very much appreciate your taking the time to send it to us!

2) After some experimentation, the NewTradeOrderRequestDTO header on page 2 of the print out is obscuring the If/Done parameter table row. After investigting the software used to generate the API documentation, it appears to be an issue on that end. I've raised a support ticket with the developer of the software, but since it is a 3rd party I don't have a time frame as to when or even if they will release a fix for this. 

When or if a fix is ever released, we will of course rebuild the API documentation with the fix. That way, they can be printed without having some information obscured by the title when printouts run across more than 1 page.

3) This is another area where the documentation can be made more clear. When placing a trade to close an open position, the user must POST the usual place trade parameter information required for a Trade request and additionally, include the Close property with the Order ID of the opening trade. The user should not POST a trade request with just the Close property information only. We'll make this more clear in the Trade page of the API documentation.

3A) Enter the current Bid/Ask in the closing Trade request. You are still making a trade request so the call must be valid for the time it is being made. 

3B) PriceTolerance is an optional parameter - you can choose to supply a value to override the default value of 2, or leave it out of the call and the system will use the default. I just tested and was able to send a close Trade request successfully WITHOUT the Price Tolerance parameter supplied. 

4) Yes, attached closing orders to a position are automatically cancelled when the position is closed.

5) To close all open positions in a market (Close All Positions), wrap the OrderIDs for both positions in square brackets within the Close property, as it is an integer array.  

Kind Regards, PM

 

Share this post


Link to post

Thank-you for your reply from above.

Closing Trades - 

1 - I created 3 identical MarketOrders and successfully submitted them.  I also saw all 3 in the ForexCom trading platform.  I noted the OrderID's in the trading platform were the same ones as indicated in the 3 seperate ApiTradeOrderResponseDTO  responses (which one would expect).  So, I then constructed a TradeRequest->CloseOrder specifying the first 2 OrderID's from above and sent them as an array of 2 integers.  I see that the request was properly formed.  The resulting action was that the second order that was created above got closed, but the first order created above did not.  In the Close() array, I sent the first order number, second order number (in that order).

Note: I have managed to create and test a TradeRequest->CloseOrder that seems to work reliably when just one market order is placed and then subsequently closed.

A - Is there a Quantity issue here in the TradeRequest->OrderClose procedure. (ie do I need to add up all the previous Quantities for the orders, or is the Quantity parameter disregarded in this context)?
B - Is there some potential FIFO issue here.  Do I need to specify the order of the OrderID's in a certain manner so some back end FIFO rules are met?
C - If neither the above A/B are issues, what could potentially cause the issue noted above in 1?

Share this post


Link to post

Hi, 

You are correct in A), the total quantity must be specified.

Example: if your position 1 and position 2 were for 1000 each, then the closing trade request quantity should be 2000. Please keep us updated if that  resolves the problem you are currently seeing.

Kind Regards, PM

Share this post


Link to post

I read through this thread and got a lot of useful info. So, with demo account I'm making NewTradeOrder Api call to close an open position. In the request body I am giving OfferPrice and BidPrice both the same value = Mid Price. And my trade request is successful. Is it correct to do so?  Honestly speaking, I'm finding using LS with Python hard to use so currently not reading prices from Lightstreamer. I'm using GetPriceTicks's latest MID price tick as the current price.

Share this post


Link to post

Hi,

You should supply the actual Bid and Offer prices in the OfferPrice and BidPrice fields to avoid anything going wrong. 

If you are having trouble using Python to connect with LightStreamer, you could try posting your specific queries in the Lightstreamer forums at: https://forums.lightstreamer.com/. They have a helpful blog post based on using Python to connect with LightStreamer at: http://blog.lightstreamer.com/2015/01/a-python-client-example-for_14.html that you can use as a starting point.  

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
×