Order book data function

7. Detailed real-time data on price steps within each order book

How to use the library after logging in. Detailed examples are provided at the end of this chapter.

event = client.BidAsk(tickers = tickers, callback = callback)

Paramtere

Parameter
Description
Data type
Required

tickers

Code name, including stock codes, index codes, derivative codes, and covered warrant codes. These codes are written in uppercase.

list [str]

Yes

callback

This is a user-defined function for data manipulation.

function

Yes

The data receiving class is BidAsk, with the following two methods:

callback function

This is a user-defined method for data manipulation, which will be passed as an argument when initializing the data receiving object. This method will have the following format:

//pseudocode
//callback_function
def name_of_callback(data: BidAskData):
    //do something

event = client.BidAsk(tickers = ['ticker_1','ticker_2',,,'ticker_n'], callback = name_of_callback)
event.start()
# tickers can include ticker, coveredwarrant, index and derivative.
event = client.BidAsk(tickers = ['ticker_1','ticker_2',,,'ticker_n'], callback = name_of_callback)
evente.start()

BidAskData has the following methods and attributes:

BidAskData has the following attributes:
Description

to_dataFrame( )

Returns all data attributes instead of individual ones, stored as a Pandas DataFrame.

Data BidAskData has the following attributes:

Name
Description
Data type

ComGroupCode

Company group code

str

StockType

Securities type

str

Ticker

Code name

str

TradingDate

Time

str

Timestamp

Time (rounded to seconds)

str

Spread

Best1Ask - Best1Bid.

float

SpreadDelta

Current spread tick - Previous spread tick

float

DepthImbalance

TotalBidVolume / (TotalBidVolume + TotalAskVolume).

float

TotalBuyTradeVolume

Total buy trading volume

int

TotalSellTradeVolum

Total sell trading volume

int

TotalBidVolume

Total bid volume

int

TotalAskVolume

Total ask volume

int

Best1Bid

Bid price level 1

float

Best2Bid

Bid price level 2

float

Best3Bid

Bid price level 3

float

Best4Bid

Bid price level 4

float

Best5Bid

Bid price level 5

float

Best6Bid

Bid price level 6

float

Best7Bid

Bid price level 7

float

Best8Bid

Bid price level 8

float

Best9Bid

Bid price level 9

float

Best10Bid

Bid price level 10

float

Best1Ask

Ask price level 1

float

Best2Ask

Ask price level 2

float

Best3Ask

Ask price level 3

float

Best4Ask

Ask price level 4

float

Best5Ask

Ask price level 5

float

Best6Ask

Ask price level 6

float

Best7Ask

Ask price level 7

float

Best8Ask

Ask price level 8

float

Best9Ask

Ask price level 9

float

Best10Ask

Ask price level 10

float

Best1BidVolume

Bid volume at bid price level 1

int

Best2BidVolume

Bid volume at bid price level 2

int

Best3BidVolume

Bid volume at bid price level 3

int

Best4BidVolume

Bid volume at bid price level 4

int

Best5BidVolume

Bid volume at bid price level 5

int

Best6BidVolume

Bid volume at bid price level 6

int

Best7BidVolume

Bid volume at bid price level 7

int

Best8BidVolume

Bid volume at bid price level 8

int

Best9BidVolume

Bid volume at bid price level 9

int

Best10BidVolume

Bid volume at bid price level 10

int

Best1AskVolume

Ask volume at bid price level 1

int

Best2AskVolume

Ask volume at bid price level 2

int

Best3AskVolume

Ask volume at bid price level 3

int

Best4AskVolume

Ask volume at bid price level 4

int

Best5AskVolume

Ask volume at bid price level 5

int

Best6AskVolume

Ask volume at bid price level 6

int

Best7AskVolume

Ask volume at bid price level 7

int

Best8AskVolume

Ask volume at bid price level 8

int

Best9AskVolume

Ask volume at bid price level 9

int

Best10AskVolume

Ask volume at bid price level 10

int

BidPriceDelta1

Current best bid price tick difference from previous tick

float

BidPriceDelta2

Current 2nd best bid price tick difference from previous tick.

float

BidPriceDelta3

Current 3rd best bid price tick difference from previous tick.

float

BidPriceDelta4

Current 4th best bid price tick difference from previous tick.

float

