Skip to main content

Shioaji Realtime Kline Extension

An Extensions help you streaming with real-time data

Contributors Stargazers Issues PyPI Latest Release PyPI Downloads

Table Of Contents

About The Project

When you use Shioaji Python API for technical analysis, you may need real-time data, and in different time dimensions, this package can help you subscribe to tick data and convert it into Kbars type (exactly the same as Shioaji Kbars ), to assist you in converting from Kbars to use more immediate data.

If you have any ideas or suggestions, we sincerely welcome you to contact us via email, or by creating an issue.

Assuming this project has been of great help to you, you are welcome to support my continued efforts through the following means.

Donate with PayPal

ETH : 0xb25aD6A441E89cFCa7850bA47A0d74131374d616

Description

  1. To use the extension just initialize the object
import shioaji_realtime_kbars
Contracts = shioaji_realtime_kbars.ShioajiRealtimeKbars(api)
  1. Get the real-time Kbars data with function
shioaji_realtime_kbars.Kbars(
    contract: shioaji.contracts.BaseContract,
    period: str = '5min'
) -> shioaji.data.Kbars

ℹ️ period format can refer to the pandas document.

⚠️ If you using this extension, you start with the market is opened and transactions frequently time. The latest Kline will be a little error.

Example : I use this extension in 8:45:10 in future market. The 8:46 Kline will have a little error. Ths data after 8:47 will be correct. So run this extension before the market is opened.

Getting Started

This is an example of how you may give instructions on setting up your project locally.

pip install shioaji_realtime_kbars

Usage

kbars

Refer to the shioaji sample

import pandas as pd
kbars = api.kbars(
    contract=api.Contracts.Stocks["2330"], 
    start="2023-01-15", 
    end="2023-01-16", 
)
df = pd.DataFrame({**kbars})
df.ts = pd.to_datetime(df.ts)
df.tail(5)

Change to

Contracts = shioaji_realtime_kbars.ShioajiRealtimeKbars(api)
Contracts.subscribe(api.Contracts.Futures.MXF.MXFR1)
Contracts.subscribe(api.Contracts.Futures.TXF.TXFR1)

@api.on_tick_stk_v1()
def callback(exchange: Exchange, tick : TickSTKv1):
    Contracts.update(tick, "stk")

@api.on_tick_fop_v1()
def callback(exchange : Exchange, tick : TickFOPv1):
    Contracts.update(tick, "fop")
        
while True:
    MXFR1_1K = Contracts.kbars(api.Contracts.Futures.MXF.MXFR1, "1min")
    df = pd.DataFrame({**MXFR1_1K })
    df.ts = pd.to_datetime(df.ts)
    print(df.tail(2), end = "\n")
    MXFR1_5K = Contracts.kbars(api.Contracts.Futures.MXF.MXFR1, "5min")
    df = pd.DataFrame({**MXFR1_5K })
    df.ts = pd.to_datetime(df.ts)
    print(df.tail(2), end = "\n")

Callback funtion

shioaji_realtime_kbars.ShioajiRealtimeKbars.subscribe?

Signature:
shioaji_realtime_kbars.ShioajiRealtimeKbars.subscribe(
    contract: List[Union[shioaji.contracts.Option, shioaji.contracts.Future, shioaji.contracts.Stock, shioaji.contracts.Index]],
    last_days: int = 0,
    cb: Any = List[[callback_function, period]]
) -> None

Example

If you want to clearly write your strategy. You can refer to example

def strategy(period, kbars):
    print(period)
    df = pd.DataFrame({**kbars}, columns = ["ts", "Open", "High", "Low", "Close", "Volume", "Amount"])
    df.ts = pd.to_datetime(df.ts)

    ### Write your strategy here ###

    print(df.tail(5), end = "\n")

if __name__ == "__main__":

    api = sj.Shioaji(simulation = True)

    api.login(
        api_key=config.API_KEY, 
        secret_key=config.API_SECRET
    )

    Contracts = shioaji_realtime_kbars.ShioajiRealtimeKbars(api)
    Contracts.subscribe(api.Contracts.Futures.MXF.MXFR1, last_days = 3, cb = [[strategy, "1min"], [strategy, "5min"]])

    @api.on_tick_fop_v1()
    def callback(exchange : Exchange, tick : TickFOPv1):
        Contracts.update(tick, "fop")

    Event().wait()

Version

  • v1.1.1 (2026/5/22) Fix import crash on newer shioaji where KBars is a native, non-subclassable type
  • v1.1.0 (2024/2/27) Improve with memory allocation
  • v1.0.7 (2023/10/11) Add TSE, TFE simtrade filter, Fix kbars with no historical problem
  • v1.0.6 (2023/7/28) Fis display
  • v1.0.5 (2023/7/19) Add callback function
  • v1.0.4 (2023/7/17)
  • v1.0.3 (2023/6/30) Fix Stock kbars problem issue
  • v1.0.1 Fix Naming Problem
  • v1.0.0

Roadmap

See the open issues for a list of proposed features (and known issues).

Authors

Metadata

Release files for shioaji-realtime-kbars 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shioaji-realtime-kbars 1.1.2
File Size Uploaded Provenance Actions
shioaji_realtime_kbars-1.1.2.tar.gz 6.1 kB With provenance Details for shioaji_realtime_kbars-1.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for shioaji-realtime-kbars 1.1.2
File Interpreter ABI Platform Actions
shioaji_realtime_kbars-1.1.2-py3-none-any.whl Python 3 none any Details for shioaji_realtime_kbars-1.1.2-py3-none-any.whl

Total release size: 12.1 kB

Release files / shioaji_realtime_kbars-1.1.2.tar.gz

Download URL shioaji_realtime_kbars-1.1.2.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
817b36acdd08337fd17909d4a6206626c890b0ace5b436cbffb8de53cb9d6f09
BLAKE2b-256 checksum
How to use checksums
5345d981ccd32e6dce3e9f5b608e8573e219de2d488944fb69ac74d5b252b9f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 1, 2026.

Transparency log

Release files / shioaji_realtime_kbars-1.1.2-py3-none-any.whl

Download URL shioaji_realtime_kbars-1.1.2-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f2d13e468a7cb7307cc00e1388443b71b9de12cc9a7d564fdae4b7888230f6a7
BLAKE2b-256 checksum
How to use checksums
19d4d2957f7bc4223e50d9802bc07bc45543fa861d301bdf40f09678158c6e27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 1, 2026.

Transparency log

Security for shioaji-realtime-kbars 1.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for shioaji_realtime_kbars-1.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page