Common

About 4 min

QuoteClient(client_config, logger=None, is_grab_permission=True)

When initiating a quotation interface call in the SDK, you need to use QuoteClient, which encapsulates all market-related API interface calls.

By default, QuoteClient will automatically preempt market permissions (is_grab_permission=True), At this time, you need to ensure that QuoteClient is a singleton, that is, you can instantiate QuoteClient at the module level, and import it when used elsewhere, otherwise you may encounter To the current limit problem of the market preemption interface. If you need to control the market permission preemption by yourself, you can set is_grab_permission to False.

grab_quote_permission Grab Quote Permission

QuoteClient.grab_quote_permission(market=Market.ALL, lang=None)

Description

Seize the market authority. When multiple devices share an account, only the main device will return the market information. Therefore, every time you switch devices, you need to preempt the market authority and set the current device as the master device. If you don't switch devices, you don't need to call

Note: After the Python sdk version 2.0.9, QuoteClient will call this interface by default to seize the permission when it is initialized, so there is no need to call it again.

If you request other market interface and return no permission error, you can use this interface to obtain the permission list of this account and check whether you have the corresponding permission

When a device that does not have the right to preempt market quotations requests real-time quotations, it will get the following error:

code=4 msg=4000:permission denied(current device does not have permission)

Argmuments

N/A

Response

list, Each of them is a dict composed of permission data

The dictionary has the following fields:

KEYVALUE
nameName of the quote permission subscription
expire_atExpiration time (-1 means never expire)

name description

name field valuedescription
hkStockQuoteLv2Hong Kong Stocks Lv2 permission, free Hong Kong Stocks API market for mainland IP, cannot be purchased separately, free for mainland users
hkStockQuoteLv2GlobalLv2 access to Hong Kong stocks, providing real-time quotation data, 10 orders, transaction details and brokerage queue, non-mainland users need to buy
usQuoteBasicU.S. stock Lv1 quotes, after purchasing Nasdaq Basic API quotes, you can get it in the API **Including Nasdaq, NYSE, NYSE MKT, etc. **Exchange listed securities (including U.S. stocks and ETFs, excluding U.S. stocks Lv1 real-time market information including futures and US stock options
usStockQuoteLv2TotalviewU.S. stock Lv2 quotes, After purchasing Nasdaq Basic+TotalView API quotes, you can get it in the API**Including Nasdaq, NYSE, NYSE MKT, etc. *Exchange listed securities (including U.S. stocks and ETFs, *Not including US stock futures and US stock options **) market information
usOptionQuoteU.S. stock options Lv1, data based on OPRA, displaying the latest price and best buy/sell data based on quotations from 16 exchanges
CMEFuturesQuoteLv2Chicago Mercantile Exchange Lv2 permission, after purchasing Chicago Mercantile Exchange Lv2 market data, you can obtain real-time market data of futures traded on CME through API. The futures categories traded by CME include Nasdaq, S&P 500 index futures and exchange rate futures, etc.
CBOOTFuturesQuoteLv2Chicago Board of Trade Lv2 permission, after purchasing Chicago Board of Trade Lv2 market data, you can obtain real-time market data of futures traded at CBOT through API, futures traded at CBOT include ** Dow Jones index futures, agricultural products and interest rates Futures** etc.
CBOEFuturesQuoteLv2Chicago Board Options Exchange Lv2 permission, after purchase, you can get L2 real-time market data of futures traded on Chicago Options Exchange via API
NYMEXFuturesQuoteLv2New York Mercantile Exchange Lv2 permission, after purchasing the New York Mercantile Exchange Lv2 market data, you can obtain real-time market data of futures traded on NYMEX through the API. The futures categories traded on NYMEX include US crude oil, natural gas and other energy futures.
COMEXFuturesQuoteLv2New York Mercantile Exchange Lv2 permission, after purchasing the New York Mercantile Exchange Lv2 market data, you can obtain real-time market data of futures traded on COMEX through API. The futures categories traded by COMEX include gold, silver and other metal futures.
HKEXFuturesQuoteLv2Hong Kong Exchange Lv2 authority, Hong Kong Futures Exchange Lv2 market authority includes Hong Kong Futures L2 and Hong Kong Options L2 market data (Mainland users can obtain option L2 market data for free, no need to purchase separately)
SGXFuturesQuoteLv2Singapore Exchange Lv2 permission, after purchase, you can get the L2 market data of futures traded on Singapore Futures Exchange via API
OSEFuturesQuoteLv2Osaka Exchange Lv2 permission, after purchase, you can get the L2 real-time market data of futures traded on Osaka Futures Exchange through API**
EUREXFuturesQuoteLv2European Exchange Lv2 permission, after purchase, you can obtain L2 real-time market data of futures traded on European Exchange via API

Example

from tigeropen.quote.quote_client import QuoteClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key file path', tiger_id='your tiger id', account='your account')
quote_client = QuoteClient(client_config)

permissions = quote_client.grab_quote_permission()
print(permissions)

Response

[{'name': 'usStockQuote', 'expire_at': 1698767999000}, {'name': 'usStockQuoteLv2Arca', 'expire_at': 1698767999000}, {'name': 'usStockQuoteLv2Totalview', 'expire_at': 1698767999000}, {'name': 'hkStockQuoteLv2', 'expire_at': 1698767999000}, {'name': 'usOptionQuote', 'expire_at': 1698767999000}]

get_quote_permission Query Current Quote Subscription

QuoteClient.get_quote_permission()

Description Use this function to query all your current quote permissions subscriptions.

Arguments

N/A

Return Same as grab_quote_permission

Example

from tigeropen.quote.quote_client import QuoteClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key file path', tiger_id='your tiger id', account='your account')
quote_client = QuoteClient(client_config)

permissions = quote_client.get_quote_permission()
print(permissions)

Response

[{'name': 'usStockQuote', 'expire_at': 1698767999000}, {'name': 'usStockQuoteLv2Arca', 'expire_at': 1698767999000}, {'name': 'usStockQuoteLv2Totalview', 'expire_at': 1698767999000}, {'name': 'hkStockQuoteLv2', 'expire_at': 1698767999000}, {'name': 'usOptionQuote', 'expire_at': 1698767999000}]

get_kline_quota

Get historical Kline quota details

Description

Query the number of used and remaining symbols according to this user's level, including stocks, futures, options corresponding to stocks (different options of the same stock, only occupy a symbol)

Parameters

ParameterTypeRequiredDescription
with_detailsboolNoWhether to return the requested symbol details, default is no

Return

Each of these items is as follows

fieldtypedescription
usedintused
remainintnumber left
methodstrapi method (kline: stock Kline; future_kline: futures Kline; option_kline: options Kline; history_timeline: stock history time line
detailslist[str]details of the used symbols

Examples

from tigeropen.quote.quote_client import QuoteClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
quote_client = QuoteClient(client_config)


result = quote_client.get_kline_quota()
print(result)

Return Example

[{'main': 2, 'used': 18, 'method': 'kline', 'details': ['AAPL', 'FB']} 
{'main': 10, 'used': 0, 'method': 'future_kline', 'details': []}.
 {'main': 20, 'used': 0, 'method': 'option_kline', 'details': []}. 
 {'main': 20, 'used': 0, 'method': 'history_timeline', 'details': []}]
Last update: