From a8ad37d35c9a26957dd8c4cc4ee498354c4eaf10 Mon Sep 17 00:00:00 2001 From: khwkim1111 Date: Sat, 9 May 2026 17:01:57 +0900 Subject: [PATCH] commit --- new_prac.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/new_prac.py b/new_prac.py index 6b066c8..2666a33 100644 --- a/new_prac.py +++ b/new_prac.py @@ -81,16 +81,16 @@ def main(): # GS/MS/WFC 마켓 메이킹 active orders stock_orders = {} # {order_id: {"symbol": ..., "dir": ..., "price": ..., "size": ...}} - last_refresh = time.time() + last_refresh = time.time() last_stock_refresh = time.time() - # hello 메시지에서 기존 포지션 로드 -for sym_info in hello_message["symbols"]: # "symbol" → "symbols" - sym = sym_info["symbol"] - pos = sym_info["position"] - if sym in om.positions: - om.positions[sym] = pos - om.future_positions[sym] = pos + # hello 메시지에서 기존 포지션 로드 (재접속 시 필수) ← 들여쓰기 수정 + for sym_info in hello_message["symbols"]: + sym = sym_info["symbol"] + pos = sym_info["position"] + if sym in om.positions: + om.positions[sym] = pos + om.future_positions[sym] = pos print(f" 초기 포지션 로드: {om.positions}") def next_id(): @@ -122,9 +122,9 @@ for sym_info in hello_message["symbols"]: # "symbol" → "symbols" return cancel_all_bond_orders() - pos = om.positions["BOND"] - base = BOND_ORDER_SIZE - adj = abs(pos) // 5 + pos = om.positions["BOND"] + base = BOND_ORDER_SIZE + adj = abs(pos) // 5 if pos < 0: buy_sz = min(base + adj, 100 - pos) @@ -160,11 +160,11 @@ for sym_info in hello_message["symbols"]: # "symbol" → "symbols" info = stock_orders[oid] if symbol is None or info["symbol"] == symbol: size = info.get("size", 0) - sym = info["symbol"] + s = info["symbol"] if info["dir"] == Dir.BUY: - om.future_positions[sym] -= size + om.future_positions[s] -= size else: - om.future_positions[sym] += size + om.future_positions[s] += size om.cancel(oid) stock_orders.pop(oid, None) @@ -178,14 +178,13 @@ for sym_info in hello_message["symbols"]: # "symbol" → "symbols" if bid_price is None or ask_price is None: return - mid = (bid_price + ask_price) // 2 + mid = (bid_price + ask_price) // 2 our_bid = mid - STOCK_SPREAD our_ask = mid + STOCK_SPREAD - pos = om.positions[sym] + pos = om.positions[sym] limit = STOCK_MAX_POSITION - # 기존 해당 심볼 주문 취소 cancel_stock_orders(sym) buy_sz = max(0, min(STOCK_ORDER_SIZE, limit - pos)) @@ -206,7 +205,8 @@ for sym_info in hello_message["symbols"]: # "symbol" → "symbols" # ── XLF 차익거래 ───────────────────────────────────────────── def try_xlf_arb(): - nonlocal xlf_state, xlf_direction, xlf_pending, xlf_arb_size, xlf_convert_oid + # nonlocal에 xlf_last_fail 추가 ← 수정 + nonlocal xlf_state, xlf_direction, xlf_pending, xlf_arb_size, xlf_convert_oid, xlf_last_fail if not market_open or xlf_state != "IDLE": return @@ -505,7 +505,7 @@ for sym_info in hello_message["symbols"]: # "symbol" → "symbols" if sym in ["VALE", "VALBZ"]: try_vale_arb() - # GS/MS/WFC 마켓 메이킹 갱신 (호가 바뀔 때마다) + # GS/MS/WFC 마켓 메이킹 갱신 (2초마다) if sym in ("GS", "MS", "WFC") and xlf_state == "IDLE": now = time.time() if now - last_stock_refresh > 2.0: