Technical analysis API in C#: RSI and EMA for crypto and stocks


If you’re building a trading bot, a dashboard or a backtester in .NET, you need indicator values: RSI, moving averages, MACD and so on. You can compute them yourself, but then you also have to fetch and store candles, handle every exchange’s quirks, and check your maths against the charting tools your users trust.

A technical analysis API does that part for you. TAAPI.IO calculates 263 indicators for crypto pairs and US stocks, and returns them as JSON. One HTTP request, and you have the number.

In this tutorial you’ll build a small C# console app that:

  1. Gets the RSI for BTCUSDT on Binance.
  2. Gets RSI, EMA 50 and EMA 200 for Bitcoin and Apple in one request, and deserializes them into typed records.
  3. Runs a simple, clearly labelled example check on those numbers.
  4. Handles errors, timeouts and retries the way a production app should.

Every code example below was compiled with the .NET 8 SDK and run against the live API on 1 December 2026, and every response shown is the real output from that run.

What you need

  • The .NET 8 SDK (or newer). Check with dotnet --version.
  • A TAAPI.IO API key. Sign up for free, then copy your key from API Keys in the dashboard.

You don’t need any NuGet packages. Everything here uses HttpClient and System.Text.Json, which ship with .NET.

Create a console project:

dotnet new console -n TaapiDemo --framework net8.0
cd TaapiDemo

Put your API key in an environment variable, so it never ends up in your code or in Git:

# macOS / Linux
export TAAPI_API_KEY="your-api-key"

# Windows PowerShell
$env:TAAPI_API_KEY = "your-api-key"

Step 1: Get one indicator

The single-indicator endpoint is GET https://v2.taapi.io/indicator/{name}. You pass the exchange, the symbol and the timeframe, and authenticate with your key as a Bearer token.

Replace the contents of Program.cs with:

using System.Net.Http.Headers;
using System.Text.Json;

var apiKey = Environment.GetEnvironmentVariable("TAAPI_API_KEY")
    ?? throw new InvalidOperationException("Set the TAAPI_API_KEY environment variable.");

using var http = new HttpClient { BaseAddress = new Uri("https://v2.taapi.io/") };
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);

var json = await http.GetStringAsync("indicator/rsi?exchange=binance&symbol=BTCUSDT&timeframe=1h");
Console.WriteLine(json);

var options = new JsonSerializerOptions(JsonSerializerDefaults.Web); // case-insensitive names
var rsi = JsonSerializer.Deserialize<IndicatorResult>(json, options)!;
var time = DateTimeOffset.FromUnixTimeSeconds(rsi.Timestamp[0]);
Console.WriteLine($"BTCUSDT 1h RSI: {rsi.Value[0]:F2} (candle opened {time:yyyy-MM-dd HH:mm} UTC)");

record IndicatorResult(double[] Value, long[] Timestamp);

Run it with dotnet run. This is the real output:

{"value":[67.53001627718776],"timestamp":[1796112000]}
BTCUSDT 1h RSI: 67.53 (candle opened 2026-12-01 08:00 UTC)

A few things to notice:

  • value and timestamp are arrays. With the default of one result they hold one entry each. Add &results=10 and you get the last 10 values, oldest first, which is handy for backtests and charts. See historical values.
  • The timestamp is when the candle opened, in Unix seconds. We ran this at 08:58 UTC, so the value is for the 1-hour candle that’s still forming. Add &backtrack=1 if you only want values from closed candles.
  • JsonSerializerDefaults.Web makes property names case-insensitive, so the C# record Value matches the JSON field value without any attributes.

The RSI uses its standard period of 14. Every indicator takes its own optional parameters, such as period; each indicator page lists them.

Step 2: Several indicators, a crypto pair and a stock, in one request

Calling the API once per indicator works, but it adds up fast. The bulk endpoint, POST https://v2.taapi.io/bulk, lets you ask for many indicators in one request.

You send a list of constructs. A construct is one market, so one exchange + symbol + timeframe, plus the indicators you want for it. Each construct and each indicator gets an id that you choose, and the response uses those ids as keys.

Here we ask for RSI, EMA 50 and EMA 200 for two markets:

  • BTCUSDT on Binance, 1h candles.
  • AAPL, Apple, on 1d candles. For US stocks, exchange is stocks and the symbol is the plain ticker.
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;
using System.Text.Json.Serialization;

