diff --git a/bot bond sell.py b/bot bond sell.py index b9adc7d..9b74047 100644 --- a/bot bond sell.py +++ b/bot bond sell.py @@ -52,6 +52,7 @@ def main(): position = 0 # 현재 BOND 포지션 order_id = 0 # 단조 증가하는 주문 ID active_orders = {} # {order_id: {"dir": ..., "price": ...}} + market_open = False # 시장 open 여부 (open 전에는 주문 불가) def next_id(): nonlocal order_id @@ -66,6 +67,9 @@ def main(): def place_bond_orders(): """포지션 한도 안에서 bid/ask 양방향 주문""" + if not market_open: + return + cancel_all_bond_orders() buy_price = FAIR_VALUE - SPREAD # 999 @@ -88,9 +92,6 @@ def main(): ) active_orders[ask] = {"dir": Dir.SELL, "price": sell_price} - # 시작 시 첫 BOND 주문 배치 - place_bond_orders() - # 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 # of the VALE market. @@ -124,9 +125,10 @@ def main(): print("The round has ended") break elif message["type"] == "open": - print("Market opened:", message) - market_open = True - place_bond_orders() # open 받은 후에만 주문 + # 시장이 열렸을 때 주문 시작 (open 전에 주문하면 reject됨) + print("Market opened:", message) + market_open = True + place_bond_orders() elif message["type"] == "error": print(message) elif message["type"] == "reject": @@ -207,15 +209,15 @@ class ExchangeConnection: ): """Add a new order""" self._write_message( - { - "type": "add", - "order_id": order_id, - "symbol": symbol, - "dir": dir, - "price": price, - "size": size, - "tif" : "GFD", # Good-For-Day (주문이 체결되거나 취소될 때까지 유효) - } + { + "type": "add", + "order_id": order_id, + "symbol": symbol, + "dir": dir, + "price": price, + "size": size, + "tif": "DAY", # 설명서 필수 필드: DAY or IOC + } ) def send_convert_message(self, order_id: int, symbol: str, dir: Dir, size: int):