1.4 Binance_interface API U本位合约行情

Binance_interface API U本位合约行情

1. API U本位合约行情接口总览

方法 解释 Path
get_ping 测试服务器连通性 PING /fapi/v1/ping
get_time 获取服务器时间 /fapi/v1/time
get_exchangeInfo 获取交易规则和交易对 /fapi/v1/exchangeInfo
get_depth 深度信息 /fapi/v1/depth
get_trades 近期成交 /fapi/v1/trades
get_historicalTrades 查询历史成交(MARKET_DATA) /fapi/v1/historicalTrades
get_aggTrades 近期成交(归集) /fapi/v1/aggTrades
get_klines K线数据 /fapi/v1/klines
get_continuousKlines 连续合约K线数据 /fapi/v1/continuousKlines
get_indexPriceKlines 价格指数K线数据 /fapi/v1/indexPriceKlines
get_markPriceKlines 标记价格K线数据 /fapi/v1/markPriceKlines
get_premiumIndexKlines 溢价指数K线数据 /fapi/v1/premiumIndexKlines
get_premiumIndex 最新标记价格和资金费率 /fapi/v1/premiumIndex
get_fundingRate 查询资金费率历史 /fapi/v1/fundingRate
get_fundingInfo 查询资金费率信息 /fapi/v1/fundingInfo
get_ticker_24hr 24hr价格变动情况 /fapi/v1/ticker/24hr
get_ticker_price_v1 最新价格 /fapi/v1/ticker/price
get_ticker_price 最新价格V2 /fapi/v2/ticker/price
get_ticker_bookTicker 当前最优挂单 /fapi/v1/ticker/bookTicker
get_openInterest 获取未平仓合约数 /fapi/v1/openInterest
get_delivery_price 季度合约历史结算价 /futures/data/delivery-price
get_openInterestHist 合约持仓量 /futures/data/openInterestHist
get_topLongShortAccountRatio 大户账户数多空比 /futures/data/topLongShortAccountRatio
get_topLongShortPositionRatio 大户持仓量多空比 /futures/data/topLongShortPositionRatio
get_globalLongShortAccountRatio 多空持仓人数比 /futures/data/globalLongShortAccountRatio
get_takerlongshortRatio 合约主动买卖量 /futures/data/takerlongshortRatio
get_basis 基差 /futures/data/basis
get_lvtKlines 杠杆代币历史净值K线 /fapi/v1/lvtKlines
get_indexInfo 综合指数交易对信息 /fapi/v1/indexInfo
get_assetIndex 多资产模式资产汇率指数 /fapi/v1/assetIndex
get_constituents 查询指数价格成分 /fapi/v1/constituents

2. 模型实例化

python 复制代码
import datetime
from binance_interface.api import UM
from binance_interface.app.utils import eprint
python 复制代码
# 转发:需搭建转发服务器,可参考:https://github.com/pyted/binance_resender
proxy_host = None
um = UM(
    proxy_host=proxy_host
)
market = um.market

3. U本位合约实时行情

3.1 当前最优挂单 get_ticker_bookTicker

python 复制代码
# 现货全部产品
bookTicker_result = market.get_ticker_bookTicker()
eprint(bookTicker_result, data_length=5)

输出:

text 复制代码
>>> {'code': 200,
>>>  'data': [{'symbol': 'BTCUSDT',
>>>            'bidPrice': '40158.10',
>>>            'bidQty': '1.750',
>>>            'askPrice': '40158.20',
>>>            'askQty': '7.586',
>>>            '...': '......'},
>>>           {'symbol': 'ETHUSDT',
>>>            'bidPrice': '2222.27',
>>>            'bidQty': '5.638',
>>>            'askPrice': '2222.28',
>>>            'askQty': '27.227',
>>>            '...': '......'},
>>>           {'symbol': 'BCHUSDT',
>>>            'bidPrice': '235.89',
>>>            'bidQty': '1.539',
>>>            'askPrice': '235.90',
>>>            'askQty': '4.531',
>>>            '...': '......'},
>>>           {'symbol': 'XRPUSDT',
>>>            'bidPrice': '0.5139',
>>>            'bidQty': '22041.0',
>>>            'askPrice': '0.5140',
>>>            'askQty': '101329.3',
>>>            '...': '......'},
>>>           {'symbol': 'EOSUSDT',
>>>            'bidPrice': '0.690',
>>>            'bidQty': '162800.4',
>>>            'askPrice': '0.691',
>>>            'askQty': '116329.8',
>>>            '...': '......'},
>>>           '......'],
>>>  'msg': ''}
python 复制代码
# 现货单个交易对
bookTicker_result = market.get_ticker_bookTicker(symbol='BTCUSDT')
eprint(bookTicker_result)