var apiKey = Environment.GetEnvironmentVariable("TAAPI_API_KEY")
    ?? throw new InvalidOperationException("Set the TAAPI_API_KEY environment variable.");

using var http = new HttpClient { BaseAddress = new Uri("https://v2.taapi.io/") };
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);

var request = new BulkRequest([
    TrendConstruct("btc_1h", "binance", "BTCUSDT", "1h"),
    TrendConstruct("aapl_1d", "stocks", "AAPL", "1d"),
]);

using var response = await http.PostAsJsonAsync("bulk", request);
response.EnsureSuccessStatusCode();
var json = await response.Content.ReadAsStringAsync();
Console.WriteLine(json);

var options = new JsonSerializerOptions(JsonSerializerDefaults.Web);
var results = JsonSerializer.Deserialize<Dictionary<string, TrendSnapshot>>(json, options)!;

foreach (var (id, s) in results)
{
    if (s.Error is not null || s.Rsi is null || s.Ema50 is null || s.Ema200 is null)
    {
        Console.WriteLine($"{id}: no data ({s.Error ?? "missing value"})");
        continue;
    }

    double rsi = s.Rsi.Value[0], ema50 = s.Ema50.Value[0], ema200 = s.Ema200.Value[0];

    // Example check only, not a trading signal: uptrend and not overbought.
    bool uptrend = ema50 > ema200;
    bool belowOverbought = rsi < 70;
    string verdict = uptrend && belowOverbought ? "PASS" : "FAIL";

    Console.WriteLine(
        $"{id,-8} RSI {rsi,6:F2} | EMA50 {ema50,10:F2} | EMA200 {ema200,10:F2} | " +
        $"EMA50 > EMA200: {(uptrend ? "yes" : "no "),-3} | RSI < 70: {(belowOverbought ? "yes" : "no "),-3} | {verdict}");
}

static Construct TrendConstruct(string id, string exchange, string symbol, string timeframe) =>
    new(id, exchange, symbol, timeframe, [
        new("rsi", "rsi", 14),
        new("ema50", "ema", 50),
        new("ema200", "ema", 200),
    ]);

record BulkRequest(Construct[] Constructs);
record Construct(string Id, string Exchange, string Symbol, string Timeframe, IndicatorRequest[] Indicators);
record IndicatorRequest(string Id, string Indicator, int Period);

record IndicatorResult(double[] Value, long[] Timestamp);
record TrendSnapshot(
    IndicatorResult? Rsi,
    IndicatorResult? Ema50,
    IndicatorResult? Ema200,
    [property: JsonPropertyName("_error")] string? Error);

PostAsJsonAsync serializes the records with camelCase names, so BulkRequest becomes exactly the body the API expects. Here’s the first construct; aapl_1d follows it with the same three indicators:

{
  "constructs": [
    {
      "id": "btc_1h",
      "exchange": "binance",
      "symbol": "BTCUSDT",
      "timeframe": "1h",
      "indicators": [
        { "id": "rsi", "indicator": "rsi", "period": 14 },
        { "id": "ema50", "indicator": "ema", "period": 50 },
        { "id": "ema200", "indicator": "ema", "period": 200 }
      ]
    }
  ]
}

This is the real response from the run, formatted for reading (the values are unchanged):

{
  "btc_1h": {
    "rsi":    { "value": [67.53001627718776], "timestamp": [1796112000] },
    "ema50":  { "value": [59737.62140987776], "timestamp": [1796112000] },
    "ema200": { "value": [60359.43085774979], "timestamp": [1796112000] }
  },
  "aapl_1d": {
    "rsi":    { "value": [54.57433532238498], "timestamp": [1795996800] },
    "ema50":  { "value": [343.2409695759447], "timestamp": [1795996800] },
    "ema200": { "value": [311.57084016926916], "timestamp": [1795996800] }
  }
}

The response mirrors your request: one key per construct id, and inside it one key per indicator id. That’s why it deserializes straight into a Dictionary<string, TrendSnapshot>, with one typed TrendSnapshot per market. The Apple timestamp is the daily candle of Monday 30 November, the last full trading day.

How many constructs can you send?

There’s no limit on the number of indicators inside a construct, but the number of constructs per request depends on your plan:

