Search code examples
javaetrade-api

how to get OptionQuote with ETrade API


I'm trying to get an option quote from Etrade using their Java SDK. I'm currently setup for using the sandbox.

here's the code:

ProductId prod = callOption.getProduct();

ArrayList<String> symbols = new ArrayList<String>(); 
// getSymbol returns GOOG Jan 22 '11 $150 Call   
symbols.add(prod.getSymbol());

// m is a MarketClient instance
QuoteResponse quotes = m.getQuote(symbols, true, DetailFlag.OPTIONS);

When I call m.getQuote I get an error. The error is

ERROR ConnectionUtils - Invalid uri 'https://etwssandbox.etrade.com/market/sandbox/rest/quote/GOOG Jan 22 '11 $150 Call': escaped absolute path not valid

I've tried using html (org.apache.commons.lang.StringEscapeUtils.escapeHtml) escaping with no luck.

Any ideas what is wrong?


Solution

  • It is because you have special characters(spaces and what not ) in your url.

    You can use the URL Encoder library for this one.

    You'll have to pass in a string of the entire url, which will give you an encoded url.

     String encodedUrl = URLEncoder.encode(<url>);
    

    For further information, here is the documentation https://docs.oracle.com/javase/7/docs/api/java/net/URLEncoder.html