Real-Time Push
The C# SDK provides real-time push notifications via WebSocket long connection through PushClient. It supports market data subscriptions and account event push, with built-in auto-reconnect and heartbeat.
PushClient is a singleton. Implement the IApiComposeCallback interface to handle push messages. Full runnable example:
using TigerOpenAPI.Common;
using TigerOpenAPI.Push;
using TigerOpenAPI.Push.Model;
TigerConfig config = new TigerConfig()
{
ConfigFilePath = "/path/to/tiger_openapi_config.properties"
};
// Implement callback interface
class MyCallback : IApiComposeCallback
{
public void QuoteCallback(IList<QuoteBasicData> items)
{
foreach (var item in items)
{
Console.WriteLine($"Quote: {item.Symbol} latest price: {item.LatestPrice}");
}
}
public void OrderCallback(IList<OrderData> items)
{
foreach (var item in items)
{
Console.WriteLine($"Order: {item.Symbol} status: {item.Status}");
}
}
public void AssetCallback(IList<AssetData> items)
{
Console.WriteLine("Asset update received");
}
public void PositionCallback(IList<PositionData> items)
{
Console.WriteLine("Position update received");
}
public void Connected()
{
Console.WriteLine("WebSocket connected");
}
public void Disconnected()
{
Console.WriteLine("WebSocket disconnected");
}
public void Error(string errorMsg)
{
Console.WriteLine($"Push error: {errorMsg}");
}
}
// Get singleton and configure
PushClient pushClient = PushClient.GetInstance()
.Config(config)
.ApiComposeCallback(new MyCallback());
// Connect
pushClient.Connect();
// Subscribe to quotes
pushClient.SubscribeQuote(new List<string> { "AAPL", "TSLA" });
// Subscribe to account events
pushClient.SubscribeAsset();
pushClient.SubscribeOrder();
pushClient.SubscribePosition();Connection Management
Connect Establish Connection
Description
Establish a WebSocket long connection. The Connected() callback fires on success. Auto-reconnect is supported.
Example
PushClient pushClient = PushClient.GetInstance()
.Config(config)
.ApiComposeCallback(new MyCallback());
pushClient.Connect();Disconnect Close Connection
Description
Actively close the WebSocket connection. The Disconnected() callback fires after disconnection.
Example
pushClient.Disconnect();Market Data Subscriptions
SubscribeQuote Subscribe to Quotes
Description
Subscribe to real-time quote updates for specified stocks. The QuoteCallback fires whenever price or volume changes.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| symbols | List<string> | Yes | List of stock symbols, e.g. ["AAPL", "TSLA"]; HK stocks e.g. ["00700"] |
Example
// US stocks
pushClient.SubscribeQuote(new List<string> { "AAPL", "TSLA", "MSFT" });
// HK stocks
pushClient.SubscribeQuote(new List<string> { "00700" });Push Data Fields
QuoteBasicData contains:
| Field | Type | Description |
|---|---|---|
| Symbol | string | Stock symbol |
| LatestPrice | double | Latest price |
| PreClose | double | Previous close |
| Change | double | Price change |
| ChangePercentage | double | Change percentage (%) |
| Volume | long | Trading volume |
| Timestamp | long | Data timestamp (ms) |
CancelSubscribeQuote Unsubscribe from Quotes
Description
Cancel quote push subscriptions for specified stocks.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| symbols | List<string> | Yes | List of symbols to unsubscribe |
Example
pushClient.CancelSubscribeQuote(new List<string> { "TSLA" });Account Event Subscriptions
SubscribeAsset Subscribe to Asset Updates
Description
Subscribe to account asset change push. The AssetCallback fires when net liquidation, margin, or available funds change.
Example
pushClient.SubscribeAsset();Push Data Fields
AssetData contains:
| Field | Type | Description |
|---|---|---|
| Account | string | Account ID |
| NetLiquidation | double | Net liquidation value |
| CashBalance | double | Cash balance |
| BuyingPower | double | Available buying power |
| UnrealizedPnl | double | Unrealized P&L |
| Timestamp | long | Data timestamp (ms) |
SubscribeOrder Subscribe to Order Updates
Description
Subscribe to order status change push. The OrderCallback fires when an order is filled, cancelled, etc.
Example
pushClient.SubscribeOrder();Push Data Fields
OrderData contains:
| Field | Type | Description |
|---|---|---|
| Id | long | Order ID |
| Symbol | string | Contract symbol |
| Action | string | Direction: BUY / SELL |
| Status | string | Order status |
| TotalQuantity | double | Total quantity |
| FilledQuantity | double | Filled quantity |
| AvgFillPrice | double | Average fill price |
| Timestamp | long | Data timestamp (ms) |
SubscribePosition Subscribe to Position Updates
Description
Subscribe to position change push. The PositionCallback fires when position quantity or cost changes.
Example
pushClient.SubscribePosition();Push Data Fields
PositionData contains:
| Field | Type | Description |
|---|---|---|
| Account | string | Account ID |
| Symbol | string | Contract symbol |
| Quantity | double | Position quantity |
| AverageCost | double | Average cost |
| MarketValue | double | Market value |
| UnrealizedPnl | double | Unrealized P&L |
| Timestamp | long | Data timestamp (ms) |
Callback Interface
IApiComposeCallback Interface
Implement this interface to handle all push message types:
class MyCallback : IApiComposeCallback
{
// Quote push callback
public void QuoteCallback(IList<QuoteBasicData> items) { }
// Order book depth push callback
public void QuoteDepthCallback(IList<QuoteDepthData> items) { }
// Trade tick push callback
public void TradeTickCallback(IList<TradeTickData> items) { }
// Order status push callback
public void OrderCallback(IList<OrderData> items) { }
// Asset change push callback
public void AssetCallback(IList<AssetData> items) { }
// Position change push callback
public void PositionCallback(IList<PositionData> items) { }
// Connection established callback
public void Connected() { }
// Disconnection callback
public void Disconnected() { }
// Error callback
public void Error(string errorMsg) { }
}Updated 5 days ago