Plan Constructs per bulk request
Basic 1
Pro 3
Expert 10
Enterprise 15+

On Basic, put all your indicators for one market in a single construct. The two-construct example above needs Pro or higher. Two constructs can’t target the same exchange, symbol and timeframe. The full reference is in Bulk / multiple assets, and the plans are compared on the pricing page.

Step 3: Turn the numbers into a check

The loop in step 2 already does something with the values. It’s an example of the kind of rule a bot or screener runs. It is not trading advice, and it isn’t a strategy anyone should trade as-is:

  • EMA 50 above EMA 200: the medium-term average is above the long-term one, a common definition of an uptrend.
  • RSI below 70: the market isn’t in the zone many traders call overbought.

A market passes when both are true. This is the real output:

btc_1h   RSI  67.53 | EMA50   59737.62 | EMA200   60359.43 | EMA50 > EMA200: no  | RSI < 70: yes | FAIL
aapl_1d  RSI  54.57 | EMA50     343.24 | EMA200     311.57 | EMA50 > EMA200: yes | RSI < 70: yes | PASS

On the hourly chart, Bitcoin’s EMA 50 was still just under its EMA 200, so it fails the trend condition even with a firm RSI. Apple’s daily EMA 50 was well above its EMA 200 and its RSI was in the middle of the range, so it passes.

Because each condition is printed on its own, you can see why a market passes or fails. That matters more than the verdict when you’re testing a rule. To try your own, add an indicator to TrendConstruct, for example new("ema21", "ema", 21), add a matching IndicatorResult? Ema21 property to TrendSnapshot, and change the two bool lines.

When one market fails

If one construct fails, for example because of a typo in a ticker, the rest of the request still succeeds. The failed construct comes back with an _error message and null indicators. We ran the same program with NOTATICKER instead of AAPL; this is the real response for that construct, and what the program printed:

"aapl_1d": {
  "_error": "Failed to fetch candles: 404 Not Found — check exchange, symbol and timeframe parameters",
  "rsi": null,
  "ema50": null,
  "ema200": null
}
btc_1h   RSI  67.53 | EMA50   59737.62 | EMA200   60359.43 | EMA50 > EMA200: no  | RSI < 70: yes | FAIL
aapl_1d: no data (Failed to fetch candles: 404 Not Found — check exchange, symbol and timeframe parameters)

That’s what the nullable properties and the _error mapping in TrendSnapshot are for. Always check them before you use a value.

Step 4: Make it production-ready

The examples above are kept short. Before you run this inside a bot or a web app, add these four things.

Reuse one HttpClient. Create it once and keep it for the life of the app. Creating a new HttpClient for every request can exhaust sockets under load. In ASP.NET Core or a worker service, register it with IHttpClientFactory (services.AddHttpClient(...)) and set the base address and the Authorization header there.

Set a timeout. The default HttpClient timeout is 100 seconds, which is far too long for a bot. 10 to 15 seconds is plenty.

Handle the status codes. Errors come back as JSON with an error message. The ones to plan for:

Status Meaning What to do
200 Success Use the data.
202 The API is fetching candles for this market for the first time Repeat the same request after 1–2 seconds.
400 Bad request, such as an unknown indicator or invalid timeframe Fix the request. Retrying won’t help.
401 Missing or invalid API key Check the key and the Authorization header.
429 with retryAfter Too many requests in the current window Wait retryAfter seconds, then retry.
429 without retryAfter More constructs than your plan allows Send fewer constructs per request. Retrying won’t help.

The construct-limit error looks like this (here for a plan with 3 constructs):

{ "error": "Too many constructs. Your plan allows 3 construct(s) per bulk request." }

And when you hit the request rate limit:

{ "error": "Too Many Requests", "retryAfter": 9 }

See rate limits for each plan’s limits and errors for the full list.

Retry only what can succeed. Here’s a helper that does all of the above: one shared HttpClient with a timeout, retries for 202, rate-limit 429s and server errors, and a typed exception for everything else. To show it working, the program sends 21 constructs, one more than the API accepts on any plan:

using System.Net;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;

var apiKey = Environment.GetEnvironmentVariable("TAAPI_API_KEY")
    ?? throw new InvalidOperationException("Set the TAAPI_API_KEY environment variable.");

