add: bot bond selling
This commit is contained in:
@@ -43,10 +43,9 @@ def main():
|
||||
# unlikely it will be traded against. Maybe there is a better price to
|
||||
# pick? Also, you will need to send more orders over time.
|
||||
# --- BOND 마켓 메이킹 설정 ---
|
||||
FAIR_VALUE = 1000 # BOND fair value (고정)
|
||||
SPREAD = 1 # fair value 기준 ±1 (999 매수 / 1001 매도)
|
||||
FAIR_VALUE = 1000 # BOND fair value (고정, 설명서 명시)
|
||||
ORDER_SIZE = 10 # 주문당 수량
|
||||
MAX_POSITION = 100 # 최대 포지션 한도
|
||||
MAX_POSITION = 100 # 포지션 한도 (설명서: BOND limit = 100)
|
||||
REFRESH_INTERVAL = 5.0 # 주문 갱신 주기 (초)
|
||||
|
||||
position = 0 # 현재 BOND 포지션
|
||||
@@ -54,6 +53,10 @@ def main():
|
||||
active_orders = {} # {order_id: {"dir": ..., "price": ...}}
|
||||
market_open = False # 시장 open 여부 (open 전에는 주문 불가)
|
||||
|
||||
# 호가창에서 파악한 BOND 최우선 bid/ask
|
||||
bond_best_bid = None
|
||||
bond_best_ask = None
|
||||
|
||||
def next_id():
|
||||
nonlocal order_id
|
||||
order_id += 1
|
||||
@@ -66,14 +69,23 @@ def main():
|
||||
active_orders.pop(oid, None)
|
||||
|
||||
def place_bond_orders():
|
||||
"""포지션 한도 안에서 bid/ask 양방향 주문"""
|
||||
"""호가창 기반으로 경쟁자보다 1틱 더 좋은 가격에 주문"""
|
||||
if not market_open:
|
||||
return
|
||||
|
||||
cancel_all_bond_orders()
|
||||
|
||||
buy_price = FAIR_VALUE - SPREAD # 999
|
||||
sell_price = FAIR_VALUE + SPREAD # 1001
|
||||
# 호가창 정보가 없으면 기본값 사용
|
||||
best_bid = bond_best_bid if bond_best_bid is not None else 999
|
||||
best_ask = bond_best_ask if bond_best_ask is not None else 1001
|
||||
|
||||
# 경쟁자보다 1틱 더 좋은 가격, 단 fair value를 절대 넘지 않음
|
||||
# 매수: 경쟁자 bid + 1 (단, fair value - 1 이하)
|
||||
# 매도: 경쟁자 ask - 1 (단, fair value + 1 이상)
|
||||
buy_price = min(best_bid + 1, FAIR_VALUE - 1) # 최대 999
|
||||
sell_price = max(best_ask - 1, FAIR_VALUE + 1) # 최소 1001
|
||||
|
||||
print(f" BOND 주문 → 매수: {buy_price}, 매도: {sell_price}")
|
||||
|
||||
# 포지션이 한도에 걸리면 한쪽 방향 주문 스킵
|
||||
if position < MAX_POSITION:
|
||||
@@ -147,6 +159,17 @@ def main():
|
||||
print(f" → BOND position: {position}")
|
||||
place_bond_orders()
|
||||
elif message["type"] == "book":
|
||||
if message["symbol"] == "BOND":
|
||||
# BOND 호가창 업데이트 → 가격 재계산 후 주문 갱신
|
||||
bond_best_bid = message["buy"][0][0] if message["buy"] else None
|
||||
bond_best_ask = message["sell"][0][0] if message["sell"] else None
|
||||
|
||||
# 호가창이 바뀔 때마다 주문 갱신 (단, rate limit 주의)
|
||||
now = time.time()
|
||||
if now - last_refresh > REFRESH_INTERVAL:
|
||||
last_refresh = now
|
||||
place_bond_orders()
|
||||
|
||||
if message["symbol"] == "VALE":
|
||||
|
||||
def best_price(side):
|
||||
@@ -167,12 +190,6 @@ def main():
|
||||
}
|
||||
)
|
||||
|
||||
# 주기적으로 BOND 주문 갱신 (주문 만료 방지)
|
||||
now = time.time()
|
||||
if now - last_refresh > REFRESH_INTERVAL:
|
||||
last_refresh = now
|
||||
place_bond_orders()
|
||||
|
||||
|
||||
# ~~~~~============== PROVIDED CODE ==============~~~~~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user