studerw / td-ameritrade-client

TD Ameritrade Java Client
Apache License 2.0
69 stars 47 forks source link

Non 200 response #9

Closed Naved81 closed 4 years ago

Naved81 commented 4 years ago

Hi there,

I got the response through https://api.tdameritrade.com/v1/oauth2/token successfully. I then copied the refresh token and client id (from app I created) into the properties as follows:

    Properties props = new Properties();
    props.setProperty("tda.client_id", "blah blah with @AMER.OAUTHAP at the end");
    props.setProperty("tda.token.refresh", "really long string");
    TdaClient tdaClient = new HttpTdaClient(props);

I keep getting this error for all API calls:

Exception in thread "main" java.lang.RuntimeException: Non 200 response: [404 - /v1/marketdata/FB/pricehistory] - https://apis.tdameritrade.com/v1/marketdata/FB/pricehistory at com.studerw.tda.client.HttpTdaClient.checkResponse(HttpTdaClient.java:622) at com.studerw.tda.client.HttpTdaClient.priceHistory(HttpTdaClient.java:165) at com.tdameritrade.PlayGround.play1(PlayGround.java:54) at com.tdameritrade.PlayGround.main(PlayGround.java:22)

Any ideas?

Thanks.

Denebulas commented 4 years ago

It's exactly the same issue I opened 10 hours before you...

studerw commented 4 years ago

I'm looking at this right now...

studerw commented 4 years ago

I think your problem is the '@AMER.OAUTHAP' at the end of your client_id. Do NOT include that part. I only am using the client ID with is 32 alphanumeric digits (uppercase) long. Take out the @AMER.OAUTHAP and see if it works.

Naved81 commented 4 years ago

I tried that already, same error message.

studerw commented 4 years ago

This worked for me. It's a Junit test, but you can just run a main method instead using public static void main...

package com.studerw.tda.demo;

import java.util.Properties;

import com.studerw.tda.client.HttpTdaClient;
import com.studerw.tda.client.TdaClient;
import com.studerw.tda.model.history.PriceHistory;
import org.junit.Test;

public class PriceHistoryTest  {

    @Test
    public void testPriceHistory() {
        Properties props = new Properties();
        props.setProperty("tda.client_id", "D....19N"); //NO @AMER... junk here
        props.setProperty("tda.token.refresh", "<ESCAPED_REFRESH_TOKEN>");

        TdaClient tdaClient = new HttpTdaClient(props);

        final PriceHistory priceHistory = tdaClient.priceHistory("FB");
        priceHistory.getCandles().stream().forEach(candle -> 
                System.out.println(candle.toString()));
    }
}
studerw commented 4 years ago

That worked for me. Can you try an easier test and just do something like:

    Properties props = new Properties();
    props.setProperty("tda.client_id", "D....19N"); //NO @AMER... junk here
    props.setProperty("tda.token.refresh", "<ESCAPED_REFRESH_TOKEN>");

    TdaClient client = new HttpTdaClient(props);
    List<SecuritiesAccount> accounts = client.getAccounts(true, true);
    accounts.forEach(account -> System.out.println(account.toString()));

It's possible you don't have the access to price history calls depending on your account level at TDA.

Naved81 commented 4 years ago

I created a fresh new repo in my IDE and did a git clone instead of just downloading the source and required libraries via pom.xml. Then I built a jar for the entire project and added that to the classpath of my project.

Did the trick.

Thanks for the code!