数字货币

初始化

本页所有示例均假设已完成以下初始化:

from tigeropen.quote.quote_client import QuoteClient
from tigeropen.tiger_open_config import TigerOpenClientConfig

client_config = TigerOpenClientConfig(props_path='your_config_directory_path')
quote_client = QuoteClient(client_config)

详见准备工作。


获取所有代码列表

QuoteClient.get_symbols(sec_type=SecurityType.CC)

说明

获取所有数字货币的代码列表。

参数

参数名类型是否必填描述
sec_typestr 或 SecurityTypeYes固定为 SecurityType.CC 或 "CC"

返回

类型

list

示例

from tigeropen.common.consts import SecurityType


symbols = quote_client.get_symbols(sec_type=SecurityType.CC)
print(symbols)

返回示例

['APT.USD', 'IOTX.USD', 'USDT.USD', 'DYDX.USD', 'DOGE.USD', 'KAIA.USD', 'ATOM.USD', 'COMP.USD', 'UNI.USD', 'AAVE.USD', 'LDO.USD', 'LINK.USD', 'SNX.USD', 'OP.USD', 'DOT.USD', 'POL.USD', 'BTC.USD', 'SOL.USD', 'ARB.USD', 'TON.USD', 'AVAX.USD', 'MKR.USD', 'IMX.USD', 'ETH.USD', 'LTC.USD']

请求频率

基础限流为 10 次/分钟。股票和数字货币的 get_symbols() 调用映射到同一接口,共享此限流额度。

获取实时行情

QuoteClient.get_cc_briefs(symbols, include_hour_trading=False, lang=None, sec_type=None)

说明

获取数字货币实时行情。

参数

参数名类型是否必填描述
symbolslist[str]Yes代码的列表,最多 50 只,如 ['BTC', 'ETH']
include_hour_tradingboolNo是否返回盘前盘后相关字段,默认 False
langLanguageNo支持的语言;省略时使用 QuoteClient 的客户端配置语言,未配置时为 en_US
sec_typestr 或 SecurityTypeNo合约类型;get_cc_briefs 是 get_stock_briefs 的别名,不会自动注入 CC,调用时请显式传 SecurityType.CC

返回

pandas.DataFrame

结构如下:

COLUMN类型描述
symbolstr证券代码
openfloat开盘价
highfloat最高价
lowfloat最低价
closefloat收盘价
pre_closefloat前收价
latest_pricefloat最新价
latest_timeint最新成交时间,毫秒单位数字时间戳
ask_pricefloat卖一价
ask_sizeint卖一量
bid_pricefloat买一价
bid_sizeint买一量
volumeint成交量(整数部分)
volume_decimalfloat成交量(含小数,数字货币专用)
amountfloat成交额
changefloat涨跌额
change_ratefloat涨跌幅
amplitudefloat振幅
adj_pre_closefloat复权前收价
statusstr交易状态

示例

import pandas as pd
from tigeropen.common.consts import SecurityType


result = quote_client.get_cc_briefs(symbols=['BTC', 'ETH'], sec_type=SecurityType.CC)
# 转置后完整展示字段,避免宽表在不同终端宽度下自动换行。
print(result.set_index('symbol').transpose().to_string())

返回示例

symbol                  BTC.USD
open                    80296.94
high                    81453.44
low                     79575.65
close                   79724.82
pre_close               80365.73
latest_price            79724.82
latest_time       1787900865911
amount             31471105.26223
change                    -640.91
change_rate             -0.007975
volume_decimal         391.89212

请求频率

基础限流为 120 次/分钟。get_stock_briefs() 与 get_cc_briefs() 映射到同一接口,共享此限流额度。

获取 K 线数据

QuoteClient.get_bars(symbols, sec_type=SecurityType.CC, period=BarPeriod.DAY, begin_time=-1, end_time=-1, limit=251)

说明

获取数字货币 K 线数据,包括:1 分、60 分、天、周、月级别。每次请求最多返回 1200 条记录;需要更长时间范围时,请按日期区间分段请求。接口支持按照日期区间或指定日期查询。