BidPriceDelta5

Current 5th best bid price tick difference from previous tick.

float

BidPriceDelta6

Current 6th best bid price tick difference from previous tick.

float

BidPriceDelta7

Current 7th best bid price tick difference from previous tick.

float

BidPriceDelta8

Current 8th best bid price tick difference from previous tick.

float

BidPriceDelta9

Current 9th best bid price tick difference from previous tick.

float

BidPriceDelta10

Current 10th best bid price tick difference from previous tick.

float

AskPriceDelta1

Current best ask price tick difference from previous tick.

float

AskPriceDelta2

Current 2nd best ask price tick difference from previous tick.

float

AskPriceDelta3

Current 3rd best ask price tick difference from previous tick.

float

AskPriceDelta4

Current 4th best ask price tick difference from previous tick.

float

AskPriceDelta5

Current 5th best ask price tick difference from previous tick.

float

AskPriceDelta6

Current 6th best ask price tick difference from previous tick.

float

AskPriceDelta7

Current 7th best ask price tick difference from previous tick.

float

AskPriceDelta8

Current 8th best ask price tick difference from previous tick.

float

AskPriceDelta9

Current 9th best ask price tick difference from previous tick.

float

AskPriceDelta10

Current 10th best ask price tick difference from previous tick.

float

BidVolumeDelta1

Current best bid volume tick difference from previous tick.

int

BidVolumeDelta2

Current 2nd best bid volume tick difference from previous tick.

int

BidVolumeDelta3

Current 3rd best bid volume tick difference from previous tick.

int

BidVolumeDelta4

Current 4th best bid volume tick difference from previous tick.

int

BidVolumeDelta5

Current 5th best bid volume tick difference from previous tick.

int

BidVolumeDelta6

Current 6th best bid volume tick difference from previous tick.

int

BidVolumeDelta7

Current 7th best bid volume tick difference from previous tick.

int

BidVolumeDelta8

Current 8th best bid volume tick difference from previous tick.

int

BidVolumeDelta9

Current 9th best bid volume tick difference from previous tick.

int

BidVolumeDelta10

Current 10th best bid volume tick difference from previous tick.

int

AskVolumeDelta1

Current best ask volume tick difference from previous tick.

int

AskVolumeDelta2

Current 2nd best ask volume tick difference from previous tick.

int

AskVolumeDelta3

Current 3rd best ask volume tick difference from previous tick.

int

AskVolumeDelta4

Current 4th best ask volume tick difference from previous tick.

int

AskVolumeDelta5

Current 5th best ask volume tick difference from previous tick.

int

AskVolumeDelta6

Current 6th best ask volume tick difference from previous tick.

int

AskVolumeDelta7

Current 7th best ask volume tick difference from previous tick.

int

AskVolumeDelta8

Current 8th best ask volume tick difference from previous tick.

int

AskVolumeDelta9

Current 9th best ask volume tick difference from previous tick.

int

AskVolumeDelta10

Current 10th best ask volume tick difference from previous tick.

int

VWAPBid

Average price that buyers are willing to pay.

float

VWAPAsk

Average price that sellers are willing to pay.

float

VWAPBidSpread

Difference between best bid price (Best1Bid) and VWAP Bid.

float

VWAPAskSpread

Difference between VWAP Ask and best ask price (Best1Ask).

float

VWAPBidAskSpread

Difference between VWAP Ask and VWAP Bid.

float

OrderFlowImbalance

VWAP Bid Spread / (VWAP Bid Spread + VWAP Ask Spread).

float

Example of Order Book Data (BidAskData):

import FiinQuantX as fq
from FiinQuantX import BidAskData
import pandas as pd
import time

client = fq.FiinSession(
    username='Enter your username',
    password='Enter your password'
)
client.login()

tickers = ['HPG','VNINDEX','VN30F1M']

def onTickerEvent(data: RealTimeData):
    print('----------------')
    print(data.to_dataFrame())
    # data.to_dataFrame().to_csv('callback.csv', mode='a', header=True)
Events = client.BidAsk(tickers=tickers, callback = onTickerEvent)
Events.start()

try:
    while not Events._stop: 
        time.sleep(1)
except KeyboardInterrupt:
    print("KeyboardInterrupt received, stopping...")
    Events.stop()

Last updated