Skip to main content

An Extensions help you streaming with real-time data

Project description


Shioaji Realtime Kline Extension

An Extensions help you streaming with real-time data

Contributors Stargazers Issues

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.

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

:information_source: period format can refer to the pandas document.

:warning: 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

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")

Version

v1.0.4 (2023/7/17)

* Fix resamplind will have some NaN rows

v1.0.3 (2023/6/30)

v1.0.2 (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

Project details


Download files

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

Source Distribution

shioaji_realtime_kbars-1.0.4.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

shioaji_realtime_kbars-1.0.4-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

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