This commit is contained in:
2026-05-09 15:53:00 +09:00
parent ad49153cfc
commit e826defc15

View File

@@ -46,7 +46,7 @@ def main():
# pick? Also, you will need to send more orders over time. # pick? Also, you will need to send more orders over time.
# --- 설정 --- # --- 설정 ---
BOND_FAIR_VALUE = 1000 # BOND fair value (고정) BOND_FAIR_VALUE = 1000 # BOND fair value (고정)
BOND_ORDER_SIZE = 80 # BOND 주문당 수량 (크게 설정해서 체결 기회 극대화) BOND_ORDER_SIZE = 50 # BOND 주문당 수량 (한도 초과 방지)
XLF_CONVERSION_FEE = 100 # XLF 변환 비용 XLF_CONVERSION_FEE = 100 # XLF 변환 비용
VALE_CONVERSION_FEE = 10 # VALE 변환 비용 VALE_CONVERSION_FEE = 10 # VALE 변환 비용
VALE_ARB_SIZE = 10 # VALE 차익거래 단위 VALE_ARB_SIZE = 10 # VALE 차익거래 단위
@@ -58,7 +58,7 @@ def main():
xlf_state = "IDLE" xlf_state = "IDLE"
xlf_pending = {} xlf_pending = {}
xlf_direction = None xlf_direction = None
xlf_arb_size = 0 # 현재 차익거래 수량 추적 xlf_arb_size = 0
# VALE state machine # VALE state machine
# IDLE → BUYING_VALBZ → CONVERTING → SELLING_VALE → IDLE # IDLE → BUYING_VALBZ → CONVERTING → SELLING_VALE → IDLE
@@ -66,7 +66,7 @@ def main():
vale_state = "IDLE" vale_state = "IDLE"
vale_pending = {} vale_pending = {}
vale_direction = None vale_direction = None
vale_arb_size = 0 # 현재 차익거래 수량 추적 vale_arb_size = 0
state = StateManager() state = StateManager()
om = OrderManager(exchange) om = OrderManager(exchange)
@@ -111,8 +111,8 @@ def main():
sell_size = base_size sell_size = base_size
# 포지션 한도 초과 방지 # 포지션 한도 초과 방지
buy_size = min(buy_size, 100 - position) buy_size = max(0, min(buy_size, 100 - position))
sell_size = min(sell_size, 100 + position) sell_size = max(0, min(sell_size, 100 + position))
if buy_size > 0: if buy_size > 0:
bid = next_id() bid = next_id()
@@ -325,16 +325,16 @@ def main():
vale_direction = None vale_direction = None
elif message["type"] == "ack": elif message["type"] == "ack":
# XLF 변환 ack 처리 # XLF 변환 ack 처리 - om.positions 직접 수정
if xlf_state == "CONVERTING": if xlf_state == "CONVERTING":
print(" XLF 변환 완료 → 매도 시작") print(" XLF 변환 완료 → 매도 시작")
if xlf_direction == "BASKET_TO_XLF": if xlf_direction == "BASKET_TO_XLF":
# 변환: BOND -3, GS -2, MS -3, WFC -2, XLF +10 # 변환: BOND -3, GS -2, MS -3, WFC -2, XLF +10
om.update_position("BOND", -1, -3) om.positions["BOND"] -= 3
om.update_position("GS", -1, -2) om.positions["GS"] -= 2
om.update_position("MS", -1, -3) om.positions["MS"] -= 3
om.update_position("WFC", -1, -2) om.positions["WFC"] -= 2
om.update_position("XLF", -1, xlf_arb_size) om.positions["XLF"] += xlf_arb_size
xlf_state = "SELLING_XLF" xlf_state = "SELLING_XLF"
oid = next_id() oid = next_id()
exchange.send_add_message( exchange.send_add_message(
@@ -343,11 +343,11 @@ def main():
xlf_pending[oid] = xlf_arb_size xlf_pending[oid] = xlf_arb_size
elif xlf_direction == "XLF_TO_BASKET": elif xlf_direction == "XLF_TO_BASKET":
# 변환: XLF -10, BOND +3, GS +2, MS +3, WFC +2 # 변환: XLF -10, BOND +3, GS +2, MS +3, WFC +2
om.update_position("XLF", -1, -xlf_arb_size) om.positions["XLF"] -= xlf_arb_size
om.update_position("BOND", -1, 3) om.positions["BOND"] += 3
om.update_position("GS", -1, 2) om.positions["GS"] += 2
om.update_position("MS", -1, 3) om.positions["MS"] += 3
om.update_position("WFC", -1, 2) om.positions["WFC"] += 2
xlf_state = "SELLING_BASKET" xlf_state = "SELLING_BASKET"
for sym, qty in [("BOND", 3), ("GS", 2), ("MS", 3), ("WFC", 2)]: for sym, qty in [("BOND", 3), ("GS", 2), ("MS", 3), ("WFC", 2)]:
oid = next_id() oid = next_id()
@@ -356,13 +356,13 @@ def main():
) )
xlf_pending[oid] = qty xlf_pending[oid] = qty
# VALE 변환 ack 처리 # VALE 변환 ack 처리 - om.positions 직접 수정
elif vale_state == "CONVERTING": elif vale_state == "CONVERTING":
print(" VALE 변환 완료 → 매도 시작") print(" VALE 변환 완료 → 매도 시작")
if vale_direction == "VALBZ_TO_VALE": if vale_direction == "VALBZ_TO_VALE":
# 변환: VALBZ -size, VALE +size # 변환: VALBZ -size, VALE +size
om.update_position("VALBZ", -1, -vale_arb_size) om.positions["VALBZ"] -= vale_arb_size
om.update_position("VALE", -1, vale_arb_size) om.positions["VALE"] += vale_arb_size
vale_state = "SELLING_VALE" vale_state = "SELLING_VALE"
oid = next_id() oid = next_id()
exchange.send_add_message( exchange.send_add_message(
@@ -371,8 +371,8 @@ def main():
vale_pending[oid] = vale_arb_size vale_pending[oid] = vale_arb_size
elif vale_direction == "VALE_TO_VALBZ": elif vale_direction == "VALE_TO_VALBZ":
# 변환: VALE -size, VALBZ +size # 변환: VALE -size, VALBZ +size
om.update_position("VALE", -1, -vale_arb_size) om.positions["VALE"] -= vale_arb_size
om.update_position("VALBZ", -1, vale_arb_size) om.positions["VALBZ"] += vale_arb_size
vale_state = "SELLING_VALBZ" vale_state = "SELLING_VALBZ"
oid = next_id() oid = next_id()
exchange.send_add_message( exchange.send_add_message(