Common
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:
KEY | VALUE |
---|---|
name | Name of the quote permission subscription |
expire_at | Expiration time (-1 means never expire) |
name description
name field value | description |
---|---|
hkStockQuoteLv2 | Hong Kong Stocks Lv2 permission, free Hong Kong Stocks API market for mainland IP, cannot be purchased separately, free for mainland users |
hkStockQuoteLv2Global | Lv2 access to Hong Kong stocks, providing real-time quotation data, 10 orders, transaction details and brokerage queue, non-mainland users need to buy |
usQuoteBasic | U.S. stock Lv1 quotes, after purchasing quotes, you can get it in the API Exchange listed securities (including U.S. stocks and ETFs, excluding U.S. stocks Lv1 real-time market information including futures and US stock options |
usStockQuoteLv2Totalview | U.S. stock Lv2 quotes, After purchasing API quotes, you can get it in the API Exchange listed securities (including U.S. stocks and ETFs,* *Not including US stock futures and US stock options **) market information |
usOptionQuote | U.S. stock options Lv1, displaying the latest price and best buy/sell data based on quotations from 16 exchanges |
CMEFuturesQuoteLv2 | Chicago 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. |
CBOOTFuturesQuoteLv2 | Chicago 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. |
CBOEFuturesQuoteLv2 | Chicago Board Options Exchange Lv2 permission, after purchase, you can get L2 real-time market data of futures traded on Chicago Options Exchange via API |
NYMEXFuturesQuoteLv2 | New 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. |
COMEXFuturesQuoteLv2 | New 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. |
HKEXFuturesQuoteLv2 | Hong 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) |
SGXFuturesQuoteLv2 | Singapore Exchange Lv2 permission, after purchase, you can get the L2 market data of futures traded on Singapore Futures Exchange via API |
OSEFuturesQuoteLv2 | Osaka Exchange Lv2 permission, after purchase, you can get the L2 real-time market data of futures traded on Osaka Futures Exchange through API** |
EUREXFuturesQuoteLv2 | European 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
Parameter | Type | Required | Description |
---|---|---|---|
with_details | bool | No | Whether to return the requested symbol details, default is no |
Return
Each of these items is as follows
field | type | description |
---|---|---|
used | int | used |
remain | int | number left |
method | str | api method (kline: stock Kline; future_kline: futures Kline; option_kline: options Kline; history_timeline: stock history time line |
details | list[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': []}]