Petersoj / alpaca-java

A Java API for Alpaca, the commission free, algo friendly, stock trading broker. https://alpaca.markets
https://petersoj.github.io/alpaca-java/
MIT License
198 stars 84 forks source link

PolygonAPI Subscribing to wildcard ("*") does not work. #9

Closed Petersoj closed 5 years ago

Petersoj commented 5 years ago

According to the Polygon API, you can stream all tickers on the available channels using the wildcard (e.g. T. or Q.), but when I do so in the code below, there are no stream updates and the connection just hangs.

        PolygonAPI polygonAPI = new PolygonAPI();
        polygonAPI.addPolygonStreamListener(new PolygonStreamListener() {
            @Override
            public Map<String, Set<ChannelType>> getStockChannelTypes() {
                Map<String, Set<ChannelType>> channelTypes = new HashMap<>();
                channelTypes.put("*", Sets.newHashSet(ChannelType.QUOTES));
                return channelTypes;
            }

            @Override
            public void streamUpdate(String s, ChannelType channelType, ChannelMessage channelMessage) {
                System.out.println("===> streamUpdate " + s + " " + channelType + " " + channelMessage);
            }
        });

I spoke with a Polygon representative and supposedly the Alpaca Live Account API Key does allow for wildcards when subscribing to various channels. It may be a limitation Polygon put on the NATS connections specifically for Alpaca, but I'm not sure.

mainstringargs commented 5 years ago

Figured out the issue -- my code wasn't expecting wildcards to be usable, so it was just throwing the messages away. Will fix soon.

mainstringargs commented 5 years ago

Give it a try when you can. I believe its working better.

Petersoj commented 5 years ago

Works great now. Thanks!