Scd.ProjectX.Client 0.2.4

dotnet add package Scd.ProjectX.Client --version 0.2.4
                    
NuGet\Install-Package Scd.ProjectX.Client -Version 0.2.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Scd.ProjectX.Client" Version="0.2.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Scd.ProjectX.Client" Version="0.2.4" />
                    
Directory.Packages.props
<PackageReference Include="Scd.ProjectX.Client" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Scd.ProjectX.Client --version 0.2.4
                    
#r "nuget: Scd.ProjectX.Client, 0.2.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Scd.ProjectX.Client@0.2.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Scd.ProjectX.Client&version=0.2.4
                    
Install as a Cake Addin
#tool nuget:?package=Scd.ProjectX.Client&version=0.2.4
                    
Install as a Cake Tool

ShortChangedDegen's ProjectX API Client

Provides common boilerplate functionality for communicating with the ProjectX REST API and event hubs.


Overview

This library provides a simple way to access the ProjectX REST API and real-time event hubs. It is intended to be used as a starting point for building applications that interact with the ProjectX platform.

RESTful API Access

REST calls are made using the ProjectXApi class. This class provides methods for accessing the various endpoints of the ProjectX API. The API is organized by endpoint, so you can access accounts, contracts, orders, trades, and more through the corresponding properties of the ProjectXApi class.

Events and Observers

Messaging uses the Observer pattern to allow for an easy way to subscribe to events. See more from MSDN on the Observer Pattern. To receive events, you need to implement IObserver<T> for the type of event you want to subscribe to. It can then be registered:

await projectXHub.Subscribe(contractIds, new MarketDepthObserver());

The types of events listed below. Definitions should mirror the ProjectX API Documentation.

  • MarketDepthEvent
  • MarketQuoteEvent
  • MarketTradeEvent
  • UserAccountEvent
  • UserOrderEvent
  • UserTradeEvent
  • UserPositionEvent

Basic Usage

Add a section to the appsettings.json file for ProjectXClient:

appsettings.json
...
},
{
    "ProjectXClient": {
        "Username": "<<USERNAME>>",
        "ApiKey": "<<APIKEY>>",
        "ApiUrl": "https://api.topstepx.com",
        "UserHubUrl": "https://rtc.topstepx.com/hubs/user",
        "MarketHubUrl": "https://rtc.topstepx.com/hubs/market",
        "TokenExpirationMinutes": 1380 // 23 "hours", token is good for 24 hours.
      }
},
...

Register required services

Adding .AddProjectXClientServices to your HostBuilder will add all the necessary classes to the appropriate ServiceCollection.

It isn't necessary to use this extension method if you're not worried about ProjectXApi and ProjectXHub.

All registered services are located using the interface they implement, so ProjectXApi is located using something like app.Services.GetService<IProjectXApi>().

var app = Host.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration((context, config) =>
                {
                    ...
                })
                .AddProjectXClientServices()
                .Build();    

Accessing the ProjectX API

ProjectX REST APIs are made using the ProjectXApi class. Everything is organized by the endpoint being called. For instance, accounts can be accessed using _projectXApi.Accounts

_projectXApi = app.Services.GetService<IProjectXApi>();
await _projectXApi.Accounts.Authenticate(username,  apikey);

Register and Starting ProjectXHub

ProjectX API real-time events are accesed through the ProjectXHub class. This is intended to simplify setting up to consume events.

It is important to call projectXHub.StartAsync() before subscribing to any type of events or thing will blow up.

var projectXHub = app.Services.GetService<IProjectXHub>();
await projectXHub!.StartAsync();

if (contractIds.Any())
{
    await projectXHub.Subscribe(contractIds, new MarketQuoteObserver());
    await projectXHub.Subscribe(contractIds, new MarketTradeObserver());
    await projectXHub.Subscribe(contractIds, new MarketDepthObserver());
}

await projectXHub.Subscribe(new UserAccountObserver());
if (accountIds.Any())
{
    await projectXHub.Subscribe(accountIds, new UserOrderObserver());
    await projectXHub.Subscribe(accountIds, new UserTradeObserver());
    await projectXHub.Subscribe(accountIds, new UserPositionObserver());
}

It is necessary to implement the IObserver<T> inteface for any class that needs to receive events. Multiple observers can receive the same type of event.

Example IObserver<T>
public class MarketDepthObserver : IObserver<MarketDepthEvent>
    {
        private int _throughputCounter = 0;

        public void OnCompleted() => Console.WriteLine($"onCompleted: {nameof(MarketDepthObserver)}");

        public void OnError(Exception error) => Console.WriteLine(error);

        public void OnNext(MarketDepthEvent value)
        {
            var @event = JsonSerializer.Serialize(value);
            Console.WriteLine($"MarketDepthEvent ({++_throughputCounter}):\n {@event}");
        }
    }

See Scd.ProjectX.Client.Example for a running console app.

FAQ

  • Why?

I decided to share some common functionality that needs to be implemented by everyone. Hopefully, it makes it easier to get started developing with the ProjectX API and doing the interesting things you want to do.

I do not have any professional relationship with ProjectX.

You can buy me a coffee if you're feeling generous and want to

I haven't looked into using Python.NET. Obviously this isn't the answer for everything (or everyone(anyone?)) but if its a good fit, it could be a way to get started with the ProjectX API in Python.

Python developers should probably check out the ProjectX Gateway API SDK for Python (Unofficial) repo.

  • Is ShortChangedDegen a degenerate gambler or something who always loses money?

¯_(ツ)_/¯ It was the first thing I could think of when joining a discord for the first time. It was mostly tongue and cheek self-deprecation. We've all been there. Well, I have.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.4 113 7/11/2025
0.2.3 125 7/10/2025
0.2.2 122 7/10/2025
0.2.1 134 7/2/2025
0.2.0 135 6/30/2025

Inintial Release