Files
lm_code/回测数据/test.py

80 lines
2.7 KiB
Python
Raw Normal View History

2025-09-25 18:29:53 +08:00
import datetime
import requests
headers = {
'accept': 'application/json, text/plain, */*',
'accept-language': 'zh,zh-CN;q=0.9,zh-HK;q=0.8,en;q=0.7',
'cache-control': 'no-cache',
'origin': 'https://www.websea.com',
'pragma': 'no-cache',
'priority': 'u=1, i',
'referer': 'https://www.websea.com/',
'sec-ch-ua': '"Chromium";v="140", "Not=A?Brand";v="24", "Google Chrome";v="140"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36',
}
if __name__ == '__main__':
datas = []
# 定义开始日期和结束日期
time_ser = datetime.datetime(2025, 9, 25)
# 获取当天开始时刻00:00:00
start_of_day = time_ser.replace(hour=0, minute=0, second=0, microsecond=0)
# 获取当天结束时刻23:59:59
end_of_day = time_ser.replace(hour=23, minute=59, second=59, microsecond=0)
# 将开始时刻和结束时刻转换为时间戳
start_timestamp = start_of_day.timestamp()
end_timestamp = end_of_day.timestamp()
params = {
'symbol': 'ETH-USDT',
'period': '1min',
'start': int(start_timestamp),
'end': int(end_timestamp),
}
response = requests.get('https://capi.websea.com/webApi/market/getKline', params=params, headers=headers)
# 提取数据
data = response.json()['result']['data']
# 根据 id 进行排序
sorted_data = sorted(data, key=lambda x: x['id'])
prev_data = None
n = 0
for i in range(1, len(sorted_data)):
current_data = sorted_data[i]
prev_data = sorted_data[i - 1]
# 当前一笔是涨的
if float(current_data['open']) < float(current_data['close']):
# 前一笔是涨的
if float(prev_data['open']) < float(prev_data['close']):
if float(current_data['open']) < float(prev_data['open']) and float(current_data['close']) > float(
prev_data['close']):
print(f"前一笔数据: {prev_data}")
print(f"当前一笔数据: {current_data}")
print("做多" + "-" * 50)
n += 1
# 前一笔是跌的
else:
if float(current_data['open']) < float(prev_data['close']) and float(current_data['close']) > float(
prev_data['open']):
print(f"前一笔数据: {prev_data}")
print(f"当前一笔数据: {current_data}")
print("做多" + "-" * 50)
n += 1
print(n)