Skip to content

升版指南

1.0 為主要版本,這份文件協助使用者遷移到版本 1.0。

使用.Net Framework

使用 NuGet 安裝完後,需將您專案下的 libsodium.dll (packages\libsodium.1.0.16\runtimes\win-x86\native\libsodium.dll) 複製到您專案執行的目標平台目錄下(你的專案\bin\Debug)

登入

登入參數person_idpassword 變更為 api_keysecret_key。 您可以在 Token 深入了解如何取得 API Key。

In

using System;
using Sinopac.Shioaji;

Shioaji _api = new Shioaji();
var _accounts = _api.Login("YOUR_API_KEY", "YOUR_SECRET_KEY");
_api.ca_activate(
    "C:/ekey/551/person_id/S/Sinopac.pfx",
    "YOUR_CA_PASSWORD",
    "Person of this Ca"
);
using System;
using Sinopac.Shioaji;

Shioaji _api = new Shioaji();
var _accounts = _api.Login("YOUR_PERSON_ID", "YOUR_PASSWORD");
_api.ca_activate(
    "C:/ekey/551/person_id/S/Sinopac.pfx",
    "YOUR_CA_PASSWORD",
    "Person of this Ca"
);

Out

[{
account_type=F, person_id=A123456789, broker_id=F002000, account_id=1234567, signed=True, username=""
},{
account_type=H, person_id=A123456789, broker_id=9A95, account_id=1234567, signed=False, username=""
},{
account_type=S, person_id=A123456789, broker_id=9A95, account_id=1234567, signed=True, username=""
}]

證券下單

  • StockOrderType 更改為 OrderType
  • first_sell 更改為 daytrade_short,enum StockFirstSell更改為 DayTradeShort

Order

var _stockOrder = new StockOrder()
    {
        price = 15.55,
        quantity = 1,
        action = Action.Buy,
        price_type = StockPriceType.LMT,
        order_type = OrderType.ROD,
        order_lot = StockOrderLot.Common,
        daytrade_short = DayTradeShort.No,
        custom_field = "Test"
    };
  var _stockOrder = new StockOrder()
    {
        price = 15.55,
        quantity = 1,
        action = Action.Buy,
        price_type = StockPriceType.LMT,
        order_type = StockOrderType.ROD,
        order_lot = StockOrderLot.Common,
        daytrade_short = StockFirstSell.No,
        custom_field = "Test"
    };

委託回報

TFTOrder 更改為 StockOrder

Order Callback

OrderState.StockOrder {
    'operation': {
        'op_type': 'New',
        'op_code': '00',
        'op_msg': ''
    },
    'order': {
        'id': 'c21b876d',
        'seqno': '429832',
        'ordno': 'W2892',
        'action': 'Buy',
        'price': 12.0,
        'quantity': 10,
        'order_cond': 'Cash',
        'order_lot': 'Common',
        'custom_field': 'test',
        'order_type': 'ROD',
        'price_type': 'LMT'
    },
    'status': {
        'id': 'c21b876d',
        'exchange_ts': 1583828972,
        'modified_price': 0,
        'cancel_quantity': 0,
        'web_id': '137'
    },
    'contract': {
        'security_type': 'STK',
        'exchange': 'TSE',
        'code': '2890',
        'symbol': '',
        'name': '',
        'currency': 'TWD'
    }
}
OrderState.TFTOrder {
    'operation': {
        'op_type': 'New',
        'op_code': '00',
        'op_msg': ''
    },
    'order': {
        'id': 'c21b876d',
        'seqno': '429832',
        'ordno': 'W2892',
        'action': 'Buy',
        'price': 12.0,
        'quantity': 10,
        'order_cond': 'Cash',
        'order_lot': 'Common',
        'custom_field': 'test',
        'order_type': 'ROD',
        'price_type': 'LMT'
    },
    'status': {
        'id': 'c21b876d',
        'exchange_ts': 1583828972,
        'modified_price': 0,
        'cancel_quantity': 0,
        'web_id': '137'
    },
    'contract': {
        'security_type': 'STK',
        'exchange': 'TSE',
        'code': '2890',
        'symbol': '',
        'name': '',
        'currency': 'TWD'
    }
}

成交回報

TFTDeal 更改為 StockDeal

Deal Callback

OrderState.StockDeal {
    'trade_id': '12ab3456', 
    'exchange_seq': '123456', 
    'broker_id': 'your_broker_id', 
    'account_id': 'your_account_id', 
    'action': 'Buy', 
    'code': '2890', 
    'order_cond': 'Cash', 
    'order_lot': 'Common',
    'price': 12, 
    'quantity': 10,
    'web_id': '137',
    'custom_field': 'test',
    'ts': 1583828972
}
OrderState.TFTDeal {
    'trade_id': '12ab3456', 
    'exchange_seq': '123456', 
    'broker_id': 'your_broker_id', 
    'account_id': 'your_account_id', 
    'action': 'Buy', 
    'code': '2890', 
    'order_cond': 'Cash', 
    'order_lot': 'Common',
    'price': 12, 
    'quantity': 10,
    'web_id': '137',
    'custom_field': 'test',
    'ts': 1583828972
}

