Trades
Receive the latest trade information for subscribed futures/options contracts.
Parameters
| Name | Type | Description |
|---|---|---|
channel* | string | Subscription channel: trades, books, aggregates, candles |
symbol* | string | Futures product symbol |
afterHours* | bool | Subscribe to after-hours market data. true: after-hours session; false: regular session; default: false |
Response
| Name | Type | Description |
|---|---|---|
symbol* | string | Product symbol |
type* | string | Ticker type |
exchange* | string | Exchange |
market | string | Market type |
trades | object | Trade quote |
>> price | number | Trade price |
>> size | number | Trade size |
>> bid | number | Bid price at the trade |
>> ask | number | Ask price at the trade |
total | object | Trade volume statistics |
>> tradeVolume | number | Total trade volume |
>> totalBidMatch | number | Bid-side match count |
>> totalAskMatch | number | Ask-side match count |
time* | number | Time |
serial* | number | Serial number |
isTrial | boolean | true during trial matching (present only during trial matching and omitted after the market opens) |
info
'*' indicates fields that are always disclosed.
Trial-matching field
isTrial is disclosed as true only during pre-open trial matching. After the market opens, regular matching data resumes and this field is omitted. If no trial trade occurs during trial matching, trades[0].price and trades[0].size are 0.
Example
Subscribe channel
- Python
- Node.js
- C#
from fubon_neo.sdk import FubonSDK, Order
def handle_message(message):
print(f'market data message: {message}')
sdk = FubonSDK()
accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password") # Login is required to obtain market-data permissions
sdk.init_realtime() # Initialize the market-data connection
futopt = sdk.marketdata.websocket_client.futopt
futopt.on('message', handle_message)
futopt.connect()
futopt.subscribe({
'channel': 'trades',
'symbol': 'TXFA4'
#'afterHours' : True # After-hours market data
})
const { FubonSDK } = require('fubon-neo');
const sdk = new FubonSDK();
const accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password");
sdk.initRealtime(); // Initialize the market-data connection
const futopt = sdk.marketdata.webSocketClient.futopt;
futopt.connect().then(() => {
futopt.subscribe({
channel: "trades",
symbol: "TXFA4"
// afterHours: true // After-hours market data
});
});
futopt.on("message", (message) => {
const data = JSON.parse(message);
console.log(data);
});
using FubonNeo.Sdk;
var sdk = new FubonSDK();
var result = sdk.Login("Your ID", "Your password", "Your cert path", "Your cert password");
sdk.InitRealtime(); // Initialize the market-data connection
var futopt = sdk.MarketData.WebSocketClient.FutureOption;
futopt.OnMessage += (msg) => Console.WriteLine($"receive: { msg }");
await futopt.Connect();
await futopt.Subscribe(FugleMarketData.WebsocketModels.FutureOptionChannel.Trades, "TXFA4");
// await futopt.Subscribe(FugleMarketData.WebsocketModels.FutureOptionChannel.Trades, new FutureOptionParams { Symbol = "TXFC4", AfterHours = true }); // After-hours market data
Subscribe to multiple products
To subscribe to multiple products at the same time, see Subscribe Channel.
Receive data
{
"event": "data",
"data": {
"symbol": "TXFA4",
"type": "FUTURE",
"exchange": "TAIFEX",
"trades": [
{
"price": 17540,
"size": 1,
"bid": 17539,
"ask": 17540
}
],
"total": {
"tradeVolume": 12174,
"totalBidMatch": 8760,
"totalAskMatch": 7907
},
"time": 1702956487023000,
"serial": 159250
},
"id": "<CHANNEL_ID>",
"channel": "trades"
}
Trial-matching phase (isTrial)
During pre-open trial matching, data also includes isTrial: true:
{
"event": "data",
"data": {
"symbol": "TXFF6",
"type": "FUTURE_AH",
"exchange": "TAIFEX",
"trades": [
{
"price": 45380,
"size": 1
}
],
"total": {
"tradeVolume": 0,
"totalBidMatch": 0,
"totalAskMatch": 0
},
"isTrial": true,
"time": 1781506205000000,
"serial": 3
},
"channel": "trades"
}