This commit is contained in:
2026-05-09 17:01:57 +09:00
parent 97a11f8c5b
commit a8ad37d35c

View File

@@ -81,16 +81,16 @@ def main():
# GS/MS/WFC 마켓 메이킹 active orders # GS/MS/WFC 마켓 메이킹 active orders
stock_orders = {} # {order_id: {"symbol": ..., "dir": ..., "price": ..., "size": ...}} stock_orders = {} # {order_id: {"symbol": ..., "dir": ..., "price": ..., "size": ...}}
last_refresh = time.time() last_refresh = time.time()
last_stock_refresh = time.time() last_stock_refresh = time.time()
# hello 메시지에서 기존 포지션 로드 # hello 메시지에서 기존 포지션 로드 (재접속 시 필수) ← 들여쓰기 수정
for sym_info in hello_message["symbols"]: # "symbol" → "symbols" for sym_info in hello_message["symbols"]:
sym = sym_info["symbol"] sym = sym_info["symbol"]
pos = sym_info["position"] pos = sym_info["position"]
if sym in om.positions: if sym in om.positions:
om.positions[sym] = pos om.positions[sym] = pos
om.future_positions[sym] = pos om.future_positions[sym] = pos
print(f" 초기 포지션 로드: {om.positions}") print(f" 초기 포지션 로드: {om.positions}")
def next_id(): def next_id():
@@ -122,9 +122,9 @@ for sym_info in hello_message["symbols"]: # "symbol" → "symbols"
return return
cancel_all_bond_orders() cancel_all_bond_orders()
pos = om.positions["BOND"] pos = om.positions["BOND"]
base = BOND_ORDER_SIZE base = BOND_ORDER_SIZE
adj = abs(pos) // 5 adj = abs(pos) // 5
if pos < 0: if pos < 0:
buy_sz = min(base + adj, 100 - pos) buy_sz = min(base + adj, 100 - pos)
@@ -160,11 +160,11 @@ for sym_info in hello_message["symbols"]: # "symbol" → "symbols"
info = stock_orders[oid] info = stock_orders[oid]
if symbol is None or info["symbol"] == symbol: if symbol is None or info["symbol"] == symbol:
size = info.get("size", 0) size = info.get("size", 0)
sym = info["symbol"] s = info["symbol"]
if info["dir"] == Dir.BUY: if info["dir"] == Dir.BUY:
om.future_positions[sym] -= size om.future_positions[s] -= size
else: else:
om.future_positions[sym] += size om.future_positions[s] += size
om.cancel(oid) om.cancel(oid)
stock_orders.pop(oid, None) 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: if bid_price is None or ask_price is None:
return return
mid = (bid_price + ask_price) // 2 mid = (bid_price + ask_price) // 2
our_bid = mid - STOCK_SPREAD our_bid = mid - STOCK_SPREAD
our_ask = mid + STOCK_SPREAD our_ask = mid + STOCK_SPREAD
pos = om.positions[sym] pos = om.positions[sym]
limit = STOCK_MAX_POSITION limit = STOCK_MAX_POSITION
# 기존 해당 심볼 주문 취소
cancel_stock_orders(sym) cancel_stock_orders(sym)
buy_sz = max(0, min(STOCK_ORDER_SIZE, limit - pos)) buy_sz = max(0, min(STOCK_ORDER_SIZE, limit - pos))
@@ -206,7 +205,8 @@ for sym_info in hello_message["symbols"]: # "symbol" → "symbols"
# ── XLF 차익거래 ───────────────────────────────────────────── # ── XLF 차익거래 ─────────────────────────────────────────────
def try_xlf_arb(): def try_xlf_arb():
nonlocal xlf_state, xlf_direction, xlf_pending, xlf_arb_size, xlf_convert_oid # nonlocalxlf_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": if not market_open or xlf_state != "IDLE":
return return
@@ -505,7 +505,7 @@ for sym_info in hello_message["symbols"]: # "symbol" → "symbols"
if sym in ["VALE", "VALBZ"]: if sym in ["VALE", "VALBZ"]:
try_vale_arb() try_vale_arb()
# GS/MS/WFC 마켓 메이킹 갱신 (호가 바뀔 때마다) # GS/MS/WFC 마켓 메이킹 갱신 (2초마다)
if sym in ("GS", "MS", "WFC") and xlf_state == "IDLE": if sym in ("GS", "MS", "WFC") and xlf_state == "IDLE":
now = time.time() now = time.time()
if now - last_stock_refresh > 2.0: if now - last_stock_refresh > 2.0: