获取API Key和Secret Key,同时通过Binance SDK连接到API。这可以使用本地安装的Python Binance库,也可以在GitHub上下载和安装Binance API的Python版本。 例如,在Python中有一个叫做python-binance的开源库,安装方法如下: pip install python-binance
然后,使用Binance API的get_historical_trades()方法来获取历史交易记录。此方法需要提供所需的交易对和时间范围。 例如,在Python中获取ETH / BTC交易对在2021年1月1日到2021年1月31日之间的历史交易记录可以使用以下代码: from binance.client import Client from datetime import datetime
api_key = 'your_api_key' api_secret = 'your_api_secret' client = Client(api_key, api_secret)
start_date = datetime(2021, 1, 1) end_date = datetime(2021, 1, 31)
trades = client.get_historical_trades(symbol='ETHBTC', startTime=int(start_date.timestamp()*1000), endTime=int(end_date.timestamp()*1000))
print(trades)
这就会返回2021年1月1日到2021年1月31日之间ETH / BTC交易对的历史交易记录。