WojciechZankowski / iextrading4j

IEX Cloud open source API wrapper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NPE when trying to get a symbol list

elyograg opened this issue · comments

Back in March, I had a program using the 2.3.0 version of iextrading4j that worked perfectly.

I hadn't run it for a long time, then tried it again a few days ago. It didn't work, and research revealed that IEX changed their API.

So I upgraded to the latest version of iextrading4j and set about fixing the code.

I am now creating the client like this:

	private static final IEXCloudClient iexClient = IEXTradingClient.create(new IEXCloudTokenBuilder()
            .withPublishableToken(IEX_PUBLISH_TOKEN)
            .withSecretToken(IEX_SECRET_TOKEN)
            .build());

And I am trying to get the symbol list like this:

		List<ExchangeSymbol> foundIexSymbols = iexClient.executeRequest(new ExchangeSymbolsRequestBuilder()
				.build());

Both of those code pieces needed changing when I upgraded. With that code, I get NPE:

Exception in thread "main" java.lang.NullPointerException: null value in entry: exchange=null
	at com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:32)
	at com.google.common.collect.SingletonImmutableBiMap.<init>(SingletonImmutableBiMap.java:42)
	at com.google.common.collect.ImmutableBiMap.of(ImmutableBiMap.java:71)
	at com.google.common.collect.ImmutableMap.of(ImmutableMap.java:123)
	at com.google.common.collect.ImmutableMap.copyOf(ImmutableMap.java:457)
	at com.google.common.collect.ImmutableMap.copyOf(ImmutableMap.java:436)
	at pl.zankowski.iextrading4j.api.util.MapUtil.immutableMap(MapUtil.java:15)
	at pl.zankowski.iextrading4j.client.rest.manager.RestRequest.<init>(RestRequest.java:32)
	at pl.zankowski.iextrading4j.client.rest.manager.RestRequestBuilder.build(RestRequestBuilder.java:102)
	at pl.zankowski.iextrading4j.client.rest.request.refdata.v1.ExchangeSymbolsRequestBuilder.build(ExchangeSymbolsRequestBuilder.java:29)
	at tristar.plieades.stocknotify.stock.StockSymbols.getAllUpdates(StockSymbols.java:139)
	at tristar.plieades.stocknotify.stock.StockSymbols.updateSymbolsFromApi(StockSymbols.java:110)
	at tristar.plieades.stocknotify.stock.StockSymbols.init(StockSymbols.java:68)
	at tristar.plieades.stocknotify.StockNotifyApplication.main(StockNotifyApplication.java:52)

Have I done something wrong, or is it a bug? I'm thinking probably bug, but maybe I should have done something different.

I did try adding .withExchange("AMEX") to the builder. This gets rid of the exception, but returns zero objects. So maybe I've used an incorrect string there.

Attaching a diff that shows the code changes I made from the old version.

iextrading4j-upgrade-patch.zip

Hey,

Yes, you need to provide an exchange to the request, otherwise it will fail. This ExchangeSymbolsRequestBuilder corresponds to this endpoint:

https://iexcloud.io/docs/api/#international-symbols

And according to the specification you need to provide an exchange. List of supported exchanges you can get from this endpoint: https://iexcloud.io/docs/api/#international-exchanges or just using ExchangeRequestBuilder.

If you just simply want to get all symbols from IEX then you can simply use this endpoint https://iexcloud.io/docs/api/#symbols which corresponds to SymbolsRequestBuilder.

Cheers,

Wojtek

Thanks. I got it working, and then discovered another piece of information -- my program now seems to be useless without paying IEX some money to allow more requests.

I feel you, message limit is pretty low on free account.