输出:

text 复制代码
>>> {'code': 200,
>>>  'data': {'symbol': 'BTCUSDT',
>>>           'bidPrice': '40148.30',
>>>           'bidQty': '0.808',
>>>           'askPrice': '40148.40',
>>>           'askQty': '5.244',
>>>           'time': 1706245394375,
>>>           'lastUpdateId': 3888877129825},
>>>  'msg': ''}

3.2 最新价格 get_ticker_price

python 复制代码
# 现货全部产品
price_result = market.get_ticker_price()
eprint(price_result, data_length=5)

输出:

text 复制代码
>>> {'code': 200,
>>>  'data': [{'symbol': 'NEARUSDT', 'price': '2.7580', 'time': 1706245389313},
>>>           {'symbol': '1000SATSUSDT', 'price': '0.0004072', 'time': 1706245399913},
>>>           {'symbol': 'UMAUSDT', 'price': '5.321000', 'time': 1706245400559},
>>>           {'symbol': 'GALAUSDT', 'price': '0.02223', 'time': 1706245396551},
>>>           {'symbol': 'MINAUSDT', 'price': '1.0101000', 'time': 1706245396476},
>>>           '......'],
>>>  'msg': ''}
python 复制代码
# 现货单个产品
price_result = market.get_ticker_price(symbol='BTCUSDT')
eprint(price_result)

输出:

text 复制代码
>>> {'code': 200, 'data': {'symbol': 'BTCUSDT', 'price': '40146.70', 'time': 1706245405158}, 'msg': ''}

3.3 24hr价格变动情况 get_ticker_24hr

python 复制代码
# 现货全部产品
hr24_result = market.get_ticker_24hr()
eprint(hr24_result, data_length=5)

输出:

text 复制代码
>>> {'code': 200,
>>>  'data': [{'symbol': 'ATAUSDT',
>>>            'priceChange': '0.0020',
>>>            'priceChangePercent': '2.389',
>>>            'weightedAvgPrice': '0.0843',
>>>            'lastPrice': '0.0857',
>>>            '...': '......'},
>>>           {'symbol': 'XMRUSDT',
>>>            'priceChange': '6.70',
>>>            'priceChangePercent': '4.404',
>>>            'weightedAvgPrice': '156.27',
>>>            'lastPrice': '158.82',
>>>            '...': '......'},
>>>           {'symbol': 'BLUEBIRDUSDT',
>>>            'priceChange': '0.10800',
>>>            'priceChangePercent': '1.381',
>>>            'weightedAvgPrice': '7.88532',
>>>            'lastPrice': '7.92700',
>>>            '...': '......'},
>>>           {'symbol': 'POLYXUSDT',
>>>            'priceChange': '0.0028000',
>>>            'priceChangePercent': '1.808',
>>>            'weightedAvgPrice': '0.1557668',
>>>            'lastPrice': '0.1577000',
>>>            '...': '......'},
>>>           {'symbol': 'ATOMUSDT',
>>>            'priceChange': '0.142',
>>>            'priceChangePercent': '1.546',
>>>            'weightedAvgPrice': '9.205',
>>>            'lastPrice': '9.327',
>>>            '...': '......'},
>>>           '......'],
>>>  'msg': ''}
python 复制代码
# 现货单个产品
hr24_result = market.get_ticker_24hr(symbol='BTCUSDT')
eprint(hr24_result)

