# C# coding example not working

**URL:** <https://forum.alpaca.markets/t/c-coding-example-not-working/11224>\
**Category:** Getting Started with Alpaca\
**Created:** [December 3, 2022, 10:41pm UTC](https://forum.alpaca.markets/t/c-coding-example-not-working/11224 "2022-12-03T22:41:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Lavoo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/mike_lavoo/32/4887_2.png) [@Mike\_Lavoo](https://forum.alpaca.markets/u/Mike_Lavoo)\
**Post date:** [December 3, 2022, 10:41pm UTC](https://forum.alpaca.markets/t/c-coding-example-not-working/11224/1 "2022-12-03T22:41:08Z")

</div>

The code here: [Assets Examples - Documentation | Alpaca](https://alpaca.markets/deprecated/docs/api-documentation/how-to/assets/)

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);

        Console.Read();
    }
}

```

}

---

<div class="post-metadata">

**Author:** ![oleg.rakhmatulin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/oleg.rakhmatulin/32/559_2.png) [@oleg.rakhmatulin](https://forum.alpaca.markets/u/oleg.rakhmatulin)\
**Post date:** [December 5, 2022, 10:08pm UTC](https://forum.alpaca.markets/t/c-coding-example-not-working/11224/2 "2022-12-05T22:08:35Z")

</div>

1. The provided link is for outdated Alpaca documentation - it’s not supported or updated anymore. I recommend you use [GitHub](https://github.com/alpacahq/alpaca-trade-api-csharp/wiki) 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.

---

<div class="post-metadata">

**Author:** ![Mike\_Lavoo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/mike_lavoo/32/4887_2.png) [@Mike\_Lavoo](https://forum.alpaca.markets/u/Mike_Lavoo)\
**Post date:** [December 17, 2022, 2:04pm UTC](https://forum.alpaca.markets/t/c-coding-example-not-working/11224/3 "2022-12-17T14:04:39Z")

</div>

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)
        {
            Console.WriteLine(item);
        }

```

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](https://olegra.github.io/Alpaca.Markets/api/Alpaca.Markets.html)  
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](https://olegra.github.io/Alpaca.Markets/api/Alpaca.Markets.IAlpacaDataClient.html#Alpaca_Markets_IAlpacaDataClient_ListHistoricalBarsAsync_Alpaca_Markets_HistoricalBarsRequest_System_Threading_CancellationToken_)

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

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

```

in a code example?

---

<div class="post-metadata">

**Author:** ![oleg.rakhmatulin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/oleg.rakhmatulin/32/559_2.png) [@oleg.rakhmatulin](https://forum.alpaca.markets/u/oleg.rakhmatulin)\
**Post date:** [December 20, 2022, 6:30am UTC](https://forum.alpaca.markets/t/c-coding-example-not-working/11224/4 "2022-12-20T06:30:52Z")

</div>

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](https://olegra.github.io/Alpaca.Markets/api/Alpaca.Markets.html) 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](https://github.com/alpacahq/alpaca-trade-api-csharp/wiki/REST-API-mappings) 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.

---

<div class="post-metadata">

**Author:** ![Mike\_Lavoo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/mike_lavoo/32/4887_2.png) [@Mike\_Lavoo](https://forum.alpaca.markets/u/Mike_Lavoo)\
**Post date:** [December 31, 2022, 2:29pm UTC](https://forum.alpaca.markets/t/c-coding-example-not-working/11224/7 "2022-12-31T14:29:19Z")

</div>

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:

> [@GetMinuteBarSubscription](https://forum.alpaca.markets/t/getminutebarsubscription/7349/4):
>
> If you need the minute bars for ALL active symbols just use the GetMinuteBarSubscription method without parameters. If you want to subscribe to some set of contracts just use the latest SDK version (some previous have a bug related to mass subscription) or use Extensions package that provides helper methods for creating a single subscription for array (or IEnumerable\<String\>) or symbols.
