# Quickstart

> Install STX.Sdk, authenticate, and make your first call in under five minutes.

Source: https://docs.stxapp.io/sdks/csharp/quickstart/

Shortest path from zero to your first authenticated call against an STX demo environment.

:::note
Use a **demo** environment for anything you're building. `OntarioProduction` trades with real balances, so exercise your code path against `OntarioDemo` first.
:::

## Prerequisites

- .NET 8 SDK or later (`dotnet --version`)
- An API key created under **Account → API Keys**, which gives you a key ID and an Ed25519 private key. Save the key to a file, for example `~/.stx/ontario.pem`

## Walkthrough

  
#### Create a project and install the SDK

    ```bash
    dotnet new console -n StxQuickstart
    cd StxQuickstart
    dotnet add package STX.Sdk
    dotnet add package Microsoft.Extensions.Hosting
    ```

    Verify the install:

    ```bash
    dotnet list package | grep STX.Sdk
    ```
  

  
#### Register STX services

    Replace `Program.cs` with:

    ```csharp Program.cs
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Hosting;
    using STX.Sdk;
    using STX.Sdk.Auth;
    using STX.Sdk.Services;
    using STX.Sdk.Settings;

    var host = Host.CreateDefaultBuilder(args)
        .ConfigureServices(services =>
        {
            services.ConfigureSTXServices(
                STXEnvironment.OntarioDemo,
                STXApiKeyCredentials.FromPemFile(
                    Environment.GetEnvironmentVariable("STX_KEY_ID")!,
                    Environment.GetEnvironmentVariable("STX_KEY_PATH")!));
        })
        .Build();

    var identity = host.Services.GetRequiredService<STXIdentityService>();
    var market = host.Services.GetRequiredService<STXMarketService>();

    // No login call. One call to learn who the key belongs to, which channels need later.
    var me = await identity.GetMeAsync();
    Console.WriteLine($"Authenticated as {me.UserId} (scope {me.Scope})");

    var resp = await market.GetMarketInfosWithCountAsync();

    Console.WriteLine($"Got {resp.MarketInfos.Count} of {resp.Count} markets");
    foreach (var m in resp.MarketInfos.Take(5))
    {
        Console.WriteLine($"  {m.MarketId}  {m.Status,-10}  {m.Title}");
    }
    ```
  

  
#### Point at your key and run

    
    ```bash macOS / Linux
    export STX_KEY_ID="your-key-id"
    export STX_KEY_PATH="$HOME/.stx/ontario.pem"
    dotnet run
    ```

    ```powershell Windows (PowerShell)
    $env:STX_KEY_ID = "your-key-id"
    $env:STX_KEY_PATH = "$HOME\.stx\ontario.pem"
    dotnet run
    ```
    

    You should see something like:

    ```
    Authenticated as 4f2c... (scope read_write)
    Got 50 of 217 markets
      mkt_8f3...  open        Who wins Game 4 of the NBA Finals?
      mkt_a12...  open        LAL @ BOS moneyline
      mkt_c94...  open        Total points over/under 214.5
      mkt_d70...  open        First team to 20 points
      mkt_e55...  open        Race to 10 rebounds
    ```

    The first number is the page you were served, the second is the total matching the filter.

    If the signature is rejected, check the host clock: the server allows 30 seconds of skew. If you see a `HttpRequestException`, the host isn't reachable from your network. If placing an order fails but queries work, your key is probably `read_only`.
  

  
#### Place your first order

    After the market fetch, pick a market and place a tiny limit order:

    ```csharp
    using STX.Sdk.Enums;

    var orderService = host.Services.GetRequiredService<STXOrderService>();
    var targetMarket = resp.MarketInfos.First(m => m.Status == STXMarketStatus.open);

    var order = await orderService.ConfirmOrderAsync(
        price:     10,                       // cents
        quantity:  1,
        marketId:  targetMarket.MarketId,
        action:    STXOrderAction.buy,
        orderType: STXOrderType.limit,
        cancelOnDisconnect: false);          // true requires the active orders channel joined

    Console.WriteLine($"Placed order {order.Id} at {order.Price}c × {order.Quantity}");

    await orderService.CancelOrderAsync(order.Id);
    Console.WriteLine($"Cancelled {order.Id}");
    ```

    Run again. The program should print the placed + cancelled order IDs.
  

## Next steps

  - [Authentication](/sdks/csharp/authentication/): API keys, signing, scopes.
  - [Configuration](/sdks/csharp/configuration/): Per-environment endpoints, DI tips.
  - [Trading](/sdks/csharp/trading/): Cancel-all, batch orders, cancel-on-disconnect.
  - [WebSockets](/sdks/csharp/websockets/): Subscribe to portfolio, orders, trades, market updates.