输出:

text 复制代码
>>> {'code': 200,
>>>  'data': {'symbol': 'BTCUSDT',
>>>           'priceChange': '253.80',
>>>           'priceChangePercent': '0.636',
>>>           'weightedAvgPrice': '39934.69',
>>>           'lastPrice': '40148.20',
>>>           'lastQty': '0.022',
>>>           'openPrice': '39894.40',
>>>           'highPrice': '40300.00',
>>>           'lowPrice': '39535.30',
>>>           'volume': '209588.044',
>>>           'quoteVolume': '8369834245.01',
>>>           'openTime': 1706158980000,
>>>           'closeTime': 1706245408978,
>>>           'firstId': 4527594884,
>>>           'lastId': 4530284646,
>>>           'count': 2689755},
>>>  'msg': ''}

4. 历史K线 get_klines

python 复制代码
# 测试时间
startDatetime = '2023-01-01 00:00:00'
endDatetime = '2023-01-01 00:05:00'
startTime = int(datetime.datetime.strptime(startDatetime, '%Y-%m-%d %H:%M:%S').timestamp() * 1000)
endTime = int(datetime.datetime.strptime(endDatetime, '%Y-%m-%d %H:%M:%S').timestamp() * 1000)

print(startDatetime, startTime)
print(endDatetime, endTime)

输出:

text 复制代码
>>> 2023-01-01 00:00:00 1672502400000
>>> 2023-01-01 00:05:00 1672502700000
python 复制代码
# 仅给定终止时间
kline_result = market.get_klines(symbol='BTCUSDT', interval='1m', endTime=endTime, limit=2)
eprint(kline_result)

输出:

text 复制代码
>>> {'code': 200,
>>>  'data': [[1672502640000, '16587.90', '16588.00', '16587.70', '16587.70', '......'],
>>>           [1672502700000, '16587.70', '16587.70', '16586.90', '16587.00', '......']],
>>>  'msg': ''}
python 复制代码
# 仅给定起始和终止时间
kline_result = market.get_klines(
    symbol='BTCUSDT',
    interval='1m',
    startTime=startTime,  # 包括startTime
    endTime=endTime,  # 包括endTime
)
eprint(kline_result)

输出:

text 复制代码
>>> {'code': 200,
>>>  'data': [[1672502400000, '16586.10', '16591.20', '16586.00', '16591.10', '......'],
>>>           [1672502460000, '16591.10', '16591.50', '16590.80', '16590.90', '......'],
>>>           [1672502520000, '16590.80', '16591.70', '16590.80', '16591.70', '......'],
>>>           [1672502580000, '16591.60', '16591.70', '16587.90', '16587.90', '......'],
>>>           [1672502640000, '16587.90', '16588.00', '16587.70', '16587.70', '......'],
>>>           [1672502700000, '16587.70', '16587.70', '16586.90', '16587.00', '......']],
>>>  'msg': ''}

5. 深度信息 get_depth

python 复制代码
depth_result = market.get_depth(symbol='BTCUSDT', limit=5)
eprint(depth_result)

输出:

text 复制代码
>>> {'code': 200,
>>>  'data': {'lastUpdateId': 3888878453883,
>>>           'E': 1706245426397,
>>>           'T': 1706245426390,
>>>           'bids': [['40152.50', '0.131'],
>>>                    ['40152.40', '0.008'],
>>>                    ['40152.20', '0.005'],
>>>                    ['40152.10', '0.013'],
>>>                    ['40151.90', '0.038']],
>>>           'asks': [['40152.60', '3.099'],
>>>                    ['40152.70', '0.008'],
>>>                    ['40152.80', '0.008'],
>>>                    ['40152.90', '0.005'],
>>>                    ['40153.00', '0.005']]},
>>>  'msg': ''}

6. 成交查询

6.1 近期成交列表 get_trades

python 复制代码
trades_result = market.get_trades(symbol='BTCUSDT', limit=5)
eprint(trades_result)