// One HttpClient for the whole app, with a timeout.
var http = new HttpClient
{
    BaseAddress = new Uri("https://v2.taapi.io/"),
    Timeout = TimeSpan.FromSeconds(15),
};
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);

// 21 constructs: one more than any plan allows, to show what an error looks like.
var symbols = new[] { "BTCUSDT", "ETHUSDT", "SOLUSDT", "XRPUSDT", "BNBUSDT", "ADAUSDT", "DOGEUSDT",
    "AVAXUSDT", "LINKUSDT", "DOTUSDT", "LTCUSDT", "TRXUSDT", "BCHUSDT", "ATOMUSDT", "NEARUSDT",
    "UNIUSDT", "APTUSDT", "ARBUSDT", "OPUSDT", "FILUSDT", "ETCUSDT" };
var tooMany = new
{
    constructs = symbols.Select(s => new
    {
        id = s.ToLowerInvariant(), exchange = "binance", symbol = s, timeframe = "1h",
        indicators = new[] { new { id = "rsi", indicator = "rsi" } },
    }),
};

try
{
    await SendWithRetryAsync<JsonElement>(http, () => new HttpRequestMessage(HttpMethod.Post, "bulk")
    {
        Content = JsonContent.Create(tooMany),
    });
}
catch (TaapiException ex)
{
    Console.WriteLine($"{(int)ex.Status} {ex.Status}: {ex.Message}");
}

static async Task<T> SendWithRetryAsync<T>(
    HttpClient http, Func<HttpRequestMessage> createRequest, CancellationToken ct = default)
{
    const int maxAttempts = 4;
    for (var attempt = 1; ; attempt++)
    {
        // A request message can only be sent once, so build a new one per attempt.
        using var response = await http.SendAsync(createRequest(), ct);
        if (response.StatusCode == HttpStatusCode.OK)
            return (await response.Content.ReadFromJsonAsync<T>(ct))!;

        var body = await response.Content.ReadAsStringAsync(ct);
        var (error, retryAfter) = ParseError(body);

        // 202: the API is fetching candles for the first time; repeat after a short pause.
        // 429 with retryAfter: the per-window request limit; wait as told.
        // 5xx: a server or network hiccup; back off and try again.
        // Anything else (400, 401, 429 without retryAfter) will fail again: don't retry.
        TimeSpan? wait = response.StatusCode switch
        {
            HttpStatusCode.Accepted => TimeSpan.FromSeconds(2),
            HttpStatusCode.TooManyRequests when retryAfter is not null => TimeSpan.FromSeconds(retryAfter.Value),
            >= HttpStatusCode.InternalServerError => TimeSpan.FromSeconds(Math.Pow(2, attempt)),
            _ => null,
        };

        if (wait is null || attempt == maxAttempts)
            throw new TaapiException(response.StatusCode, error ?? body);

        await Task.Delay(wait.Value, ct);
    }
}

static (string? Error, int? RetryAfter) ParseError(string body)
{
    try
    {
        using var doc = JsonDocument.Parse(body);
        var root = doc.RootElement;
        string? error = root.TryGetProperty("error", out var e) ? e.GetString() : null;
        int? retryAfter = root.TryGetProperty("retryAfter", out var r) ? r.GetInt32() : null;
        return (error, retryAfter);
    }
    catch (JsonException)
    {
        return (null, null);
    }
}

class TaapiException(HttpStatusCode status, string message) : Exception(message)
{
    public HttpStatusCode Status { get; } = status;
}

This is the real output. The request is rejected straight away, with no pointless retries:

400 BadRequest: Too many constructs. Maximum allowed per request is 20.

In your own code, call SendWithRetryAsync<Dictionary<string, TrendSnapshot>>(...) with the bulk request from step 2, and catch TaapiException where you can do something useful, such as logging it or skipping a cycle. If you already use Polly or Microsoft.Extensions.Http.Resilience, the same rules apply: retry 202, 429 with retryAfter and 5xx, and nothing else.

Where to go from here

  • Parameters, response fields and examples for each indicator: RSI API and EMA API
  • Everything the bulk endpoint can do: Bulk / multiple assets
  • All 263 indicators, from MACD and Bollinger Bands to fair value gaps: Indicators
  • Constructs, request rates and history per plan: Pricing

Ready to try it? Start for free with a 7-day trial on Basic or Pro. If you build something with it in C#, we’d love to hear about it: get in touch.