fix: limit order по bid/ask, partial fill, maker fee в бэктесте
- exchange: limit по bid (buy) / ask (sell) вместо last price - exchange: partial fill handling при cancel limit order - backtest_wf: MAKER_FEE + TAKER_FEE вместо TAKER_FEE * 2 - sweep_leverage/sweep_stop: аналогично maker+taker Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+24
-4
@@ -148,8 +148,16 @@ class FuturesExecutor:
|
||||
"""Try postOnly limit order. Returns filled order or None."""
|
||||
import time
|
||||
|
||||
# Place at current price — postOnly ensures maker-only
|
||||
limit_price = float(self.exchange.price_to_precision(symbol, price))
|
||||
# Place at bid (buy) or ask (sell) for maker execution
|
||||
try:
|
||||
book = self.exchange.fetch_order_book(symbol, limit=1)
|
||||
if side == "buy":
|
||||
limit_price = float(book["bids"][0][0]) if book["bids"] else price
|
||||
else:
|
||||
limit_price = float(book["asks"][0][0]) if book["asks"] else price
|
||||
except Exception:
|
||||
limit_price = price
|
||||
limit_price = float(self.exchange.price_to_precision(symbol, limit_price))
|
||||
try:
|
||||
order = self.exchange.create_order(
|
||||
symbol, "limit", side, amount, limit_price,
|
||||
@@ -175,12 +183,24 @@ class FuturesExecutor:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Not filled — cancel
|
||||
# Not filled — cancel and check for partial fill
|
||||
try:
|
||||
self.exchange.cancel_order(order_id, symbol)
|
||||
log.info(f"LIMIT {side.upper()} cancelled (not filled in {wait_sec}s)")
|
||||
except Exception as e:
|
||||
log.warning(f"Cancel limit order failed: {e}")
|
||||
|
||||
# Check if partially filled
|
||||
try:
|
||||
final = self.exchange.fetch_order(order_id, symbol)
|
||||
filled = float(final.get("filled") or 0)
|
||||
if filled > 0:
|
||||
log.info(f"LIMIT {side.upper()} PARTIAL: {filled}/{amount} {symbol} "
|
||||
f"@ ${limit_price:,.2f} (maker)")
|
||||
return final
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
log.info(f"LIMIT {side.upper()} cancelled (not filled in {wait_sec}s)")
|
||||
return None
|
||||
|
||||
def close_position(self, symbol: str, side: str, qty: float) -> dict | None:
|
||||
|
||||
Reference in New Issue
Block a user