I can not use an pre-constructed API for my trading.
I am using TDA’s API but would love to switch over to Alpaca and need just a bit of help.
On TDA this is the java code I use to connect.
String sym = “APPL”;
String access_token = CF.appPref.getAccessToken();
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(“https://api.tdameritrade.com/v1/marketdata/quotes?symbol=” + sym)
.addHeader(“Authorization”, String.format(“Bearer %s”, access_token))
.build();
Response response = client.newCall(request).execute();
int code = response.code();
I tried to use something simular for Alpaca but get an error of
cannot connect to server. Any ideas on how I could construct
the proper java code to accomplish this?
final String api_key = “???”;
final String api_secret = “???”;
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(“https://paper-api.alpaca.markets/v2/account”)
.addHeader(“APCA-API-KEY-ID”, api_key)
.addHeader(“APCA-API-SECRET-KEY”, api_secret)
.build();
Response response = client.newCall(request).execute();
int code = response.code();
Any help is appreciated
Thanks in advance.