From 7ad696673eb84bcd776153885a0aeb3ba00023ba Mon Sep 17 00:00:00 2001 From: anor Date: Mon, 9 Mar 2026 06:11:07 +1000 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=BF=D0=B5=D1=80=D0=B5=D1=85=D0=BE?= =?UTF-8?q?=D0=B4=20=D0=BD=D0=B0=20USDC=20+=20live=20mode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - spot.py: универсальная quote currency (USDT/USDC) вместо хардкода - config.yaml: mode=live, testnet=false, BTC/USDC, 1 актив, $114 капитал Co-Authored-By: Claude Opus 4.6 --- config.yaml | 38 ++++++--------------------------- src/remizov_trader/core/spot.py | 33 ++++++++++++++-------------- 2 files changed, 24 insertions(+), 47 deletions(-) diff --git a/config.yaml b/config.yaml index 8966cdc..fc2f502 100644 --- a/config.yaml +++ b/config.yaml @@ -1,43 +1,19 @@ # RemizovTrader Configuration -mode: paper # paper | live +mode: live # paper | live capital: - initial: 100.0 - currency: USDT + initial: 114.0 + currency: USDC risk: - per_trade: 0.05 # 5% risk per trade ($100 capital) + per_trade: 0.05 # 5% risk per trade max_position_pct: 0.50 # max 50% of equity in one position - max_open_positions: 3 + max_open_positions: 1 # single asset, $114 capital assets: - ticker: BTC-USD - symbol: BTC/USDT - K: 2 - corr_thresh: 0.5 - trailing_stop: true - - - ticker: ETH-USD - symbol: ETH/USDT - K: 2 - corr_thresh: 0.5 - trailing_stop: true - - - ticker: AVAX-USD - symbol: AVAX/USDT - K: 2 - corr_thresh: 0.5 - trailing_stop: true - - - ticker: LINK-USD - symbol: LINK/USDT - K: 2 - corr_thresh: 0.5 - trailing_stop: true - - - ticker: SOL-USD - symbol: SOL/USDT + symbol: BTC/USDC K: 2 corr_thresh: 0.5 trailing_stop: true @@ -62,7 +38,7 @@ exchange: data_source: exchange # "exchange" (ccxt/Bybit) or "yfinance" api_key: "" # set via REMIZOV_API_KEY env var api_secret: "" # set via REMIZOV_API_SECRET env var - testnet: true + testnet: false web: host: 0.0.0.0 diff --git a/src/remizov_trader/core/spot.py b/src/remizov_trader/core/spot.py index 5b9b373..68cb0e2 100644 --- a/src/remizov_trader/core/spot.py +++ b/src/remizov_trader/core/spot.py @@ -59,14 +59,15 @@ class SpotExecutor: log.error(f"Price fetch {symbol} failed: {e}") return None - def buy(self, symbol: str, usdt_amount: float) -> dict | None: - """Market buy with specified USDT amount. + def buy(self, symbol: str, quote_amount: float) -> dict | None: + """Market buy with specified quote currency amount. Returns order dict or None on failure. Does NOT retry on failure (prevents double orders). """ self._ensure_markets() coin = symbol.split("/")[0] + quote = symbol.split("/")[1] # USDT, USDC, etc. # 1. Get price price = self.get_price(symbol) @@ -75,7 +76,7 @@ class SpotExecutor: # 2. Calculate amount market = self.exchange.market(symbol) - amount = usdt_amount / price + amount = quote_amount / price amount = float(self.exchange.amount_to_precision(symbol, amount)) # 3. Validate minimums @@ -85,37 +86,37 @@ class SpotExecutor: if amount < min_amount: log.error(f"BUY {symbol}: amount {amount} < min {min_amount}") return None - if usdt_amount < min_cost: - log.error(f"BUY {symbol}: cost ${usdt_amount:.2f} < min ${min_cost}") + if quote_amount < min_cost: + log.error(f"BUY {symbol}: cost ${quote_amount:.2f} < min ${min_cost}") return None # 4. Check balance (strict) - usdt_free = self.get_balance("USDT") - if usdt_free < usdt_amount: + quote_free = self.get_balance(quote) + if quote_free < quote_amount: # Try to buy what we can afford - if usdt_free >= min_cost: - log.warning(f"BUY {symbol}: USDT {usdt_free:.2f} < requested {usdt_amount:.2f}, " - f"reducing to {usdt_free:.2f}") - usdt_amount = usdt_free - amount = usdt_amount / price + if quote_free >= min_cost: + log.warning(f"BUY {symbol}: {quote} {quote_free:.2f} < requested {quote_amount:.2f}, " + f"reducing to {quote_free:.2f}") + quote_amount = quote_free + amount = quote_amount / price amount = float(self.exchange.amount_to_precision(symbol, amount)) else: - log.error(f"BUY {symbol}: USDT {usdt_free:.2f} < min ${min_cost}") + log.error(f"BUY {symbol}: {quote} {quote_free:.2f} < min ${min_cost}") return None # 5. Execute ts = datetime.now(timezone.utc).isoformat() if self.dry_run: log.info(f"[DRY RUN] BUY {amount} {coin} @ ~${price:,.2f} " - f"(${usdt_amount:.2f}) at {ts}") + f"(${quote_amount:.2f}) at {ts}") return {"dry_run": True, "side": "buy", "symbol": symbol, - "amount": amount, "price": price, "cost": usdt_amount} + "amount": amount, "price": price, "cost": quote_amount} try: order = self.exchange.create_market_buy_order(symbol, amount) filled = float(order.get("filled", 0)) avg_price = float(order.get("average", price)) - cost = float(order.get("cost", usdt_amount)) + cost = float(order.get("cost", quote_amount)) log.info(f"BUY OK: {filled} {coin} @ ${avg_price:,.2f} " f"(${cost:.2f}) order={order['id']}") return order