證券
利用訂閱商品檔的方式去取得即時行情。
Quote Parameters:
enum QuoteType {tick, bidask, quote}
bool intraday_odd: {true, false}
enum QuoteVersion: {v0, v1}
Tick¶
整股¶
In
_api.Subscribe(
contract:_api.Contracts.Stocks["TSE"]["2330"],
quoteType:QuoteType.tick,
version:QuoteVersion.v1
);
Out
Response Code: 0 | Event code: 16 | Info: TIC/v1/STK/*/TSE/2330 | Event: SubscriptionOk
Exchange.TSE TickSTKv1 {
"code": "2330",
"datetime": "2022/10/14 09:24:22.500106",
"open": 414.5,
"avg_price": 412.54,
"close": 410.5,
"high": 414.5,
"low": 409.0,
"amount": 821000.0,
"total_amount": 6589192000.0,
"volume": 2,
"total_volume": 15972,
"tick_type": 1,
"chg_type": 2,
"price_chg": 15.5,
"pct_chg": 3.92,
"bid_side_total_vol": 10146,
"ask_side_total_vol": 5826,
"bid_side_total_cnt": 1260,
"ask_side_total_cnt": 2102,
"closing_oddlot_shares": 0,
"fixed_trade_vol": 0,
"suspend": false,
"simtrade": false,
"intraday_odd": false
}
Response Code: 0 | Event code: 16 | Info: MKT/*/TSE/2330 | Event: SubscriptionOk
MKT/idcdmzpcr01/TSE/2330
Date: 2022/10/14
Time: 09:21:02.418956
Close: [411]
Volume: [1]
VolSum: [15736]
AmountSum: [6492300500]
TickType: [1]
盤中零股¶
In
_api.Subscribe(
contract:_api.Contracts.Stocks["TSE"]["2330"],
quoteType:QuoteType.tick,
intradayOdd:true,
version:QuoteVersion.v1
);
Out
Response Code: 0 | Event code: 16 | Info: TIC/v1/ODD/*/TSE/2330 | Event: SubscriptionOk
Exchange.TSE TickSTKv1 {
"code": "2330",
"datetime": "2022/10/14 09:26:02.545208",
"open": 411.0,
"avg_price": 427.697026,
"close": 410.0,
"high": 411.0,
"low": 410.0,
"amount": 3491560.0,
"total_amount": 87359256.0,
"volume": 8516,
"total_volume": 204255,
"tick_type": 2,
"chg_type": 2,
"price_chg": 15.0,
"pct_chg": 3.797468,
"bid_side_total_vol": 163264,
"ask_side_total_vol": 49507,
"bid_side_total_cnt": 4,
"ask_side_total_cnt": 3,
"closing_oddlot_shares": 0,
"fixed_trade_vol": 0,
"suspend": false,
"simtrade": true,
"intraday_odd": true
}
Response Code: 0 | Event code: 16 | Info: TIC/v2/*/TSE/2330/ODDLOT | Event: SubscriptionOk
TIC/v2/replay/TSE/2330/ODDLOT
Date: 2022/10/14
Time: 09:27:02.734685
Close: 410
TickType: 2
Shares: 12041
SharesSum: 204255
Simtrade: 1
屬性¶
Tick
code (string): 商品代碼
datetime (string): 時間
open (decimal): 開盤價
avg_price (decimal): 均價
close (decimal): 成交價
high (decimal): 最高價(自開盤)
low (decimal): 最低價(自開盤)
amount (decimal): 成交額 (NTD)
total_amount (decimal): 總成交額 (NTD)
volume (int): 成交量 (整股:張, 盤中零股: 股)
total_volume (int): 總成交量 (整股:張, 盤中零股: 股)
tick_type (int): 內外盤別{1: 內盤, 2: 外盤, 0: 無法判定}
chg_type (int): 漲跌註記{1: 漲停, 2: 漲, 3: 平盤, 4: 跌, 5: 跌停}
price_chg (decimal): 漲跌
pct_chg (decimal): 漲跌幅
bid_side_total_vol (int): 買盤成交總量 (整股:張, 盤中零股: 股)
ask_side_total_vol (int): 賣盤成交總量 (整股:張, 盤中零股: 股)
bid_side_total_cnt (int): 買盤成交筆數
ask_side_total_cnt (int): 賣盤成交筆數
closing_oddlot_shares (int): 盤後零股成交股數(股)
fixed_trade_vol (int): 定盤成交量 (整股:張, 盤中零股: 股)
suspend (bool): 暫停交易
simtrade (bool): 試撮
intraday_odd (int): 盤中零股 {0: 整股, 1:盤中零股}
Date (string): 日期 (yyyy/MM/dd)
Time (string): 時間 (HH:mm:ss.ffffff)
Close (:List:float): 成交價
TickType (:List:int): 內外盤別{1: 內盤, 2: 外盤, 0: 無法判定}
SharesSum (:List:int): 總成交量 (張)
Shares (:List:int): 成交量 (張)
Simtrade (bool): 試撮
BidAsk¶
整股¶
In
_api.Subscribe(
contract:_api.Contracts.Stocks["TSE"]["2330"],
quoteType:QuoteType.bidask,
version:QuoteVersion.v1
);
Out
Response Code: 0 | Event code: 16 | Info: QUO/v1/STK/*/TSE/2330 | Event: SubscriptionOk
Exchange.TSE BidAskSTKv1 {
"code": "2330",
"datetime": "2022/10/14 09:31:05.066623",
"bid_price": [
"410.5",
"410",
"409.5",
"409",
"408.5"
],
"bid_volume": [
22,
357,
101,
171,
89
],
"diff_bid_vol": [
0,
0,
0,
0,
0
],
"ask_price": [
"411",
"411.5",
"412",
"412.5",
"413"
],
"ask_volume": [
300,
185,
603,
220,
664
],
"diff_ask_vol": [
-1,
0,
0,
0,
0
],
"suspend": false,
"simtrade": false,
"intraday_odd": false
}
Response Code: 0 | Event code: 16 | Info: QUT/*/TSE/2330 | Event: SubscriptionOk
QUT/idcdmzpcr01/TSE/2330
Date: 2022/10/14
Time: 09:32:15.316453
BidPrice: [410.5,410,409.5,409,408.5]
AskPrice: [411,411.5,412,412.5,413]
BidVolume: [91,338,218,161,89]
AskVolume: [301,170,629,230,671]
盤中零股¶
In
_api.Subscribe(
contract:_api.Contracts.Stocks["TSE"]["2330"],
quoteType:QuoteType.bidask,
intradayOdd:true,
version:QuoteVersion.v1
);
Out
Response Code: 0 | Event code: 16 | Info: QUO/v1/ODD/*/TSE/2330 | Event: SubscriptionOk
Exchange.TSE BidAskSTKv1 {
"code": "2330",
"datetime": "2022/10/14 09:29:42.875584",
"bid_price": [
"410",
"409.5",
"409",
"408.5",
"408"
],
"bid_volume": [
18,
8840,
62404,
54036,
11476
],
"diff_bid_vol": [
15319,
-98508,
-40662,
52024,
6716
],
"ask_price": [
"410.5",
"411",
"411.5",
"412",
"412.5"
],
"ask_volume": [
27978,
44773,
12908,
126508,
314258
],
"diff_ask_vol": [
14264,
-15181,
-87825,
-124052,
409216
],
"suspend": false,
"simtrade": true,
"intraday_odd": true
}
Response Code: 0 | Event code: 16 | Info: QUO/v2/*/TSE/2330/ODDLOT | Event: SubscriptionOk
QUO/v2/replay/TSE/2330/ODDLOT
Date: 2022/10/14
Time: 09:28:42.631677
BidPrice: [410,409.5,409,408.5,408]
AskPrice: [410.5,411,411.5,412,412.5]
BidShares: [2432,9465,10197,53906,11176]
AskShares: [27317,43593,12812,126623,251203]
Simtrade: 1
屬性¶
BidAsk
code (str): 商品代碼
datetime (datetime): 時間
bid_price (:List:decimal): 委買價
bid_volume (:List:int): 委買量 (張)
diff_bid_vol (:List:int): 買價增減量 (張)
ask_price (:List:decimal): 委賣價
ask_volume (:List:int): 委賣量
diff_ask_vol (:List:int): 賣價增減量 (張)
suspend (bool): 暫停交易
simtrade (bool): 試撮
Date (datetime.date): 日期 (yyyy/MM/dd)
Time (time): 時間 (HH:mm:ss.ffffff)
BidPrice (:List:float): 委買價
AskPrice (:List:float): 委賣價
BidShares (:List:int): 委買量
AskShares (:List:int): 委賣量
Simtrade (bool): 試撮
Quote¶
In
_api.Subscribe(
contract:_api.Contracts.Stocks["TSE"]["2330"],
quoteType:QuoteType.quote,
version:QuoteVersion.v1
);
Out
Response Code: 0 | Event code: 16 | Info: QUO/v2/STK/*/TSE/2330 | Event: SubscriptionOk
Exchange.TSE QuoteSTKv1 {
"code": "2330",
"datetime": "2022/10/14 09:34:34.158334",
"open": 414.5,
"avg_price": 412.36,
"close": 411.5,
"high": 414.5,
"low": 409.0,
"amount": 411500.0,
"total_amount": 7285720500.0,
"volume": 0,
"total_volume": 17668,
"tick_type": 2,
"chg_type": 2,
"price_chg": 16.5,
"pct_chg": 4.17,
"bid_side_total_vol": 11425,
"ask_side_total_vol": 6243,
"bid_side_total_cnt": 1540,
"ask_side_total_cnt": 2299,
"closing_oddlot_shares": 0,
"closing_oddlot_close": 0.0,
"closing_oddlot_amount": 0.0,
"closing_oddlot_bid_price": 0.0,
"closing_oddlot_ask_price": 0.0,
"fixed_trade_vol": 0,
"fixed_trade_amount": 0.0,
"bid_price": [
"411.5",
"411",
"410.5",
"410",
"409.5"
],
"bid_volume": [
264,
117,
449,
461,
160
],
"diff_bid_vol": [
0,
-22,
0,
0,
0
],
"ask_price": [
"412",
"412.5",
"413",
"413.5",
"414"
],
"ask_volume": [
639,
261,
657,
286,
797
],
"diff_ask_vol": [
0,
0,
0,
0,
0
],
"avail_borrowing": 3717809,
"suspend": false,
"simtrade": false
}
屬性¶
Quote
code (string): 商品代碼
datetime (string): 時間
open (decimal): 開盤價
avg_price (decimal): 均價
close (decimal): 成交價
high (decimal): 最高價(自開盤)
low (decimal): 最低價(自開盤)
amount (decimal): 成交額 (NTD)
total_amount (decimal): 總成交額 (NTD)
volume (int): 成交量
total_volume (int): 總成交量
tick_type (int): 內外盤別
chg_type (int): 漲跌註記
price_chg (decimal): 漲跌價
pct_chg (decimal): 漲跌率
bid_side_total_vol (int): 買盤成交總量 (張)
ask_side_total_vol (int): 賣盤成交總量 (張)
bid_side_total_cnt (int): 買盤成交筆數
ask_side_total_cnt (int): 賣盤成交筆數
closing_oddlot_shares (int): 盤後零股成交股數
closing_oddlot_close (decimal): 盤後零股成交價
closing_oddlot_amount (decimal): 盤後零股成交額
closing_oddlot_bid_price (decimal): 盤後零股買價
closing_oddlot_ask_price (decimal): 盤後零股賣價
fixed_trade_vol (int): 定盤成交量 (張)
fixed_trade_amount (decimal): 定盤成交額
bid_price (:List:decimal): 買價
bid_volume (:List:int) 買量
diff_bid_vol (:List:int) 買價增減量
ask_price (:List:decimal): 賣價
ask_volume (:List:int) 賣量
diff_ask_vol (:List:int) 賣價增減量
avail_borrowing (int): 借券可用餘額
suspend (bool): 暫停交易
simtrade (bool): 試撮
Callback¶
預設狀況下我們將即時行情使用Console.WriteLine
的方式呈現。可根據個人需求修改函數。請避免在函數內進行運算。
Set Quote Callback¶
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.Stocks["TSE"]["2330"], QuoteType.bidask);
}
}
public class Program
{
private static void myQuoteCB(string topic, Dictionary<string, dynamic> msg)
{
Console.WriteLine($"QuoteCB | 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.Stocks["TSE"]["2330"], QuoteType.bidask);
Console.ReadKey();
}
}
Out
QuoteCB_v1 | Exchange.TSE BidAskSTKv1 {
"code": "2330",
"datetime": "2022/10/14 09:39:00.354081",
"bid_price": [
"411",
"410.5",
"410",
"409.5",
"409"
],
"bid_volume": [
577,
191,
364,
185,
148
],
"diff_bid_vol": [
0,
0,
0,
0,
0
],
"ask_price": [
"411.5",
"412",
"412.5",
"413",
"413.5"
],
"ask_volume": [
53,
609,
230,
750,
358
],
"diff_ask_vol": [
-4,
0,
0,
0,
0
],
"suspend": false,
"simtrade": false,
"intraday_odd": false
}
QuoteCB | Topic: QUT/idcdmzpcr01/TSE/2330
Date: 2022/10/14
Time: 09:37:02.268206
BidPrice: [411,410.5,410,409.5,409]
AskPrice: [411.5,412,412.5,413,413.5]
BidVolume: [107,132,563,188,150]
AskVolume: [34,592,258,675,299]