输出:

text 复制代码
>>> {'code': 200,
>>>  'data': [{'id': 4530285100,
>>>            'price': '40151.90',
>>>            'qty': '0.003',
>>>            'quoteQty': '120.45',
>>>            'time': 1706245427482,
>>>            '...': '......'},
>>>           {'id': 4530285101,
>>>            'price': '40151.70',
>>>            'qty': '0.003',
>>>            'quoteQty': '120.45',
>>>            'time': 1706245427482,
>>>            '...': '......'},
>>>           {'id': 4530285102,
>>>            'price': '40151.60',
>>>            'qty': '0.005',
>>>            'quoteQty': '200.75',
>>>            'time': 1706245427482,
>>>            '...': '......'},
>>>           {'id': 4530285103,
>>>            'price': '40151.50',
>>>            'qty': '0.002',
>>>            'quoteQty': '80.30',
>>>            'time': 1706245427482,
>>>            '...': '......'},
>>>           {'id': 4530285104,
>>>            'price': '40151.20',
>>>            'qty': '0.026',
>>>            'quoteQty': '1043.93',
>>>            'time': 1706245428266,
>>>            '...': '......'}],
>>>  'msg': ''}

6.2 查询历史成交 get_historicalTrades

python 复制代码
historicalTrades_result = market.get_historicalTrades(symbol='BTCUSDT', limit=5)  # 这个接口需要key
eprint(historicalTrades_result)

输出:

text 复制代码
>>> {'code': 200,
>>>  'data': [{'id': 4530285131,
>>>            'price': '40151.30',
>>>            'qty': '0.004',
>>>            'quoteQty': '160.60',
>>>            'time': 1706245430957,
>>>            '...': '......'},
>>>           {'id': 4530285132,
>>>            'price': '40151.30',
>>>            'qty': '0.003',
>>>            'quoteQty': '120.45',
>>>            'time': 1706245431264,
>>>            '...': '......'},
>>>           {'id': 4530285133,
>>>            'price': '40151.20',
>>>            'qty': '0.007',
>>>            'quoteQty': '281.05',
>>>            'time': 1706245431698,
>>>            '...': '......'},
>>>           {'id': 4530285134,
>>>            'price': '40151.20',
>>>            'qty': '0.006',
>>>            'quoteQty': '240.90',
>>>            'time': 1706245431698,
>>>            '...': '......'},
>>>           {'id': 4530285135,
>>>            'price': '40151.20',
>>>            'qty': '0.110',
>>>            'quoteQty': '4416.63',
>>>            'time': 1706245431698,
>>>            '...': '......'}],
>>>  'msg': ''}

6.3 近期成交(归集) get_aggTrades

python 复制代码
aggTrades_result = market.get_aggTrades(symbol='BTCUSDT', limit=5)
eprint(aggTrades_result)

输出:

text 复制代码
>>> {'code': 200,
>>>  'data': [{'a': 2000008269, 'p': '40151.20', 'q': '0.003', 'f': 4530285152, 'l': 4530285152, '...': '......'},
>>>           {'a': 2000008270, 'p': '40151.20', 'q': '0.422', 'f': 4530285153, 'l': 4530285176, '...': '......'},
>>>           {'a': 2000008271, 'p': '40151.10', 'q': '0.008', 'f': 4530285177, 'l': 4530285178, '...': '......'},
>>>           {'a': 2000008272, 'p': '40151.00', 'q': '0.005', 'f': 4530285179, 'l': 4530285179, '...': '......'},
>>>           {'a': 2000008273, 'p': '40150.90', 'q': '0.005', 'f': 4530285180, 'l': 4530285180, '...': '......'}],
>>>  'msg': ''}

7. 交易规范信息 get_exchangeInfo

python 复制代码
exchangeInfo_result = market.get_exchangeInfo()
eprint(exchangeInfo_result)

输出:

