简体   繁体   中英

How to get the price history of forex in TDAmeritrade API such as EUR/USD?

I use the TD Ameritrade API as documented on the API documentation .

The URL to get the price history contains the symbol of the asset to fetch.

在此处输入图像描述

The documentation says:

Replace the {symbol} in the URL with the actual symbol

It works well with stock symbols like GOOG or AAPL or FB.

For example for AAPL, the url would be: https://api.tdameritrade.com/vi/marketdata/AAPL/pricehistory

But with symbols that contain a backslash like the EUR/USD spot, it does not work because the backslash is considered as an additional path to the URL So I get URL not found withhttps://api.tdameritrade.com/vi/marketdata/EUR/USD/pricehistory

Same with EUR/CAD , EUR/GBP , and other forex spots. How to fetch forex spot?

Use a dot instead of the slash between the currencies. So this will work:https://api.tdameritrade.com/v1/marketdata/EUR.USD/pricehistory

Yeah, the docs are rubbish about it and even the symbol lookup returns the slash as part of the symbol eg. GBP/USD as a valid symbol:

{
  "GBP/USD": {
    "symbol": "GBP/USD",
    "description": "GBPound/US Dollar Spot",
    "exchange": "GFT",
    "assetType": "FOREX"
  }
}

for other broker (X Trade Brokers) you can request EURUSD price history in NodeJS https://github.com/peterszombati/xapi-node#get-eurusd-m1-price-history

request price history with this module is simple like this code

x.onReady(() => {
    x.getPriceHistory({
        symbol:'EURUSD',
        period: PERIOD_FIELD.PERIOD_M1
    }).then(({candles, digits}) => {
        console.log(candles.length);
        console.log(candles[0]);
        console.log('digits = ' + digits);
    })
});

Only Stocks , Options and Index prices are available from the pricehistory endpoint. I received an email from one of TD Ameritrades product managers confirming as much:

Hello Tobiah,

Thank you for the email and I apologize for the delay in response.

Forex data is only available via the Get Quote endpoint . Here is an example of a request for multiple forex symbols at once for an in the moment snapshot quote: https://api.tdameritrade.com/v1/marketdata/quotes?apikey=YING4&symbol=EUR%2FUSD%2CUSD%2FJPY

Get Price History is only available for stocks, options, and Index currently. Futures and Forex instruments would not be available through that endpoint.

Kind regards,

Michael Ying Product Manager, Trader TD Ameritrade 600 W Chicago Ave, Chicago, IL 60654

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM