bot split sex
This commit is contained in:
52
bot split/order_new.py
Normal file
52
bot split/order_new.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import time
|
||||
from collections import deque
|
||||
from ETC import ExchangeConnection, Dir
|
||||
from position import PositionManager
|
||||
|
||||
class OrderManager:
|
||||
def __init__(self, exchange: ExchangeConnection, positionMan: PositionManager):
|
||||
self.exchange = exchange
|
||||
self._order_size = 0
|
||||
|
||||
self._send_timestamps = deque(maxlen=500)
|
||||
|
||||
self.positionMan = positionMan
|
||||
|
||||
def _next_order(self):
|
||||
self._order_size += 1
|
||||
return self._order_size
|
||||
|
||||
def _attempt_send(self, action_type: str, symbol: str, dir: Dir, price: int, size: int) -> bool:
|
||||
"""
|
||||
주문 전송을 시도합니다.
|
||||
제한에 걸려 무시되면 False를, 정상 전송되면 True를 반환합니다.
|
||||
"""
|
||||
now = time.time()
|
||||
|
||||
if len(self._send_timestamps) == 500:
|
||||
elapsed = now - self._send_timestamps[0]
|
||||
if elapsed < 1.01:
|
||||
return False
|
||||
|
||||
# 전송 조건 통과 시 실제 통신 수행
|
||||
if action_type == "add":
|
||||
self.exchange.send_add_message(symbol=symbol, dir=dir, price=price, size=size)
|
||||
elif action_type == "cancel":
|
||||
self.exchange.send_cancel_message(symbol=symbol, dir=dir, price=price, size=size)
|
||||
elif action_type == "convert":
|
||||
self.exchange.send_convert_message(symbol=symbol, dir=dir, price=price, size=size)
|
||||
|
||||
self._send_timestamps.append(now)
|
||||
return True
|
||||
|
||||
def sell(self, symbol: str, dir: Dir, price: int, size: int):
|
||||
return self._attempt_send("add", order_id=self._next_order(), symbol=symbol, dir=dir, price=price, size=size)
|
||||
|
||||
def buy(self, symbol: str, dir: Dir, price: int, size: int):
|
||||
return self._attempt_send("add", order_id=self._next_order(), symbol=symbol, dir=dir, price=price, size=size)
|
||||
|
||||
def convert(self, symbol: str, dir: Dir, size: int):
|
||||
return self._attempt_send("convert", order_id=self._next_order(), symbol=symbol, dir=dir, size=size)
|
||||
|
||||
def cancel(self, order_id: int):
|
||||
return self._attempt_send("cancel", order_id=order_id)
|
||||
Reference in New Issue
Block a user