Unable to subscribe to streaming trade and quote data with paid account with C# client

I’m on a paid account. I signed up in order specifically to access real time data.

Here’s the test code:

public class AlpacaStreamingTest
{
public static async Task RunTest(string apiKey, string apiSecret)
{
try
{
Console.WriteLine("=== Alpaca Streaming Test ===");

// 1. Create credentials
var credentials = new SecretKey(apiKey, apiSecret);

// 2. Get streaming client for live environment with real-time data
var streamingClient = Alpaca.Markets.Environments.Live.GetAlpacaDataStreamingClient(credentials);

Console.WriteLine("Created streaming client for live environment");

// 3. Connect and authenticate
Console.WriteLine("Connecting to Alpaca streaming...");
await streamingClient.ConnectAndAuthenticateAsync();
Console.WriteLine("✓ Connected and authenticated successfully!");

// 4. Test subscription to trades for AAPL
var symbol = "AAPL";
Console.WriteLine($"Testing trade subscription for {symbol}...");

var tradeSubscription = streamingClient.GetTradeSubscription(symbol);
tradeSubscription.Received += (trade) =>
{
Console.WriteLine($"✓ TRADE: {trade.Symbol} at ${trade.Price} (Volume: {trade.Size})");
};

// 5. Attempt subscription
await streamingClient.SubscribeAsync(tradeSubscription);

Console.WriteLine($"Trade subscription status: {(tradeSubscription.Subscribed ? "SUCCESS" : "FAILED")}");

// 6. Test subscription to quotes
Console.WriteLine($"Testing quote subscription for {symbol}...");

var quoteSubscription = streamingClient.GetQuoteSubscription(symbol);
quoteSubscription.Received += (quote) =>
{
Console.WriteLine($"✓ QUOTE: {quote.Symbol} Bid=${quote.BidPrice} Ask=${quote.AskPrice}");
};

await streamingClient.SubscribeAsync(quoteSubscription);

Console.WriteLine($"Quote subscription status: {(quoteSubscription.Subscribed ? "SUCCESS" : "FAILED")}");

// 7. Wait for data
if (tradeSubscription.Subscribed || quoteSubscription.Subscribed)
{
Console.WriteLine("✓ Subscriptions successful! Waiting for real-time data for 30 seconds...");
await Task.Delay(30000);
}
else
{
Console.WriteLine("✗ No subscriptions successful. Market data access may not be enabled.");
}

// 8. Cleanup
await streamingClient.DisconnectAsync();
Console.WriteLine("Disconnected from Alpaca streaming");

}
catch (Exception ex)
{
Console.WriteLine($"✗ Test failed: {ex.Message}");
Console.WriteLine($"Stack trace: {ex.StackTrace}");
}
}
}

And here’s what I get:

=== Alpaca Streaming Test ===
Created streaming client for live environment
Connecting to Alpaca streaming...
✓ Connected and authenticated successfully!
Testing trade subscription for AAPL...
Trade subscription status: FAILED
Testing quote subscription for AAPL...
Quote subscription status: FAILED
✗ No subscriptions successful. Market data access may not be enabled.
Disconnected from Alpaca streaming

Why is this failing? REST apis work fine so far.

It’s noon, during market hours.

@nawoc What is the API key you are using or, if you know it, the ip address of your client. I can check the logs for what may be happening.

ok, i just connected via a VPN and here is the IP address you can look for: 185.229.59.168
here’s a paper api key that fails: PKDPT0AFJ9A99GC9FF72
i can give you a live one too if you need it

@nawoc From the logs it appears you are authenticating and successfully subscribing to AAPL trades, quotes and bars, However, your client then immediately disconnects. You are also connecting to the iex endpoint and not the sip endpoint so you aren’t streaming full market data. You may want to change that.

Below are the logs. Times are in market time US EDT. The first entry “client upgraded” simply means connected and authenticated. The next three entries are successfully subscribing to trades, quotes, and bars. But then the last entry is your client disconnecting “connection reset by peer’.

2025-08-15 14:18:31.711	
{"level":"info","timestamp":"2025-08-15T18:18:31.711Z","caller":"stream/client.go:458","msg":"client upgraded","clientIP":"185.229.59.168","connID":24351691}

