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

ParameterTypeRequiredDescription
symbolsList<string>YesList 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:

FieldTypeDescription
SymbolstringStock symbol
LatestPricedoubleLatest price
PreClosedoublePrevious close
ChangedoublePrice change
ChangePercentagedoubleChange percentage (%)
VolumelongTrading volume
TimestamplongData timestamp (ms)

CancelSubscribeQuote Unsubscribe from Quotes

Description

Cancel quote push subscriptions for specified stocks.

Parameters

ParameterTypeRequiredDescription
symbolsList<string>YesList 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:

FieldTypeDescription
AccountstringAccount ID
NetLiquidationdoubleNet liquidation value
CashBalancedoubleCash balance
BuyingPowerdoubleAvailable buying power
UnrealizedPnldoubleUnrealized P&L
TimestamplongData 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:

FieldTypeDescription
IdlongOrder ID
SymbolstringContract symbol
ActionstringDirection: BUY / SELL
StatusstringOrder status
TotalQuantitydoubleTotal quantity
FilledQuantitydoubleFilled quantity
AvgFillPricedoubleAverage fill price
TimestamplongData 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:

FieldTypeDescription
AccountstringAccount ID
SymbolstringContract symbol
QuantitydoublePosition quantity
AverageCostdoubleAverage cost
MarketValuedoubleMarket value
UnrealizedPnldoubleUnrealized P&L
TimestamplongData 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) { }
}