Jump to content

Recommended Posts

I'm looking at your online reference page ListTradeHistory.  When I send a request to /tradehistory I get an array of trades.  Each trade contains the string


Note that there are no characters between the colon and the comma. There seems to be some disagreement as to whether this is valid Json format.  The Visual Studio Json Visualizer will display

                                                      ManagedTrades: undefined

but the module System.Text.Json.dll which is also a Microsoft product, throws an exception

                                                      System.Text.Json.JsonException: '',' is an invalid start of a value. 

I am not a Json expert.  My work around is to have my code insert [], to indicate an empty array, in the string between the colon and the comma before calling Json functions.  Maybe your developers could do the same?  Or is this in fact valid Json and I'm just going to have to live with it?

Addition:  I'm having a similar issue with the results from ListTradeHistory.  According to ApiTradeHistoryDTO,  http://docs.labs.gaincapital.com/Content/Data Types/ApiTradeHistoryDTO.htm the field OpeningOrderIds is an integer array.  But the return I get contains no square brackets, i.e. it is just an integer.  This works fine if the position being closed was entered in a single order.  But if the position is opened with BUY 1000 GBP/USD, BUY 2000 GBP/USD, BUY 3000 GBP/USD, and closed with SELL 6000 GBP/USD, the result is "OpeningOrderIds":order1,order2,order4, which causes my JSON parser to fail, instead of what I was expecting...  "OpeningOrderIds":[order1,order2,order4],  Again, I have a workaround to insert square brackets into the response string prior to JSON processing.

Share this post

Link to post

Hi Chuck,

Much obliged for the notes regarding JSON and the ListTradeHistory call. I'm passing it to the API development team and will reply with any responses from them. 

Kind Regards, PM

Share this post

Link to post

Hi Chuck,

The team were not able to reproduce what you mentioned,  a snippet of a trade history response from a test call appears to us as below:

            "OrderId": 724807954,
            "OpeningOrderIds": [
            "MarketId": 401166447,
            "MarketName": "EUR/USD",
            "LastChangedDateTimeUtc": "/Date(1585341486553)/",
            "ExecutedDateTimeUtc": "/Date(1585341486553)/",
            "TradeReference": null,
            "ManagedTrades": [],
            "OrderReference": null,
            "Source": "G2",
            "IsCloseBy": false,
            "Liquidation": false


Please send us (via a private message) your user name, precise call parameters and if possible, the raw JSON? We can check further then to see what is happening.

Many thanks PM. 

Share this post

Link to post

I apologize for my not being more thorough in my debugging.  I thought that I was looking at the raw response, but in fact I was looking at a string which had been corrupted by my own code.  Thank you for taking the time to look into this.

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