Files
lm_code/回测数据/接口查询.py
2025-09-25 18:29:53 +08:00

96 lines
3.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import datetime
import requests
import pandas as pd
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'])
low_data = None
n = 0
n1 = 0
for _, i in enumerate(sorted_data):
if not low_data:
low_data = i
continue
# 当前一笔是多
if i['open'] < i['close']:
if low_data['open'] < low_data['close']:
if float(i['open']) < float(low_data['open']) and float(i['close']) > float(low_data['close']):
try:
if sorted_data[_ + 3]["open"] > i['open'] and sorted_data[_ + 3]["close"] > i['close']:
print(f"老数据:{low_data}")
print(f"老数据:{i}")
print(f"新数据:{sorted_data[_ + 3]}")
print("做多" + "-" * 50)
except:
pass
# if float(i['open']) < float(low_data['open']) and float(i['close']) < float(low_data['close']):
#
# try:
# if sorted_data[_ + 3]["open"] < i['open'] and sorted_data[_ + 3]["close"] < i['close']:
# print(f"老数据:{i}")
# print(f"新数据:{sorted_data[_ + 3]}")
#
# print("做空" + "-" * 50)
# except:
# pass
low_data = i
print(n)
# 第一种情况:当前一笔是涨的,这里又有两种情况。第一种情况:前一笔是涨的,然后当前一笔的价格,开盘的价格小于前一笔,结盘的价格大于前一笔;第二种情况:前一笔是跌的,当前一笔的开盘价格低于前一笔的结盘价格,当前一笔的结盘价格,大于前一笔的开盘价格