add: bot bond selling
This commit is contained in:
@@ -44,10 +44,14 @@ 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 마켓 메이킹 설정 ---
|
# --- BOND 마켓 메이킹 설정 ---
|
||||||
FAIR_VALUE = 1000 # BOND fair value (고정)
|
FAIR_VALUE = 1000 # BOND fair value (고정)
|
||||||
ORDER_SIZE = 10 # 주문당 기본 수량
|
ORDER_SIZE = 5 # 가격대별 주문 수량
|
||||||
MAX_POSITION = 100 # 최대 포지션 한도
|
MAX_POSITION = 100 # 최대 포지션 한도
|
||||||
REFRESH_INTERVAL = 5.0 # 주문 갱신 주기 (초)
|
REFRESH_INTERVAL = 5.0 # 주문 갱신 주기 (초)
|
||||||
|
|
||||||
|
# 매수: 999, 998, 997 / 매도: 1001, 1002, 1003
|
||||||
|
BUY_PRICES = [FAIR_VALUE - 1, FAIR_VALUE - 2, FAIR_VALUE - 3]
|
||||||
|
SELL_PRICES = [FAIR_VALUE + 1, FAIR_VALUE + 2, FAIR_VALUE + 3]
|
||||||
|
|
||||||
position = 0 # 현재 BOND 포지션
|
position = 0 # 현재 BOND 포지션
|
||||||
order_id = 0 # 단조 증가하는 주문 ID
|
order_id = 0 # 단조 증가하는 주문 ID
|
||||||
active_orders = {} # {order_id: {"dir": ..., "price": ...}}
|
active_orders = {} # {order_id: {"dir": ..., "price": ...}}
|
||||||
@@ -65,33 +69,29 @@ def main():
|
|||||||
active_orders.pop(oid, None)
|
active_orders.pop(oid, None)
|
||||||
|
|
||||||
def place_bond_orders():
|
def place_bond_orders():
|
||||||
"""포지션 한도 안에서 bid/ask 양방향 주문"""
|
"""여러 가격대에 분산해서 매수/매도 주문"""
|
||||||
if not market_open:
|
if not market_open:
|
||||||
return
|
return
|
||||||
|
|
||||||
cancel_all_bond_orders()
|
cancel_all_bond_orders()
|
||||||
|
|
||||||
buy_price = FAIR_VALUE - 1 # 999
|
# 포지션에 따라 size 조정
|
||||||
sell_price = FAIR_VALUE + 1 # 1001
|
|
||||||
|
|
||||||
# 포지션이 음수일수록 매수 size 크게, 매도 size 작게
|
|
||||||
# 포지션이 양수일수록 매도 size 크게, 매수 size 작게
|
|
||||||
base_size = ORDER_SIZE
|
base_size = ORDER_SIZE
|
||||||
adjustment = abs(position) // 5 # 포지션 5마다 1씩 조정
|
adjustment = abs(position) // 5
|
||||||
|
|
||||||
if position < 0:
|
if position < 0:
|
||||||
# 숏 포지션 → 매수를 더 많이
|
buy_size = min(base_size + adjustment, MAX_POSITION)
|
||||||
buy_size = min(base_size + adjustment, MAX_POSITION - position)
|
|
||||||
sell_size = max(base_size - adjustment, 1)
|
sell_size = max(base_size - adjustment, 1)
|
||||||
elif position > 0:
|
elif position > 0:
|
||||||
# 롱 포지션 → 매도를 더 많이
|
|
||||||
buy_size = max(base_size - adjustment, 1)
|
buy_size = max(base_size - adjustment, 1)
|
||||||
sell_size = min(base_size + adjustment, MAX_POSITION + position)
|
sell_size = min(base_size + adjustment, MAX_POSITION)
|
||||||
else:
|
else:
|
||||||
buy_size = base_size
|
buy_size = base_size
|
||||||
sell_size = base_size
|
sell_size = base_size
|
||||||
|
|
||||||
if buy_size > 0:
|
# 999, 998, 997 세 가격대에 매수 주문
|
||||||
|
for buy_price in BUY_PRICES:
|
||||||
|
if position < MAX_POSITION:
|
||||||
bid = next_id()
|
bid = next_id()
|
||||||
exchange.send_add_message(
|
exchange.send_add_message(
|
||||||
order_id=bid, symbol="BOND",
|
order_id=bid, symbol="BOND",
|
||||||
@@ -99,7 +99,9 @@ def main():
|
|||||||
)
|
)
|
||||||
active_orders[bid] = {"dir": Dir.BUY, "price": buy_price}
|
active_orders[bid] = {"dir": Dir.BUY, "price": buy_price}
|
||||||
|
|
||||||
if sell_size > 0:
|
# 1001, 1002, 1003 세 가격대에 매도 주문
|
||||||
|
for sell_price in SELL_PRICES:
|
||||||
|
if position > -MAX_POSITION:
|
||||||
ask = next_id()
|
ask = next_id()
|
||||||
exchange.send_add_message(
|
exchange.send_add_message(
|
||||||
order_id=ask, symbol="BOND",
|
order_id=ask, symbol="BOND",
|
||||||
@@ -107,7 +109,7 @@ def main():
|
|||||||
)
|
)
|
||||||
active_orders[ask] = {"dir": Dir.SELL, "price": sell_price}
|
active_orders[ask] = {"dir": Dir.SELL, "price": sell_price}
|
||||||
|
|
||||||
print(f" BOND 주문 → 매수: {buy_price} x{buy_size}, 매도: {sell_price} x{sell_size}, 포지션: {position}")
|
print(f" BOND 주문 → 매수: {BUY_PRICES} x{buy_size}, 매도: {SELL_PRICES} x{sell_size}, 포지션: {position}")
|
||||||
|
|
||||||
# Set up some variables to track the bid and ask price of a symbol. Right
|
# Set up some variables to track the bid and ask price of a symbol. Right
|
||||||
# now this doesn't track much information, but it's enough to get a sense
|
# now this doesn't track much information, but it's enough to get a sense
|
||||||
@@ -123,7 +125,7 @@ def main():
|
|||||||
# the message). Feel free to modify any of the starter code below.
|
# the message). Feel free to modify any of the starter code below.
|
||||||
#
|
#
|
||||||
# Note: a common mistake people make is to call write_message() at least
|
# Note: a common mistake people make is to call write_message() at least
|
||||||
# once for every read_message() response.
|
# once for every read_machine() response.
|
||||||
#
|
#
|
||||||
# Every message sent to the exchange generates at least one response
|
# Every message sent to the exchange generates at least one response
|
||||||
# message. Sending a message in response to every exchange message will
|
# message. Sending a message in response to every exchange message will
|
||||||
|
|||||||
Reference in New Issue
Block a user