行情資料

注意

版本>=1.1將不再提供QuoteVersion.v0,請更改至QuoteVersion.v1。

Callback

Tick

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();
        var _accounts = _api.Login("YOUR_API_KEY", "YOUR_SECRET_KEY");

        _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();
        var _accounts = _api.Login("YOUR_API_KEY", "YOUR_SECRET_KEY");

        _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]

期貨下單

FuturesOrderType 更改為 OrderType

Order

var _futOptOrder = new FutOptOrder()
    {
        price = 13770,
        quantity = 1,
        action = Action.Buy,
        price_type = FuturePriceType.LMT,
        order_type = OrderType.ROD,
        octype = OCType.Auto
    };
var _futOptOrder = new FutOptOrder()
    {
        price = 17760,
        quantity = 1,
        action = Action.Buy,
        price_type = FuturePriceType.LMT,
        order_type = FutureOrderType.ROD,
        octype = OCType.Auto
    };

委託回報

FOrder 更改為 FuturesOrder

Order Event

OrderState.FuturesOrder {
    'operation': {
        'op_type': 'New', 
        'op_code': '00', 
        'op_msg': ''
    }, 
    'order': {
        'id': '02c347f7', 
        'seqno': '956201', 
        'ordno': 'kY00H', 
        'action': 'Sell', 
        'price': 17760.0, 
        'quantity': 1, 
        'order_cond': None, 
        'order_type': 'ROD', 
        'price_type': 'LMT', 
        'market_type': 'Night', 
        'oc_type': 'New', 
        'subaccount': ''
    }, 
    'status': {
        'id': '02c347f7', 
        'exchange_ts': 1625729890, 
        'modified_price': 0.0, 
        'cancel_quantity': 0,
        "web_id": "P"
    }, 
    'contract': {
        'security_type': 'FUT', 
        'code': 'TXF', 
        'exchange': 'TIM', 
        'delivery_month': '202107', 
        'strike_price': 0.0, 
        'option_right': 'Future'
    }
}
OrderState.FOrder {
    'operation': {
        'op_type': 'New', 
        'op_code': '00', 
        'op_msg': ''
    }, 
    'order': {
        'id': '02c347f7', 
        'seqno': '956201', 
        'ordno': 'kY00H', 
        'action': 'Sell', 
        'price': 17760.0, 
        'quantity': 1, 
        'order_cond': None, 
        'order_type': 'ROD', 
        'price_type': 'LMT', 
        'market_type': 'Night', 
        'oc_type': 'New', 
        'subaccount': ''
    }, 
    'status': {
        'id': '02c347f7', 
        'exchange_ts': 1625729890, 
        'modified_price': 0.0, 
        'cancel_quantity': 0,
        "web_id": "P"
    }, 
    'contract': {
        'security_type': 'FUT', 
        'code': 'TXF', 
        'exchange': 'TIM', 
        'delivery_month': '202107', 
        'strike_price': 0.0, 
        'option_right': 'Future'
    }
}

成交回報

FDeal 更改為 FuturesDeal

Deal Event

OrderState.FuturesDeal {
    "trade_id":"02c347f7",
    "seqno":"956344",
    "ordno":"ky00N11O",
    "exchange_seq":"a0000060",
    "broker_id":"F002000",
    "account_id":"9104000",
    "action":"Sell",
    "code":"TXF",
    "price":17650.0,
    "quantity":4,
    "subaccount":"",
    "security_type":"FUT",
    "delivery_month":"202107",
    "strike_price":0.0,
    "option_right":"Future",
    "market_type":"Day",
    "ts":1625800369
}
OrderState.FDeal {
    "trade_id":"02c347f7",
    "seqno":"956344",
    "ordno":"ky00N11O",
    "exchange_seq":"a0000060",
    "broker_id":"F002000",
    "account_id":"9104000",
    "action":"Sell",
    "code":"TXF",
    "price":17650.0,
    "quantity":4,
    "subaccount":"",
    "security_type":"FUT",
    "delivery_month":"202107",
    "strike_price":0.0,
    "option_right":"Future",
    "market_type":"Day",
    "ts":1625800369
}

歷史行情

Ticks 新增 QueryType

帳務資訊

重新命名API

1. ListSettlements 更名為 Settlements
2. ListProfitLossSum 更名為 ListProfitLossSummary

新增 API

ListPositionDetail

欲瞭解更多帳務API,請參見

最後在GITHUB上給我們支持與鼓勵吧 👍👍👍 github