简体   繁体   English

如何在 TDAmeritrade API 中获取 EUR/USD 等外汇价格历史?

[英]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 .我使用 API 文档中记录的 TD Ameritrade API。

The URL to get the price history contains the symbol of the asset to fetch.获取价格历史记录的 URL 包含要获取的资产的符号。

在此处输入图像描述

The documentation says:文档说:

Replace the {symbol} in the URL with the actual symbol将 URL 中的{symbol}替换为实际符号

It works well with stock symbols like GOOG or AAPL or FB.它适用于 GOOG、AAPL 或 FB 等股票代码。

For example for AAPL, the url would be: https://api.tdameritrade.com/vi/marketdata/AAPL/pricehistory例如,对于 AAPL,url 将是: 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 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 /欧元/美元/价格历史

Same with EUR/CAD , EUR/GBP , and other forex spots.EUR/CADEUR/GBP和其他外汇现货相同。 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所以这将起作用: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 作为有效交易品种:

{
  "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对于其他经纪人(X Trade Brokers),您可以在NodeJS https://github.com/peterszombati/xapi-node#get-eurusd-m1-price-history中请求 EURUSD 价格历史

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. pricehistory端点仅提供股票期权指数价格 I received an email from one of TD Ameritrades product managers confirming as much:我收到了来自 TD Ameritrades 产品经理之一的 email 确认:

Hello Tobiah,你好托比亚,

Thank you for the email and I apologize for the delay in response.感谢您提供 email,对于延迟回复我深表歉意。

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以下是同时请求多个外汇交易品种以获取即时报价的示例: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 Michael Ying 产品经理,Trader TD Ameritrade 600 W Chicago Ave, Chicago, IL 60654

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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