.NET
How to implement our HFTFeed.Client into your project
Install HFTFeed.Client Package
Before installation, make sure you are downloading the latest version of the client. Check the latest release on: https://www.nuget.org/packages/HFTFeed.Client
Install using .NET CLI
dotnet add package HFTFeed.Client --version 1.0.2
Install using NuGet Package Manager
NuGet\Install-Package HFTFeed.Client -Version 1.0.2
Manually add to .csproj file
PackageReference Include="HFTFeed.Client" Version="1.0.2"
Implementation
After installing the required dependencies, you need to import the HFTFeed.Client namespace and create an instance of HFTFeedClient. This class is responsible for managing the entire connection and real-time data streaming.
Creating an HFTFeedClient Instance
The HFTFeedClient class provides two constructors, both requiring an email and password for authentication. The first constructor connects to the default server. The second constructor allows you to specify a custom server host and port if needed.
public HFTFeedClient(string email, string password)
public HFTFeedClient(string email, string password, string host, int port)
using HFTFeed.Client;
// Connect to the default server, use this if you want to connect to the default HFTFeed server.
var client = new HFTFeedClient("your_email@example.com", "your_password");
// OR connect to a custom server, use this if you need to specify a custom host and port.
var client = new HFTFeedClient("your_email@example.com", "your_password", "custom.host.com", 1234);
Handling Events
HFTFeedClient provides several events that allow you to react to different actions, such as receiving market data (ticks), FIX messages, or connection status updates. Events in HFTFeedClient work like "callbacks"—when something important happens (e.g., a new market tick arrives), your code can automatically execute a function in response. Each event is an Action delegate, which means you can assign a method to it. When the event occurs, your assigned method will be called.
Method 1: Lambda Expression
// Handle new market ticks
client.OnNewTick = tick => Console.WriteLine($"New Tick: {tick}");
// Handle FIX messages
client.OnFixMsg = message => Console.WriteLine($"FIX Message: {message}");
// Handle connection status changes
client.OnConnectionStatus = status => Console.WriteLine($"Connection Status: {status}");
// Handle subscription confirmations
client.OnSubscribe = symbol => Console.WriteLine($"Subscribed to: {symbol}");
// Handle unsubscription confirmations
client.OnUnsubscribe = symbol => Console.WriteLine($"Unsubscribed from: {symbol}");
Method 2: Named Function
void HandleNewTick(Md tick)
{
Console.WriteLine($"New Tick Received: {tick}");
}
void HandleFixMsg(string fixMsg)
{
Console.WriteLine($"FIX Message: {fixMsg}");
}
void HandleConnectionStatus(ConnectionStatus status)
{
Console.WriteLine($"Connection Status: {status}");
}
void HandleSubscribe(string symbol)
{
Console.WriteLine($"Subscribed: {symbol}");
}
void HandleUnsubscribe(string symbol)
{
Console.WriteLine($"Unsubscribed: {symbol}");
}
//binding
client.OnNewTick += HandleNewTick;
client.OnFixMsg += HandleFixMsg;
client.OnConnectionStatus += HandleConnectionStatus;
client.OnSubscribe += HandleSubscribe;
client.OnUnsubscribe += HandleUnsubscribe;
//unbinding
client.OnNewTick -= HandleNewTick;
client.OnFixMsg -= HandleFixMsg;
client.OnConnectionStatus -= HandleConnectionStatus;
client.OnSubscribe -= HandleSubscribe;
client.OnUnsubscribe -= HandleUnsubscribe;
Connecting to the Server
Once you have created an instance of HFTFeedClient and bound your events, you need to start the connection to begin receiving market data.
Call Start() to begin receiving data:
client.Start();
To disconnect from the server, call Stop():
client.Stop();
Fetching symbols
HFTFeedClient provides a method to obtain the symbols, once your client is connected, call GetSymbols() to fetch available symbols.
Understanding HFTFeedSymbol Fields
The GetSymbols() method returns an array of HFTFeedSymbol, where each object represents an available market instrument.
public class HFTFeedSymbol
{
public string SymbolKey {get;set;}
public string SymbolName {get;set;}
public double Digits {get;set;}
}
SymbolKey Internal server ID of the symbol. This is required when subscribing to or managing streaming data.
SymbolName Human-readable name of the instrument, such as EURUSD or NDX.
Digits Number of decimal places used in price quotes. For example, if a price is 1.55455, then Digits = 5.
// Fetch symbols
var symbols = client.GetSymbols();
// Print symbols
foreach (var symbol in symbols)
{
Console.WriteLine($"SymbolKey: {symbol.SymbolKey}");
Console.WriteLine($"SymbolName: {symbol.SymbolName}");
Console.WriteLine($"Digits: {symbol.Digits}");
}
Best Practices
✅ Always use SymbolKey when subscribing to or managing data streams, as this is the server’s internal identifier.
✅ Use SymbolName for UI display to make it easier for users to recognize instruments.
✅ Handle different Digits values to ensure correct price formatting when processing market data.
Subscribe/Unsubscribe
After connecting your client and setting up the necessary bindings, you can begin retrieving market data. HFTFeedClient provides 4 methods to manage subscriptions efficiently.
client.Subscribe("TEST"); //Subscribes to a specific symbol to receive real-time market data.
client.Unsubscribe("TEST"); //Unsubscribes from a specific symbol, stopping data updates.
client.SubscribeAll(); // Subscribes to all available symbols at once.
client.UnsubscribeAll(); // Unsubscribes from all active subscriptions.
Full example
using HFTFeed.Client;
// Connect to the default server, use this if you want to connect to the default HFTFeed server.
var client = new HFTFeedClient("your_email@example.com", "your_password");
// Handle new market ticks
client.OnNewTick = tick => Console.WriteLine($"New Tick: {tick}");
// Handle FIX messages
client.OnFixMsg = message => Console.WriteLine($"FIX Message: {message}");
// Handle connection status changes
client.OnConnectionStatus = status => Console.WriteLine($"Connection Status: {status}");
// Handle subscription confirmations
client.OnSubscribe = symbol => Console.WriteLine($"Subscribed to: {symbol}");
// Handle unsubscription confirmations
client.OnUnsubscribe = symbol => Console.WriteLine($"Unsubscribed from: {symbol}");
client.Start();
client.SubscribeAll(); // Subscribes to all available symbols at once.
Console.Readline();
client.UnsubscribeAll(); // Unsubscribes from all active subscriptions.
client.Stop();