2025-08-15 14:18:31.895	
{"level":"info","timestamp":"2025-08-15T18:18:31.894Z","caller":"stream/client.go:769","msg":"client subscription changed","clientIP":"185.229.59.168","connID":24351691,"path":"/v2/iex","query":"","auth_type":"account","auth_id":"13317f23-20e0-461f-8963-83e66abf0a66","kind":"subscribe","trades":{"symbols":"AAPL","count":1},"corrections":{"symbols":"AAPL","count":1},"cancel_errors":{"symbols":"AAPL","count":1}}

2025-08-15 14:18:31.903	
{"level":"info","timestamp":"2025-08-15T18:18:31.903Z","caller":"stream/client.go:769","msg":"client subscription changed","clientIP":"185.229.59.168","connID":24351691,"path":"/v2/iex","query":"","auth_type":"account","auth_id":"13317f23-20e0-461f-8963-83e66abf0a66","kind":"subscribe","quotes":{"symbols":"AAPL","count":1},"trades":{"symbols":"","count":1},"cancel_errors":{"symbols":"","count":1},"corrections":{"symbols":"","count":1}}

2025-08-15 14:18:31.903	
{"level":"info","timestamp":"2025-08-15T18:18:31.903Z","caller":"stream/client.go:769","msg":"client subscription changed","clientIP":"185.229.59.168","connID":24351691,"path":"/v2/iex","query":"","auth_type":"account","auth_id":"13317f23-20e0-461f-8963-83e66abf0a66","kind":"subscribe","bars":{"symbols":"AAPL","count":1},"trades":{"symbols":"","count":1},"cancel_errors":{"symbols":"","count":1},"corrections":{"symbols":"","count":1},"quotes":{"symbols":"","count":1}}

2025-08-15 14:18:31.903	
{"level":"warn","timestamp":"2025-08-15T18:18:31.903Z","caller":"stream/client.go:505","msg":"client disconnected","clientIP":"185.229.59.168","connID":24351691,"error":"read: connection reset by peer"}
 

I can’t be of much more help. I’m not very familiar with the C# SDK.

Post back here if you want me to check the logs again to help troubleshoot.

That helped slightly. It looks like the subscribe status is only posted in the C# SDK as an event, just doing async/away on the Subscribe doesn’t guarantee a connection. So got that working for the paper account. The live account though still doesn’t work when using wss://stream.data.alpaca.markets/v2/sip, but my live api key and secret key seem to work with the paper endpoint wss://stream.data.alpaca.markets/v2/iex … Any ideas on that one?

@nawoc Regarding sip vs iex, you will need to set that when you set GetAlpacaDataStreamingClient. Set the environment parameter to live (not sure of the syntax). See here on github.

It’s unfortunate that some of the SDKs equate live with sip and paper with iex. There really isn’t any correlation. Actually, when setting up your data clients (streaming or REST) you can use API keys from any paper or live account. The only reason you enter keys at all is so the API can 1) look up the account then 2) in the account look up the owner_id then 3) it finds your owner_id and checks which market data subscription you have. The market data subscription is tied to your owner_id and not the account.

Anyway, initialize GetAlpacaDataStreamingClient with your live environment and that by default will use the wss://stream.data.alpaca.markets/v2/sip endpoint. It looks like you can set/override this URL but using the live environment should do it. Note this doesn’t impact your trading environment.

@nawoc If you are able to figure out how to override/set the streaming URL endpoint, you may want to consider connecting to wss://stream.data.alpaca.markets/v2/test and then subscribing to the symbol FAKEPACA. That is a test connection which streams 24x7 so you can test after hours and on weekends. It may make troubleshooting easier?

I just re-ran the failing code and today everything’s working without any changes. So I’m guessing right now it’s a timing issue where I needed to wait 24 hours for the free to paid account change to kick in. The three tests I have are to subscribe to paper account with paper secrets, paper account with live secrets, and live account with live secrets. Working for quote, trade and bar data streaming subscriptions in all three cases. :man_shrugging:

@nawoc Great to hear it’s working. Just FYI, you mentioned “needed to wait 24 hours for the free to paid account change to kick in”. That change is immediate on the Alpaca side, so not sure what it could have been. This may not be your case, but often the keys and secrets are stored in OS variables. Changes made to environment variables are generally not propagated to running processes. They are only checked when a process is started.

In any case glad it’s working. Post back (maybe in a separate thread) if there is anything else.