Skip to main content

Python client for send order to Concords Securities.

Project description

conrich

PyPI PyPI - Python Version PyPI - Format PyPI - License PyPI - Downloads contact

康和綜合證券程式下單API整合了.net framework 4.5架構下的交易介面,讓使用者可以輕鬆的運用python執行快速下單。

conrich is a securities, futures, option API, which send orders to Concord Securities Group. This package integrated with .net framework 4.5, and is compatible with Python 3.5+. It is distributed under the MIT license.

Installation

Preinstall

API usage needs application in advance. In order to use this package, please contact us.

Binaries

simply use pip to install

pip install conrich

Quick Starts

Login

from conrich import StockAPI

agent = StockAPI()
agent.login("YOUR_PERSON_ID", "YOUR_PASSWORD")
from conrich import FuturesAPI

agent = FuturesAPI()
agent.login("YOUR_PERSON_ID", "YOUR_PASSWORD")
from conrich import ForeignFuturesAPI

agent = ForeignFuturesAPI()
agent.login("YOUR_PERSON_ID", "YOUR_PASSWORD")

Place Order

Stock

from conrich.Stock import constant

result = agent.order(action = constant.Action.NEW_ORDER.value,
                     branch_no = '8450',
                     account_no = "YOUR_ACCOUNT",
                     lot_type = constant.LotType.ROUND_LOT.value,
                     order_type = constant.OrderType.ORDINARY.value,
                     side = constant.Side.BUY.value,
                     day_trade_flag = constant.DayTradeFlag.N.value,
                     symbol = '6016',
                     quantity = 1,
                     price = 10.0, 
                     price_flag = constant.PriceFlag.FIX.value,
                     time_in_force = constant.TimeInForce.ROD.value)

Futures

from conrich.Futures import constant

result = agent.order(action = constant.Action.NEW_ORDER.value,
                     branch_no = 'F029000',
                     account_no = "YOUR_ACCOUNT",
                     market_type = constant.Market.FUTURES.value,
                     compound_type = constant.CompoundType.FUTURES_SINGLE.value,
                     commodity = 'TXFI0',
                     time_in_force = constant.TimeInForce.ROD.value,
                     writeoff = constant.WriteOff.AUTO.value,
                     order_type = constant.OrderType.LIMIT.value,
                     side = constant.Side.BUY.value,
                     quantity = 1,
                     price = 12000.00)

Foreign Futures

agent.order(action=constant.Action.NEW_ORDER.value,
            branch_no = 'F029000',
            account_no = "YOUR_ACCOUNT",
            exchange = 'NYM',
            side1 = constant.Side.BUY.value,
            market_type1 = constant.Market.FUTURES.value,
            commodity1 = 'QM',
            commodity_month1 = '202010',
            strike_price1 = 0,
            put_call1 = constant.PutCall.NONE.value,
            side2 = '',
            market_type2 = '',
            commodity2 = '',
            commodity_month2 = '',
            strike_price2 = 0,
            put_call2 = constant.PutCall.NONE.value,
            order_type = constant.ForeignOrderType.LIMIT.value,
            price = 0,
            price_numerator = 0,
            price_denominator = 0,
            stop_price = 42.95,
            stop_price_numerator = 0,
            stop_price_denominator = 0,
            quantity = 1,
            writeoff = constant.Writeoff.OPEN.value)

Register Event

If you want to catch order or match report, one can define a function and register

Stock

def OrderReportHandler(result, msg):
        order_result = {'result'    : result.ResultType,
                        'status'    : result.StatusCode,
                        'desc'      : result.CodeDesc,
                        'order_guid'    : result.OrderGuid,
                        'net_no'    : result.ClOrdID
                        }

        if result.ResultType=='1':
            report = result.ExcReport
            exe_report = {'order_id'  : report.OrderID,
                        'orig_net_no'   : report.OrigClOrdID,
                        'execute_status'    : report.ExecType,
                        'account_no'    : report.Account,
                        'symbol'    : report.Symbol,
                        'side'      : report.Side,
                        'quantity'  : report.OrderQty,
                        'price'     : report.Price,
                        'strike_quantity'   : report.LastQty,
                        'strike_price'   : report.LastPx,
                        'transaction_time'  : report.TransactTime}

agent.OrderReportEvent += OrderReportHandler

Futures

def OrderReportHandler(code, msg):
    dict_msg = dict((agent.msg_tag[k], v) for k,v in [tag.split('=') for tag in msg.split('|')])
    print(dict_msg)

agent.OnFOrderReport += OrderReportHandler

Quote

When you want to initiate a quote server, you should open and connect to 康和金好康 first.

from conrich import QuoteServer

def test_get_quote(commodity, topic, value):
    print('[{}][{}] {}'.format(commodity, topic, value))

agent = QuoteServer()
agent.OnQuoteUpdate += test_get_quote

agent.register_topic('2330.TW','Bid')
agent.register_topic('2330.TW','Ask')

topic1 = agent.code_convert(commodity='TXO', commodity_type='P', strike_price=12500, expire_date=datetime(2020, 10, 18), after_hour=True)
agent.register_topic(topic1, 'Bid')
topic2 = agent.code_convert(commodity='TX', commodity_type='F', strike_price=0, expire_date=datetime(2020, 10, 18), after_hour=False)
agent.register_topic(topic2, 'Ask')

Reference

FuturesAPI

https://www.concords.com.tw/download/20200318_證券API客戶使用元件及文件.zip https://www.concordfutures.com.tw/WebSiteUpload//Files/Document/20200728_期貨API.zip

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

conrich-0.7.7-cp38-cp38-win_amd64.whl (3.9 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

conrich-0.7.7-cp38-cp38-win32.whl (3.9 MB view hashes)

Uploaded CPython 3.8 Windows x86

conrich-0.7.7-cp37-cp37m-win_amd64.whl (3.9 MB view hashes)

Uploaded CPython 3.7m Windows x86-64

conrich-0.7.7-cp37-cp37m-win32.whl (3.9 MB view hashes)

Uploaded CPython 3.7m Windows x86

conrich-0.7.7-cp36-cp36m-win_amd64.whl (3.9 MB view hashes)

Uploaded CPython 3.6m Windows x86-64

conrich-0.7.7-cp36-cp36m-win32.whl (3.9 MB view hashes)

Uploaded CPython 3.6m Windows x86

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page