gfrdegdergr

This commit is contained in:
27942
2025-09-30 10:06:28 +08:00
parent e873ddd7fd
commit 53806a6c2a
5 changed files with 0 additions and 488 deletions

View File

@@ -1,58 +0,0 @@
import datetime
import requests
headers = {
'accept': 'application/json, text/plain, */*',
'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__':
# 指定日期
time_ser = datetime.datetime(2025, 9, 25)
start_of_day = time_ser.replace(hour=0, minute=0, second=0, microsecond=0)
end_of_day = time_ser.replace(hour=23, minute=59, second=59, microsecond=0)
start_timestamp = int(start_of_day.timestamp())
end_timestamp = int(end_of_day.timestamp())
params = {
'symbol': 'ETH-USDT',
'period': '1min',
'start': start_timestamp,
'end': end_timestamp,
}
response = requests.get('https://capi.websea.com/webApi/market/getKline',
params=params, headers=headers)
data = response.json()['result']['data']
# 排序
sorted_data = sorted(data, key=lambda x: x['id'])
for idx in range(1, len(sorted_data)):
prev = sorted_data[idx - 1] # 前一笔
curr = sorted_data[idx] # 当前一笔
po, pc = float(prev['open']), float(prev['close'])
co, cc = float(curr['open']), float(curr['close'])
prev_up = pc > po # 前一笔涨
curr_up = cc > co # 当前一笔涨
# -------- 第一种情况:当前是涨 --------
if curr_up:
# ① 前一笔是涨的
if prev_up and (co < po and cc > pc):
print(f"涨-包裹(前涨,当前涨) id={curr['id']} 前={po,pc} 当前={co,cc}")
# ② 前一笔是跌的
if not prev_up and (co < pc and cc > po):
print(f"涨-包裹(前跌,当前涨) id={curr['id']} 前={po,pc} 当前={co,cc}")
# -------- 第二种情况:当前是跌 --------
else:
# ① 前一笔是跌的
if not prev_up and (co > po and cc < pc):
print(f"跌-包裹(前跌,当前跌) id={curr['id']} 前={po,pc} 当前={co,cc}")
# ② 前一笔是涨的
if prev_up and (co > pc and cc < po):
print(f"跌-包裹(前涨,当前跌) id={curr['id']} 前={po,pc} 当前={co,cc}")

View File

@@ -1,103 +0,0 @@
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__':
# 请求数据
time_ser = datetime.datetime(2025, 9, 22)
start_of_day = time_ser.replace(hour=0, minute=0, second=0, microsecond=0)
end_of_day = time_ser.replace(hour=23, minute=59, second=59, microsecond=0)
params = {
'symbol': 'ETH-USDT',
'period': '1min',
'start': int(start_of_day.timestamp()),
'end': int(end_of_day.timestamp()),
}
response = requests.get('https://capi.websea.com/webApi/market/getKline', params=params, headers=headers)
data = response.json()['result']['data']
sorted_data = sorted(data, key=lambda x: x['id'])
signals = 0
wins = 0
lig_price = 0
low_price = 0
for idx in range(1, len(sorted_data) - 2): # 需要至少留两根K线做验证
prev = sorted_data[idx - 1] # 前一笔
curr = sorted_data[idx] # 当前这笔
future = sorted_data[idx + 2] # 两根后的K线
prev_open, prev_close = float(prev['open']), float(prev['close'])
curr_open, curr_close = float(curr['open']), float(curr['close'])
future_close = float(future['close'])
# 当前为涨
if curr_close > curr_open:
# 前一笔涨 + 包裹
if prev_close > prev_open and curr_open < prev_open and curr_close > prev_close:
signals += 1
lig_price += (future_close - curr_close)
if future_close > curr_close:
wins += 1
# 前一笔跌 + 反包
elif prev_close < prev_open and curr_open < prev_close and curr_close > prev_open:
signals += 1
lig_price += (future_close - curr_close)
if future_close > curr_close:
wins += 1
# 当前为跌
elif curr_close < curr_open:
# 前一笔跌 + 包裹
if prev_close < prev_open and curr_open > prev_open and curr_close < prev_close:
signals += 1
low_price += (curr_close - future_close)
if future_close < curr_close:
wins += 1
# 前一笔涨 + 反包
elif prev_close > prev_open and curr_open > prev_close and curr_close < prev_open:
signals += 1
low_price += (curr_close - future_close)
if future_close < curr_close:
wins += 1
if signals > 0:
win_rate = wins / signals * 100
print(f"信号数={signals}, 胜率={win_rate:.2f}%")
else:
print("没有找到符合条件的形态")
print(lig_price)
print(low_price)

View File

@@ -1,111 +0,0 @@
import datetime
import requests
from loguru import logger
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__':
zh_project = 0
for i in range(1, 31):
# 请求数据
time_ser = datetime.datetime(2025, 8, i)
start_of_day = time_ser.replace(hour=0, minute=0, second=0, microsecond=0)
end_of_day = time_ser.replace(hour=23, minute=59, second=59, microsecond=0)
params = {
'symbol': 'ETH-USDT',
'period': '1min',
'start': int(start_of_day.timestamp()),
'end': int(end_of_day.timestamp()),
}
response = requests.get('https://capi.websea.com/webApi/market/getKline', params=params, headers=headers)
data = response.json()['result']['data']
sorted_data = sorted(data, key=lambda x: x['id'])
signals = 0
wins = 0
lig_price = 0
low_price = 0
for idx in range(1, len(sorted_data) - 2): # 需要至少留两根K线做验证
prev = sorted_data[idx - 1] # 前一笔
curr = sorted_data[idx] # 当前这笔
future = sorted_data[idx + 2] # 两根后的K线
prev_open, prev_close = float(prev['open']), float(prev['close'])
curr_open, curr_close = float(curr['open']), float(curr['close'])
future_close = float(future['close'])
# 当前为涨
if curr_close > curr_open:
# 前一笔涨 + 包裹
if prev_close > prev_open and curr_open < prev_open and curr_close > prev_close:
signals += 1
lig_price += (future_close - curr_close)
if future_close > curr_close:
wins += 1
# 前一笔跌 + 反包
elif prev_close < prev_open and curr_open < prev_close and curr_close > prev_open:
signals += 1
lig_price += (future_close - curr_close)
if future_close > curr_close:
wins += 1
# 当前为跌
elif curr_close < curr_open:
# 前一笔跌 + 包裹
if prev_close < prev_open and curr_open > prev_open and curr_close < prev_close:
signals += 1
low_price += (curr_close - future_close)
if future_close < curr_close:
wins += 1
# 前一笔涨 + 反包
elif prev_close > prev_open and curr_open > prev_close and curr_close < prev_open:
signals += 1
low_price += (curr_close - future_close)
if future_close < curr_close:
wins += 1
# if signals > 0:
# win_rate = wins / signals * 100
# print(f"信号数={signals}, 胜率={win_rate:.2f}%")
# else:
# print("没有找到符合条件的形态")
logger.info(
f"日期:{i}号,信号数={signals}, 胜率={wins / signals * 100:.2f}%,上涨方向:{lig_price:.2f},下跌方向:{low_price:.2f},综合价格:{(lig_price - low_price):.2f}")
zh_project += (lig_price - low_price)
logger.success(f"综合价格:{zh_project:.2f}")

View File

@@ -1,120 +0,0 @@
import datetime
import requests
import pandas as pd
import plotly.graph_objects as go
headers = {
'accept': 'application/json, text/plain, */*',
'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',
}
def fetch_kline():
time_ser = datetime.datetime(2025, 9, 26)
start_of_day = time_ser.replace(hour=0, minute=0, second=0, microsecond=0)
end_of_day = time_ser.replace(hour=23, minute=59, second=59, microsecond=0)
start_timestamp = int(start_of_day.timestamp())
end_timestamp = int(end_of_day.timestamp())
params = {
'symbol': 'ETH-USDT',
'period': '1min',
'start': start_timestamp,
'end': end_timestamp,
}
response = requests.get('https://capi.websea.com/webApi/market/getKline',
params=params, headers=headers)
data = response.json()['result']['data']
sorted_data = sorted(data, key=lambda x: x['id'])
df = pd.DataFrame(sorted_data)
df['Date'] = pd.to_datetime(df['id'], unit='s')
df.set_index('Date', inplace=True)
df.rename(columns={
'open': 'Open',
'close': 'Close',
'high': 'High',
'low': 'Low',
'amount': 'Volume'
}, inplace=True)
df[['Open', 'Close', 'High', 'Low', 'Volume']] = df[['Open', 'Close', 'High', 'Low', 'Volume']].astype(float)
return df
def detect_signals(df):
signals = []
for idx in range(1, len(df)):
prev = df.iloc[idx - 1]
curr = df.iloc[idx]
po, pc = prev['Open'], prev['Close']
co, cc = curr['Open'], curr['Close']
prev_up = pc > po
curr_up = cc > co
if curr_up:
if prev_up and (co < po and cc > pc):
signals.append((curr.name, 'bull'))
if not prev_up and (co < pc and cc > po):
signals.append((curr.name, 'bull'))
else:
if not prev_up and (co > po and cc < pc):
signals.append((curr.name, 'bear'))
if prev_up and (co > pc and cc < po):
signals.append((curr.name, 'bear'))
return signals
def plot_signals(df, signals):
fig = go.Figure()
# 蜡烛图
fig.add_trace(go.Candlestick(
x=df.index,
open=df['Open'],
high=df['High'],
low=df['Low'],
close=df['Close'],
name='K线',
increasing_line_color='green',
decreasing_line_color='red'
))
# 标记信号
bull_x = [dt for dt, sig in signals if sig == 'bull']
bull_y = [df.loc[dt, 'Close'] for dt, sig in signals if sig == 'bull']
bear_x = [dt for dt, sig in signals if sig == 'bear']
bear_y = [df.loc[dt, 'Close'] for dt, sig in signals if sig == 'bear']
fig.add_trace(go.Scatter(
x=bull_x, y=bull_y,
mode="markers",
marker=dict(symbol="triangle-up", size=12, color="lime"),
name="看涨信号"
))
fig.add_trace(go.Scatter(
x=bear_x, y=bear_y,
mode="markers",
marker=dict(symbol="triangle-down", size=12, color="orange"),
name="看跌信号"
))
# 美化布局
fig.update_layout(
title="ETH-USDT 包裹信号",
xaxis_title="时间",
yaxis_title="价格 (USDT)",
template="plotly_dark", # 黑色主题,比较炫酷
xaxis_rangeslider_visible=False, # 隐藏默认范围滑块
hovermode="x unified" # 鼠标悬浮时统一显示数据
)
fig.show()
if __name__ == "__main__":
df = fetch_kline()
signals = detect_signals(df)
plot_signals(df, signals)

View File

@@ -1,96 +0,0 @@
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)
# 第一种情况:当前一笔是涨的,这里又有两种情况。第一种情况:前一笔是涨的,然后当前一笔的价格,开盘的价格小于前一笔,结盘的价格大于前一笔;第二种情况:前一笔是跌的,当前一笔的开盘价格低于前一笔的结盘价格,当前一笔的结盘价格,大于前一笔的开盘价格