期貨
利用訂閱商品檔的方式去取得即時行情。
Quote Parameters:
enum QuoteType {tick, bidask}
bool intraday_odd: {true, false}
enum QuoteVersion: {v0, v1}
Tick¶
範例¶
In
_api.Subscribe(
contract:_api.Contracts.Futures["TXF"]["TXF202210"],
quoteType:QuoteType.tick,
version:QuoteVersion.v1
);
Out
Response Code: 0 | Event code: 16 | Info: TIC/v1/FOP/*/TFE/TXFJ2 | Event: SubscriptionOk
Exchange.TAIFEX TickFOPv1 {
"code": "TXFJ2",
"datetime": "2022/10/13 16:22:31.966000",
"open": 12880.0,
"underlying_price": 12810.73,
"bid_side_total_vol": 5266,
"ask_side_total_vol": 5255,
"avg_price": 12865.525151,
"close": 12868.0,
"high": 12887.0,
"low": 12842.0,
"amount": 77208.0,
"total_amount": 112792059.0,
"volume": 6,
"total_volume": 8767,
"tick_type": 2,
"chg_type": 4,
"price_chg": -1.0,
"pct_chg": -0.007771,
"simtrade": false
}
Response Code: 0 | Event code: 16 | Info: L/*/TXFJ2 | Event: SubscriptionOk
L/TFE/TXFJ2
Code: TXFJ2
Date: 2022/10/13
Time: 16:17:30.246000
Open: 12880
TargetKindPrice: 12810.73
TradeBidVolSum: 5215
TradeAskVolSum: 5179
AvgPrice: [12865.489219]
Close: [12870]
High: [12887]
Low: [12842]
Amount: [25740]
AmountSum: [111582388]
Volume: [2]
VolSum: [8673]
TickType: [1]
DiffType: [2]
DiffPrice: [1]
DiffRate: [0.007771]
屬性¶
Tick
code (string): 商品代碼
datetime (string): 日期
open (decimal): 開盤價
underlying_price (decimal): 標的物價格
bid_side_total_vol(int): 買盤成交總量 (lot)
ask_side_total_vol(int): 賣盤成交總量 (lot)
avg_price (decimal): 均價
close (decimal): 成交價
high (decimal): 最高價(自開盤)
low (decimal): 最低價(自開盤)
amount (decimal): 成交額 (NTD)
total_amount (decimal): 總成交額 (NTD)
volume (int): 成交量 (lot)
total_volume (int): 總成交量 (lot)
tick_type (int): 內外盤別{1: 內盤, 2: 外盤, 0: 無法判定}
chg_type (int): 漲跌註記{1: 漲停, 2: 漲, 3: 平盤, 4: 跌, 5: 跌停}
price_chg (decimal): 漲跌
pct_chg (decimal): 漲跌幅 (%)
simtrade (bool): 試撮
Amount (list of float): 成交額 (成交價)
AmountSum (list of float): 總成交額 (總成交價)
AvgPrice (list of float): 均價
Close (list of float): 成交價
Code (string): 商品代碼
Date (string): 日期 (yyyy/MM/dd)
DiffPrice (list of float): 漲跌
DiffRate (list of float): 漲跌幅 (%)
DiffType (list of int): 漲跌註記{1: 漲停, 2: 漲, 3: 平盤, 4: 跌, 5: 跌停}
High (list of float): 最高價(自開盤)
Low (list of float): 最低價(自開盤)
Open (float): 開盤價
TargetKindPrice float: 標的物價格
TickType (:list:int): 內外盤別{1: 內盤, 2: 外盤, 0: 無法判定}
Time (string): 時間 (HH:mm:ss.ffffff)
TradeAskVolSum (int): 賣盤成交總量 (lot)
TradeBidVolSum (int): 買盤成交總量 (lot)
VolSum (list of int): 總成交量 (lot)
Volume (list of int): 成交量 (lot)
BidAsk¶
範例¶
In
_api.Subscribe(
contract:_api.Contracts.Futures["TXF"]["TXF202210"],
quoteType:QuoteType.bidask,
version:QuoteVersion.v1
);
Out
Response Code: 0 | Event code: 16 | Info: QUO/v1/FOP/*/TFE/TXFJ2 | Event: SubscriptionOk
Exchange.TAIFEX BidAskFOPv1 {
"code": "TXFJ2",
"datetime": "2022/10/13 16:27:31.856000",
"bid_total_vol": 79,
"ask_total_vol": 98,
"bid_price": [
"12870",
"12869",
"12868",
"12867",
"12866"
],
"bid_volume": [
4,
13,
25,
16,
21
],
"diff_bid_vol": [
-10,
-3,
-6,
5,
-1
],
"ask_price": [
"12871",
"12872",
"12873",
"12874",
"12875"
],
"ask_volume": [
4,
11,
27,
30,
26
],
"diff_ask_vol": [
-2,
1,
13,
-9,
0
],
"first_derived_bid_price": 12869.0,
"first_derived_ask_price": 12873.0,
"first_derived_bid_vol": 1,
"first_derived_ask_vol": 2,
"underlying_price": 12810.73,
"simtrade": false
}
Response Code: 0 | Event code: 16 | Info: Q/*/TXFJ2 | Event: SubscriptionOk
Q/TFE/TXFJ2
Code: TXFJ2
Date: 2022/10/13
Time: 16:29:41.356000
BidVolSum: 78
AskVolSum: 121
DiffBidVolSum: 0
DiffAskVolSum: 0
BidPrice: [12875,12874,12873,12872,12871]
BidVolume: [1,10,20,33,14]
DiffBidVol: [0,0,0,0,0]
AskPrice: [12876,12877,12878,12879,12880]
AskVolume: [9,15,41,24,32]
DiffAskVol: [-1,0,0,0,0]
FirstDerivedBidPrice: 12872
FirstDerivedAskPrice: 12878
FirstDerivedBidVolume: 2
FirstDerivedAskVolume: 2
TargetKindPrice: 12810.73
屬性¶
BidAsk
code (string): 商品代碼
datetime (string): 時間
bid_total_vol (int): 委買量總計 (lot)
ask_total_vol (int): 委賣量總計 (lot)
bid_price (:List:decimal): 委買價
bid_volume (:List:int): 委買量 (lot)
diff_bid_vol (:List:int): 委買價增減量 (lot)
ask_price (:List:decimal): 委賣價
ask_volume (:List:int): 委賣量 (lot)
diff_ask_vol (:List:int): 委賣價增減量 (lot)
first_derived_bid_price (decimal): 衍生一檔委買價
first_derived_ask_price (decimal): 衍生一檔委賣價
first_derived_bid_vol (int): 衍生一檔委買量
first_derived_ask_vol (int): 衍生一檔委賣量
underlying_price (decimal): 標的物價格
simtrade (bool): 試撮
AskPrice (:List:float): 委賣價
AskVolSum (int): 委賣量總計(lot)
AskVolume (:List:int): 委賣量
BidPrice (:List:float): 委買價
BidVolSum (int): 委買量總計(lot)
BidVolume (:List:int): 委買量
Code (string): 商品代碼
Date (string): 日期 (yyyy/MM/dd)
DiffAskVol (:List:int): 賣價增減量(lot)
DiffAskVolSum (int):
DiffBidVol (:List:int): 買價增減量(lot)
DiffBidVolSum (int):
FirstDerivedAskPrice (float): 衍生一檔委賣價
FirstDerivedAskVolume (int): 衍生一檔委賣量
FirstDerivedBidPrice (float): 衍生一檔委買價
FirstDerivedBidVolume (int): 衍生一檔委買量
TargetKindPrice (float): 標的物價格
Time (string): 時間 (HH:mm:ss.ffffff)
Callback¶
預設狀況下我們將即時行情使用Console.WriteLine
的方式呈現。可根據個人需求修改函數。請避免在函數內進行運算。
In
public class Program
{
private static void myQuoteCB_v1(Exchange exchange, dynamic quote)
{
Console.WriteLine($"QuoteCB_v1 | Exchange.{exchange} {quote.GetType().Name} {quote}");
}
public static void Main(string[] args)
{
var _api = new Shioaji();
// version >= 1.0
var _accounts = _api.Login("YOUR_API_KEY", "YOUR_SECRET_KEY");
// version <1.0
// var _accounts = _api.Login("PERSON_ID", "PASSWORD");
_api.SetQuoteCallback_v1(myQuoteCB_v1);
_api.Subscribe(
_api.Contracts.Futures["TXF"]["TXF202210"],
QuoteType.bidask,
version:QuoteVersion.v1
);
Console.ReadKey();
}
}
public class Program
{
private static void myQuoteCB(string topic, Dictionary<string, dynamic> msg)
{
Console.WriteLine("myQuoteCB | Topic: " + topic);
foreach (var item in msg)
{
Console.WriteLine(item.Key + ": " + item.Value);
}
Console.WriteLine("-----------------------------------");
}
public static void Main(string[] args)
{
var _api = new Shioaji();
// version >= 1.0
var _accounts = _api.Login("YOUR_API_KEY", "YOUR_SECRET_KEY");
// version <1.0
// var _accounts = _api.Login("PERSON_ID", "PASSWORD");
_api.SetQuoteCallback(myQuoteCB);
_api.Subscribe(
_api.Contracts.Futures["TXF"]["TXF202210"],
QuoteType.bidask,
version:QuoteVersion.v0
);
Console.ReadKey();
}
}
Out
QuoteCB_v1 | Exchange.TAIFEX BidAskFOPv1 {
"code": "TXFJ2",
"datetime": "2022/10/13 16:36:58.481000",
"bid_total_vol": 92,
"ask_total_vol": 99,
"bid_price": [
"12893",
"12892",
"12891",
"12890",
"12889"
],
"bid_volume": [
6,
13,
36,
21,
16
],
"diff_bid_vol": [
-5,
0,
5,
0,
0
],
"ask_price": [
"12894",
"12895",
"12896",
"12897",
"12898"
],
"ask_volume": [
1,
12,
33,
24,
29
],
"diff_ask_vol": [
0,
0,
5,
-5,
0
],
"first_derived_bid_price": 12891.0,
"first_derived_ask_price": 12897.0,
"first_derived_bid_vol": 2,
"first_derived_ask_vol": 7,
"underlying_price": 12810.73,
"simtrade": false
}
myQuoteCB | Topic: Q/TFE/TXFJ2
Code: TXFJ2
Date: 2022/10/13
Time: 16:35:23.981000
BidVolSum: 91
AskVolSum: 108
DiffBidVolSum: 0
DiffAskVolSum: 0
BidPrice: [12890,12889,12888,12887,12886]
BidVolume: [10,19,22,21,19]
DiffBidVol: [1,0,0,0,0]
AskPrice: [12892,12893,12894,12895,12896]
AskVolume: [17,29,23,23,16]
DiffAskVol: [-1,0,0,0,0]
FirstDerivedBidPrice: 12890
FirstDerivedAskPrice: 12894
FirstDerivedBidVolume: 51
FirstDerivedAskVolume: 2
TargetKindPrice: 12810.73