SaxoBank / openapi-samples-js

Sample code demonstrating OpenAPI interactions in JavaScript

Home Page:https://www.developer.saxo/openapi/learn

Repository from Github https://github.comSaxoBank/openapi-samples-jsRepository from Github https://github.comSaxoBank/openapi-samples-js

SOLVED: Instruments Lookup Failing with 404 in Live Environment (works in Simulation environment)

wislon opened this issue · comments

Describe the bug

OpenAPI 'Instruments Lookup' Failing with 404 in Live Environment (works perfectly in Simulation environment)

To Reproduce

  1. When hitting the SIM endpoint for instrument lookup (using Postman to verify):

https://gateway.saxobank.com/sim/openapi/ref/v1/instruments?$top=5&exchangeId=ASX&keywords=PLL&assetTypes=stock&accountKey={mySimulatorAccountKey}

I get a result:

{
    "Data": [
        {
            "AssetType": "Stock",
            "CurrencyCode": "AUD",
            "Description": "Piedmont Lithium Ltd",
            "ExchangeId": "ASX",
            "GroupId": 12489,
            "Identifier": 7671883,
            "IssuerCountry": "US",
            "SummaryType": "Instrument",
            "Symbol": "PLL:xasx",
            "TradableAs": [
                "Stock"
            ]
        }
    ]
}

X-Correlation: 44df3b1e3519427895b4a4c02aaa5d50#2958#82ee4235-f409-49f3-af65-3d10abee9fc1#82

  1. When I hit the same endpoint in the LIVE environment:

https://gateway.saxobank.com/openapi/ref/v1/instruments?$top=5&exchangeId=ASX&keywords=PLL&assetTypes=stock&accountKey={{myLIVEAccountKey}}

I get an HTTP 404/Not Found Response

X-Correlation: 7b6ffad83f8a4962a7e74477f5dea850#824#addb4598-31af-4455-83c6-6808d2e1b532#352

Please note: I have the correct and valid access tokens used in both. I know they are correct and valid because if I use the wrong ones, or they're expired, I get an expected 401/Unauthorized.

Expected behavior

I expected the LIVE account instrument lookup URL to work as described in your documentation. It doesn't.

Screenshots

Simulator: working:

image

Live: Has the LIVE api endpoint and the LIVE account key and access token, but otherwise identical to the sim one:

image

As you can see, the only difference between those urls is the /sim/ slug and the client account keys

Desktop (please complete the following information):

  • OS - Windows 10 (also fails on mac and linux, it's not my OS causing the problem)
  • Browser: Postman (to verify) but initially found using C# client.

Additional context
I've tried various combinations of adding/removing / at the end, casing of query-string parameters, ordering of query-string parameters. Whatever I do works perfectly in the simulation environment, but the live one fails with a 404 Every. Single. Time.

Please can you update the documentation to reflect the actual URL/endpoint we should be using for the LIVE instrument lookup? Or if it's not available any more, can you indicate it's obsolete/deprecated (and perhaps suggest how else we might go about doing an instrument lookup). Is there a versioning difference? Or, alternatively, fix the LIVE endpoint so it doesn't 404?

Thanks :)

...and just so you know, the balances endpoint is doing exactly the same thing, tested pretty much exactly the same way as the above issue:

/port/v1/balances/?AccountKey={saxoClientKey}&ClientKey={saxoClientKey} works perfectly in the Simulation environment, but 404's in the Live environment.

/port/v1/balances/me works perfectly in both environments, but I can't use that one because it doesn't return the CashAvailableForTrading property in the results JSON. It's literally the only field I was interested in from the abovementioned balances endpoint. There is a CashBalance property, but I have no idea if that's the right one, because it's reporting a value I cannot see ($112) when I log in to the actual SaxoTrader website (which tells me I have $100.67 as my cash balance).

commented

Hi John,

Thanks for bringing this up and good to see you are ready for Live.
On the simulation environment, AccountKey and ClientKey are the same. On Live, they are different.

Looking at your detailed report (thanks for that), it seems you are mixing AccountKey with ClientKey. That results in a 404 Not Found.
Can that be the case?

https://gateway.saxobank.com/openapi/ref/v1/instruments?$top=5&exchangeId=ASX&keywords=PLL&assetTypes=stock&accountKey=**{{myLIVEAccountKey}}**

image

This is the search sample connected to Live:
https://saxobank.github.io/openapi-samples-js/instruments/instrument-search/?env=live

Can you try that, to see if it makes any difference?

Regards,
Bas

Hey @basgroot thanks for getting back to me so quickly!

You are absolutely correct, that is the problem! I can tell you where I went wrong:

In the SIM environment the AccountKey has the same value as the ClientKey when I fetched the user account info, and so I was working with the assumption that they would be the same in the LIVE environment. I have just gone back and checked, and they are of course different from each other in the LIVE account.

I am almost certain that the issue I mentioned in the earlier comment regarding the balances endpoint has exactly the same issue.

Lesson learned 🤦🏻‍♂️ .

Thanks so much for your help! I will close this issue as solved.