text 复制代码
>>> {'code': 200,
>>>  'data': {'timezone': 'UTC',
>>>           'serverTime': 1706241611125,
>>>           'futuresType': 'U_MARGINED',
>>>           'rateLimits': [{'rateLimitType': 'REQUEST_WEIGHT', 'interval': 'MINUTE', 'intervalNum': 1, 'limit': 2400},
>>>                          {'rateLimitType': 'ORDERS', 'interval': 'MINUTE', 'intervalNum': 1, 'limit': 1200},
>>>                          {'rateLimitType': 'ORDERS', 'interval': 'SECOND', 'intervalNum': 10, 'limit': 300}],
>>>           'exchangeFilters': [],
>>>           'assets': [{'asset': 'USDT', 'marginAvailable': True, 'autoAssetExchange': '-10000'},
>>>                      {'asset': 'BTC', 'marginAvailable': True, 'autoAssetExchange': '-0.10000000'},
>>>                      {'asset': 'BNB', 'marginAvailable': True, 'autoAssetExchange': '-10'},
>>>                      {'asset': 'ETH', 'marginAvailable': True, 'autoAssetExchange': '-5'},
>>>                      {'asset': 'XRP', 'marginAvailable': True, 'autoAssetExchange': '0'},
>>>                      '......'],
>>>           'symbols': [{'symbol': 'BTCUSDT',
>>>                        'pair': 'BTCUSDT',
>>>                        'contractType': 'PERPETUAL',
>>>                        'deliveryDate': 4133404800000,
>>>                        'onboardDate': 1569398400000,
>>>                        '...': '......'},
>>>                       {'symbol': 'ETHUSDT',
>>>                        'pair': 'ETHUSDT',
>>>                        'contractType': 'PERPETUAL',
>>>                        'deliveryDate': 4133404800000,
>>>                        'onboardDate': 1569398400000,
>>>                        '...': '......'},
>>>                       {'symbol': 'BCHUSDT',
>>>                        'pair': 'BCHUSDT',
>>>                        'contractType': 'PERPETUAL',
>>>                        'deliveryDate': 4133404800000,
>>>                        'onboardDate': 1569398400000,
>>>                        '...': '......'},
>>>                       {'symbol': 'XRPUSDT',
>>>                        'pair': 'XRPUSDT',
>>>                        'contractType': 'PERPETUAL',
>>>                        'deliveryDate': 4133404800000,
>>>                        'onboardDate': 1569398400000,
>>>                        '...': '......'},
>>>                       {'symbol': 'EOSUSDT',
>>>                        'pair': 'EOSUSDT',
>>>                        'contractType': 'PERPETUAL',
>>>                        'deliveryDate': 4133404800000,
>>>                        'onboardDate': 1569398400000,
>>>                        '...': '......'},
>>>                       '......']},
>>>  'msg': ''}
相关推荐
加密新世界6 分钟前
Move on Sui入门 004-在sui链上发布Coin合约和Faucet Coin合约
区块链
好看资源平台1 小时前
网络爬虫——综合实战项目:多平台房源信息采集与分析系统
爬虫·python
进击的六角龙1 小时前
深入浅出:使用Python调用API实现智能天气预报
开发语言·python
檀越剑指大厂1 小时前
【Python系列】浅析 Python 中的字典更新与应用场景
开发语言·python
湫ccc1 小时前
Python简介以及解释器安装(保姆级教学)
开发语言·python
孤独且没人爱的纸鹤1 小时前
【深度学习】:从人工神经网络的基础原理到循环神经网络的先进技术,跨越智能算法的关键发展阶段及其未来趋势,探索技术进步与应用挑战
人工智能·python·深度学习·机器学习·ai
羊小猪~~1 小时前
tensorflow案例7--数据增强与测试集, 训练集, 验证集的构建
人工智能·python·深度学习·机器学习·cnn·tensorflow·neo4j
lzhlizihang1 小时前
python如何使用spark操作hive
hive·python·spark
q0_0p2 小时前
牛客小白月赛105 (Python题解) A~E
python·牛客
极客代码2 小时前
【Python TensorFlow】进阶指南(续篇三)
开发语言·人工智能·python·深度学习·tensorflow