Exemple #1
0
 def __init__(self,
              k2_api_key: str,
              k2_secret_key: str,
              trading_pairs: Optional[List[str]] = None,
              trading_required: bool = True):
     """
     :param k2_api_key: The API key to connect to private K2 APIs.
     :param k2_secret_key: The API secret.
     :param trading_pairs: The market trading pairs which to track order book data.
     :param trading_required: Whether actual trading is needed.
     """
     super().__init__()
     self._trading_required = trading_required
     self._trading_pairs = trading_pairs
     self._k2_auth = K2Auth(k2_api_key, k2_secret_key)
     self._order_book_tracker = K2OrderBookTracker(
         trading_pairs=trading_pairs)
     self._user_stream_tracker = K2UserStreamTracker(
         self._k2_auth, trading_pairs)
     self._ev_loop = asyncio.get_event_loop()
     self._shared_client = None
     self._poll_notifier = asyncio.Event()
     self._last_timestamp = 0
     self._in_flight_orders = {
     }  # Dict[client_order_id:str, K2InFlightOrder]
     self._order_not_found_records = {
     }  # Dict[client_order_id:str, count:int]
     self._trading_rules = {}  # Dict[trading_pair:str, TradingRule]
     self._status_polling_task = None
     self._user_stream_tracker_task = None
     self._user_stream_event_listener_task = None
     self._trading_rules_polling_task = None
     self._last_poll_timestamp = 0
Exemple #2
0
 def setUpClass(cls):
     cls.ev_loop: asyncio.BaseEventLoop = asyncio.get_event_loop()
     cls.k2_auth = K2Auth(cls.api_key, cls.api_secret)
     cls.trading_pairs = ["ETH-USD"]
     cls.user_stream_tracker: K2UserStreamTracker = K2UserStreamTracker(
         k2_auth=cls.k2_auth, trading_pairs=cls.trading_pairs)
     cls.user_stream_tracker_task: asyncio.Task = safe_ensure_future(cls.user_stream_tracker.start())
Exemple #3
0
 def setUpClass(cls):
     cls.ev_loop: asyncio.BaseEventLoop = asyncio.get_event_loop()
     api_key = conf.k2_api_key
     secret_key = conf.k2_secret_key
     cls.auth: K2Auth = K2Auth(api_key, secret_key)