分钟级别 K:BTC 支持最早 2024 年 3 月 27 日开始的数据
日 K 及以上(日/周/月/年):BTC 支持最早 2010 年 7 月 13 日开始的数据

参数

参数名类型是否必填描述
symbolslist[str]Yes证券代码列表,单次上限:50,其中 A 股上限:30, 如 ['AAPL', 'GOOG']
sec_typestr 或 SecurityTypeYes固定为 SecurityType.CC 或 "CC"
periodBarPeriodNo获取的 K 线周期。默认 BarPeriod.DAY,可以使用 tigeropen.common.consts.BarPeriod 下提供的枚举常量,1min, 60min, day, week, month
begin_timeint 或 strNo区间查询的开始时间, 建议使用时间戳, 避免不同市场的时区问题
end_timeint 或 strNo区间查询的截止时间
limitintNo限制数据的条数。默认 251,最大 1200

返回

pandas.DataFrame

结构如下:

参数名类型描述
timeint毫秒时间戳,如 1639371600000
openfloatBar 的开盘价
closefloatBar 的收盘价
highfloatBar 的最高价
lowfloatBar 的最低价
volume_decimalfloatBar 的小数成交量

数字货币返回 volume_decimal 小数成交量,可能不返回整数 volume 字段;股票则返回整数 volume,不返回 volume_decimal。

示例

import pandas as pd
from tigeropen.common.consts import SecurityType



bars = quote_client.get_bars(['BTC.USD'], sec_type=SecurityType.CC)

返回示例

    symbol      open     close      high       low  volume_decimal           time
0  BTC.USD  82808.12  82780.21  82808.12  82772.25         0.29135  1769749140000
1  BTC.USD  82810.81  82803.37  82810.81  82803.37         0.04455  1769749080000
2  BTC.USD  82823.91  82810.17  82823.91  82791.82         0.04930  1769749020000

请求频率

基础限流为 60 次/分钟。股票和数字货币的 get_bars() 调用映射到同一接口,共享此限流额度。



获取最近一个交易日的分时数据

QuoteClient.get_timeline(symbols, sec_type=SecurityType.CC, begin_time=-1)

说明

获取最近一个交易日的分时数据。分时数据类似于分钟 K 线,每分钟生成一条记录。仅支持查询最新交易日的数据。

参数

参数名类型是否必填描述
symbolslist[str]Yes代码列表,单次上限 10 只
begin_timestrNo获取分时数据的起始时间, 支持毫秒级别的时间戳,或日期时间字符串。如 1639386000000 或 '2019-06-07 23:00:00' 或 '2019-06-07',默认返回当天数据
sec_typestr 或 SecurityTypeYes固定为 SecurityType.CC 或 "CC"

返回

pandas.DataFrame

结构如下:

COLUMN类型描述
symbolstr证券代码
pre_closefloat前收价
trade_sessionstr交易时段,如 "Regular"
timeint精确到毫秒的时间戳,如 1639386000000
pricefloat当前分钟的收盘价
volume_decimalfloat这一分钟的小数成交量

数字货币当前分时返回 volume_decimal 小数成交量,可能不返回整数 volume 字段。该字段不适用于股票或历史分时。

示例

import pandas as pd
from tigeropen.common.consts import SecurityType



timeline = quote_client.get_timeline(['BTC.USD'], sec_type=SecurityType.CC)

返回示例

    symbol  pre_close trade_session           time     price  volume_decimal
0  BTC.USD   77517.15       Regular  1770040440000  77917.75         0.01902
1  BTC.USD   77517.15       Regular  1770040500000  77999.83         0.06813
2  BTC.USD   77517.15       Regular  1770040560000  78150.00         0.06568
3  BTC.USD   77517.15       Regular  1770040620000  78159.46         0.07281

请求频率

基础限流为 120 次/分钟。股票和数字货币的 get_timeline() 调用映射到同一接口,共享此限流额度。


Did this page help you?