Skip to content

Navigation Menu

Sign in
Sign up

Ysing the functions of the Forex Api using the Broker Api #157

Answered by Petersoj
Seyrelf asked this question in Q&A
Discussion options

Hello, please tell me, can I get data on currency pairs using my Broker Api or do I necessarily need to create a Trader Api for this?
I'm trying to get data for the next pair, but I get an exception when checking response.isSuccessful(). Could the reason for the exception be the use of the Broker Api?

 final BrokerAPIEndpointType endpointType = BrokerAPIEndpointType.SANDBOX; // or 'PRODUCTION'
 final AlpacaAPI alpacaAPI = new AlpacaAPI(brokerAPIKey, brokerAPISecret, endpointType);
 
 final ApiClient api = new ApiClient(alpacaAPI.getOkHttpClient());
 ForexApi forexApi = new ForexApi(api);
 forexApi.latestRates("USDJPY,USDMXN");

excep

You must be logged in to vote

A few things:

  • Don't construct your own instance of ApiClient otherwise the Alpaca authorization headers won't be present in requests. All API requests should be made through method calls in the AlpacaAPI instance and its endpoint methods (e.g. api.trader().accountActivities()...).
  • The Broker API doesn't have access to the market data endpoints that regular Alpaca users have. You can't use market data endpoints with Broker API keys or with the Connect API unless you have some sort of special agreement set in place with Alpaca.
  • The Broker API should be used if you're trying to use Alpaca as a white-label brokerage. If that's the case, you should reach out to their sales staff to discuss pr...

Replies: 1 comment 1 reply

Comment options

A few things:

  • Don't construct your own instance of ApiClient otherwise the Alpaca authorization headers won't be present in requests. All API requests should be made through method calls in the AlpacaAPI instance and its endpoint methods (e.g. api.trader().accountActivities()...).
  • The Broker API doesn't have access to the market data endpoints that regular Alpaca users have. You can't use market data endpoints with Broker API keys or with the Connect API unless you have some sort of special agreement set in place with Alpaca.
  • The Broker API should be used if you're trying to use Alpaca as a white-label brokerage. If that's the case, you should reach out to their sales staff to discuss pricing and such before integrating the Broker API into your business/application. You may want to look into the Connect API (OAuth) instead.
  • If you want to use Forex data on behalf of your own Alpaca account, your code should look something like this:
    final AlpacaAPI alpacaAPI = new AlpacaAPI("<id>", "<secret>", TraderAPIEndpointType.LIVE, MarketDataWebsocketSourceType.IEX);
    alpacaAPI.marketData().forex().latestRates("EURUSD");
    
You must be logged in to vote
1 reply
Comment options

Thank you very much, you helped me a lot

Answer selected by Petersoj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /