# Initialize Binance exchange instance

exchange = ccxt.binance({

'apiKey': 'API_KEY',

'secret': '_SECRET',

'enableRateLimit': True,

})

# Load market data

exchange.load_markets()

# Set trading pair and interval

symbol = 'BTC/USDT'

day_ms = 24 * 60 * 60 * 1000 # Number of milliseconds in a day

start_time = exchange.parse8601('2025-03-31T00:00:00Z')

now = exchange.milliseconds()

all_trades = []

while start_time < now:

print(f'Fetching trades from {exchange.iso8601(start_time)}')

end_time = start_time + day_ms

# Fetch trading records within the specified time range

trades = exchange.fetch_my_trades(symbol, since=start_time, params={'endTime': end_time})

if trades:

last_trade = trades[-1]

start_time = last_trade['timestamp'] + 1 # Avoid duplication

all_trades.extend(trades)

else:

start_time = end_time # If no trades, jump to the next time period

print(f'Fetched {len(all_trades)} trades in total.')

# Output all trading records

for i, trade in enumerate(all_trades):

print(i, trade['id'], trade['datetime'], trade['amount'])