我正在尝试使用 Etrade 的 Java SDK 获取期权报价。我目前正在设置使用沙箱。
这是代码:
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);
当我调用 m.getQuote 时,出现错误。错误是
ERROR ConnectionUtils - Invalid uri 'https://etwssandbox.etrade.com/market/sandbox/rest/quote/GOOG Jan 22 '11 $150 Call': escaped absolute path not valid
我尝试使用 html (org.apache.commons.lang.StringEscapeUtils.escapeHtml) 转义,但没有成功。
有什么问题吗?
最佳答案
这是因为您的网址中有特殊字符(空格等)。
您可以为此使用 URL 编码器库。
您必须传入整个 url 的字符串,这将为您提供一个编码的 url。
String encodedUrl = URLEncoder.encode(<url>);
有关更多信息,请参阅文档 https://docs.oracle.com/javase/7/docs/api/java/net/URLEncoder.html
关于java - 如何使用 ETrade API 获取 OptionQuote,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42147987/