oanda / v20-java-samples

Some sample applications using the v20 java libraries
14 stars 10 forks source link

Need example of how to lookup prices #1

Open quux00 opened 7 years ago

quux00 commented 7 years ago

I am currently unable to figure out how to lookup prices via the Java API. I am able to do it via curl with

curl \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <KEY>" \
  "https://api-fxpractice.oanda.com/v3/accounts/<ACCOUNT>/pricing?instruments=EUR_USD%2CUSD_CAD"

I am also able to get your Java code examples to work (e.g., I can create an order via the Java API). But you don't have any example of how to look up prices for one or more instruments. My attempt was:

  private void lookupPrices() throws RequestException, ExecuteException {
    // ctx.pricing.get();
    List<InstrumentName> instruments = new ArrayList<>();
    instruments.add(tradeableInstrument);
    PricingGetRequest priceRequest = new PricingGetRequest(accountId, instruments);
    PricingGetResponse pricingGetResponse = ctx.pricing.get(priceRequest);
  }

or

  private void lookupPrices() throws RequestException, ExecuteException {
    // ctx.pricing.get();
    List<String> instruments = new ArrayList<>();
    instruments.add("USD_CAD");
    PricingGetRequest priceRequest = new PricingGetRequest(accountId, instruments);
    PricingGetResponse pricingGetResponse = ctx.pricing.get(priceRequest);
  }

but both attempts fail with:

class com.oanda.v20.RequestException
Exception in thread "main" com.oanda.v20.v20sample.TestFailureException: 400 : null : null
    at com.oanda.v20.v20sample.TestTradesAndOrders.main(TestTradesAndOrders.java:75)
Caused by: 400 : null : null
    at com.oanda.v20.Context.execute(Context.java:191)
    at com.oanda.v20.pricing.PricingContext.get(PricingContext.java:72)
    at com.oanda.v20.v20sample.TestTradesAndOrders.lookupPrices(TestTradesAndOrders.java:92)
    at com.oanda.v20.v20sample.TestTradesAndOrders.runMPTest(TestTradesAndOrders.java:83)
    at com.oanda.v20.v20sample.TestTradesAndOrders.main(TestTradesAndOrders.java:72)

I also tried using versions 3.0.17 and 3.0.18 of the oanda/v20-java library. Same result with both.

Help and examples requested. Thank you.

fxnh commented 7 years ago

I just tried with 3.0.19 and seems to work now but I still would appreciate a example. Not sure about PriceBucket, ClientPrice, Steraming,....

No it only worked for 2 days now I get - with same code - also 400 error back