增加斐波那契下单

This commit is contained in:
dekun
2026-05-18 16:50:02 +08:00
parent a250c28ceb
commit b9f1b9e62a
5 changed files with 1018 additions and 24 deletions
+60
View File
@@ -0,0 +1,60 @@
"""斐波关键位监控:纯计算与类型判断(Gate / Binance 主站共用)。"""
FIB_KEY_MONITOR_TYPES = frozenset({"斐波回调0.618", "斐波回调0.786"})
FIB_RATIO_BY_TYPE = {
"斐波回调0.618": 0.618,
"斐波回调0.786": 0.786,
}
def is_fib_key_monitor_type(monitor_type):
return (monitor_type or "").strip() in FIB_KEY_MONITOR_TYPES
def fib_ratio_from_type(monitor_type):
return FIB_RATIO_BY_TYPE.get((monitor_type or "").strip())
def calc_fib_plan(direction, upper, lower, ratio):
"""
上沿 H、下沿 L;挂单价 E = L + ratio*(H-L)。
多:SL=LTP=H;空:SL=HTP=L。
返回 (entry, stop_loss, take_profit) 或 None。
"""
try:
h = float(upper)
l = float(lower)
r = float(ratio)
except (TypeError, ValueError):
return None
if h <= l or r <= 0 or r >= 1:
return None
span = h - l
entry = l + r * span
direction = (direction or "long").strip().lower()
if direction == "short":
return entry, h, l
return entry, l, h
def stored_key_signal_type(monitor_type):
"""写入 order_monitors / trade_records 的 key_signal_type(箱体/收敛/斐波)。"""
mt = (monitor_type or "").strip()
if mt in FIB_KEY_MONITOR_TYPES:
return mt
return None
def fib_invalidate_by_mark(direction, mark_price, upper, lower):
"""先触达止盈侧(标记价)则失效。多:mark>=H;空:mark<=L。"""
try:
m = float(mark_price)
h = float(upper)
l = float(lower)
except (TypeError, ValueError):
return False
direction = (direction or "long").strip().lower()
if direction == "short":
return m <= l
return m >= h