C# coding example not working

The code here: Assets Examples - Documentation | Alpaca

doesn’t do anything. It looks like a neat way to get a list of US stocks. Is there any way to make it work?

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

namespace CodeExamples
internal static class Example
private static string API_KEY = “your_api_key”;

    private static string API_SECRET = "your_secret_key";

    public static async Task Main(string[] args)
        // First, open the API connection
        var client = Alpaca.Markets.Environments.Paper
            .GetAlpacaTradingClient(new SecretKey(API_KEY, API_SECRET));

        // Get a list of all active assets.
        var assets = await client.ListAssetsAsync(
            new AssetsRequest { AssetStatus = AssetStatus.Active });

        // Filter the assets down to just those on NASDAQ.
        var nasdaqAssets = assets.Where(asset => asset.Exchange == Exchange.NyseMkt);



  1. The provided link is for outdated Alpaca documentation - it’s not supported or updated anymore. I recommend you use GitHub for actual code samples.
  2. The provided code itself is working. I just don’t print anything but the nasdaqAssets variable is properly populated with a list of IAsset objects if you provide the correct API key/secret and run this code with a breakpoint. You can easily print the content of this variable using foreach C# statement and Console.WriteLine method.

hey man, thanks for taking the time. I did try looping through such as:

        var assets3 = await client3.ListAssetsAsync(new AssetsRequest { AssetStatus = AssetStatus.Active });
        foreach (var item in assets3)

Perhaps the code executed before await? not to sure why it didn’t print anything. Actually I’m not even sure what data type Var is expecting.

Also thanks for the tip on the Github code. I’ve been studying it, but I must admit I am lost there as well. Is there a way to find a list of class methods available to functions like
ListAssetsAsync, ListHistoricalBarsAsync, etc…
I’ve read through Namespace Alpaca.Markets
But I really need more dumbed down code examples or explanations of manipulating market data with alpaca.markets using C# or perhaps just a code example using endpoints with curl and parsing json.

like in Interface IAlpacaDataClient

how does one use:
[GET] /v2/stocks/{symbol}/bars

Task<IBar> GetLatestBarAsync(LatestMarketDataRequest request, CancellationToken cancellationToken = null)

in a code example?

I’m sorry but I’m not a technical writer - I know that documentation and code samples are important but I was never able to find time to make them properly. Maybe this type of documentation can be more useful for you.

  1. Requesting all assets required some time for processing but if you correctly configure your API key/secret this code should print a long list of JSON objects received from the API. At least in the latest versions of SDK.
  2. The GetLatestsBarAsync method is obsolete and moreover it’s not related to the HTTP request that are you looking for. You should use the ListHistoricalBarsAsync method and you can find a good use case of this method in the MeanReversionBrokerage class.
  3. This Wiki page contains a mappings list between REST endpoints and .NET SDK methods. But again - it’s a little bit outdated and can miss some latest changes in the SDK.

In the MeanReversionBrokerage class it shows getting bar data for a single ticker:

       var barSubscription = client3.GetMinuteBarSubscription("symbol");

If I had the list from above nasdaqAssets, could I send that to GetMinuteBarSubscription(nasdaqAssets)?

I don’t quite follow what you mean in the older post here: