Skip to content

Need example of how to lookup prices #1

@quux00

Description

@quux00

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions