trading-quant/test.py
2024-06-07 09:41:43 +08:00

21 lines
502 B
Python

import requests
import pandas as pd
api_url = "https://api.exness.com/v1/ohlc"
params = {
'symbol': 'XAUUSDm',
'interval': '1d',
'start': '2020-01-01',
'end': '2023-01-01'
}
# 发起HTTP请求
response = requests.get(api_url, params=params)
data = response.json()
# 转换为DataFrame
df = pd.DataFrame(data['ohlc'], columns=['timestamp', 'open', 'high', 'low', 'close', 'volume'])
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='s')
# 打印前五行数据
print(df.head())