question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No market data from polygon web socket

See original GitHub issue

I switched to using the PolygonSockClient (since the NATS client was deprecated), but no market events are being fired. See sample code below:

using Alpaca.Markets;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace AlpacaApiTests
{
    class Program
    {
        static void Main(string[] args)
        {
            AlpacaClient client = new AlpacaClient();
            client.Start().Wait();
            Console.WriteLine("done");
        }
    }

    public class AlpacaClient
    {
        private readonly PolygonSockClient marketDataClient;
        private readonly ManualResetEventSlim awaiter;

        public AlpacaClient()
        {
            this.marketDataClient = new PolygonSockClient(
                keyId: "<ALPACA_API_KEY_ID>",
                isStagingEnvironment: false);
            this.awaiter = new ManualResetEventSlim();
        }

        public async Task Start()
        {
            var auth = await this.marketDataClient.ConnectAndAuthenticateAsync();
            Console.WriteLine(auth);
            this.marketDataClient.OnError += MarketDataClient_OnError;
            this.marketDataClient.QuoteReceived += MarketDataClient_QuoteReceived;
            this.marketDataClient.SubscribeQuote("AAPL");

            this.marketDataClient.SecondAggReceived += MarketDataClient_SecondAggReceived;
            this.marketDataClient.SubscribeSecondAgg("AAPL");

            awaiter.Wait();
        }

        private void MarketDataClient_OnError(Exception obj)
        {
            Console.WriteLine(obj);
        }

        private void MarketDataClient_SecondAggReceived(IStreamAgg obj)
        {
            Console.WriteLine($"{obj.EndTime}: {obj.Symbol}");
        }

        private void MarketDataClient_QuoteReceived(IStreamQuote obj)
        {
            Console.WriteLine($"{obj.Time}: {obj.Symbol}");
        }
    }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:21 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
OlegRacommented, Oct 22, 2019

I’m unable to change this behavior in the current SDK version because it would be a breaking change. But I’ll open a separate issue for the next major release. In this case, I’ll have time for investigation of possible procs and cons of this change.

0reactions
OlegRacommented, Oct 22, 2019

@biyimaks Could you please close this issue if the problem is solved now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues | Knowledge Base
WebSocket disconnects can occur for a variety of reasons. Usually, a disconnect means the market data isn't being consumed fast enough.
Read more >
Not receiving all messages from polygon websocket when ...
I'm using polygon's websocket with my Alpaca API key, from chatting with polygon the best way to get this data is to subscribe...
Read more >
Streaming Real-Time Stock Market Data with Polygon.io + ...
... Polygon.io with Python for accessing stock market data, we'll explore how to stream real-time stock market data through a websocket.
Read more >
Streaming Real-Time Stock Market Data with Polygon.io + Go
... using Polygon.io with Go for accessing stock market data, we'll explore how to stream real-time stock market data through a websocket.
Read more >
Streaming Real-Time Stock Market Data with Polygon.io + ...
... Polygon.io with JavaScript for accessing stock market data, we'll explore how to stream real-time stock market data through a websocket.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found