Books
Receive the latest five best bids and asks for subscribed futures/options contracts.
Parameters
| Name | Type | Description |
|---|---|---|
channel* | string | Subscription channel: trades, books, aggregates, candles |
symbol* | string | Contract symbol |
afterHours* | bool | Subscribe to after-hours market data. true: after-hours session; false: regular session; default: false |
Response
| Name | Type | Description |
|---|---|---|
symbol* | string | Futures/options contract symbol |
type* | string | Ticker type |
exchange* | string | Exchange |
market | string | Market type |
time* | number | Time |
bids | object[] | Five best bids |
>> price | number | Bid price |
>> size | number | Bid size |
asks | object[] | Five best asks |
>> price | number | Ask price |
>> size | number | Ask size |
derivedBid | object | Derived best bid (one additional level; price/size are 0 when no derived level is available) |
>> price | number | Derived bid price |
>> size | number | Derived bid size |
derivedAsk | object | Derived best ask (one additional level; price/size are 0 when no derived level is available) |
>> price | number | Derived ask price |
>> size | number | Derived ask size |
isTrial | boolean | true during trial matching (present only during the trial-matching phase) |
info
'*' indicates fields that are always disclosed.
Derived levels and trial-matching field
derivedBid/derivedAskprovide an additional derived quote level, primarily for spread contracts. For ordinary futures contracts,price=0andsize=0are typical.isTrialmay betruewhenever the instrument is in trial matching, including pre-open trial matching and an intraday auction/cooling period. During normal continuous matching, the field may befalseor omitted.- These advanced futures/options market data fields appear only when supported by the service.
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': 'books',
'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: "books",
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.Books, "TXFA4");
// await futopt.Subscribe(FugleMarketData.WebsocketModels.FutureOptionChannel.Books, 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",
"bids": [
{
"price": 17539,
"size": 2
},
{
"price": 17538,
"size": 4
},
{
"price": 17537,
"size": 3
},
{
"price": 17536,
"size": 10
},
{
"price": 17535,
"size": 10
}
],
"asks": [
{
"price": 17541,
"size": 2
},
{
"price": 17542,
"size": 15
},
{
"price": 17543,
"size": 3
},
{
"price": 17544,
"size": 5
},
{
"price": 17545,
"size": 4
}
],
"derivedBid": {
"price": 17540,
"size": 1
},
"derivedAsk": {
"price": 0,
"size": 0
},
"time": 1702956500113000
},
"id": "<CHANNEL_ID>",
"channel": "books"
}