示例#1
0
    def test_get_rest_assistant(self):
        factory = WebAssistantsFactory()

        rest_assistant = self.async_run_with_timeout(
            factory.get_rest_assistant())

        self.assertIsInstance(rest_assistant, RESTAssistant)
示例#2
0
    def test_get_ws_assistant(self):
        factory = WebAssistantsFactory(throttler=AsyncThrottler(
            rate_limits=[]))

        ws_assistant = self.async_run_with_timeout(factory.get_ws_assistant())

        self.assertIsInstance(ws_assistant, WSAssistant)
def build_api_factory(throttler: AsyncThrottler,
                      auth: Optional[AuthBase] = None) -> WebAssistantsFactory:
    api_factory = WebAssistantsFactory(
        throttler=throttler,
        auth=auth,
        rest_pre_processors=[CoinflexRESTPreProcessor()])
    return api_factory
def build_api_factory(
        throttler: Optional[AsyncThrottler] = None,
        auth: Optional[AuthBase] = None) -> WebAssistantsFactory:
    throttler = throttler or create_throttler()
    api_factory = WebAssistantsFactory(
        throttler=throttler,
        auth=auth)
    return api_factory
def build_api_factory(
        throttler: Optional[AsyncThrottler] = None,
        auth: Optional[AuthBase] = None) -> WebAssistantsFactory:
    throttler = throttler or create_throttler()
    api_factory = WebAssistantsFactory(
        throttler=throttler,
        auth=auth,
        rest_pre_processors=[CoinflexPerpetualRESTPreProcessor()])
    return api_factory
def build_api_factory(auth: Optional[AuthBase] = None) -> WebAssistantsFactory:

    throttler = create_throttler()
    api_factory = WebAssistantsFactory(throttler=throttler,
                                       auth=auth,
                                       rest_pre_processors=[
                                           BitmexPerpetualRESTPreProcessor(),
                                       ])
    return api_factory
示例#7
0
def build_api_factory(auth: Optional[AuthBase] = None) -> WebAssistantsFactory:
    """
    Builds an API factory with custom REST preprocessors

    :param auth: authentication class for private requests

    :return: API factory
    """
    api_factory = WebAssistantsFactory(
        auth=auth, rest_pre_processors=[AscendExRESTPreProcessor()])
    return api_factory
示例#8
0
    def setUp(self) -> None:
        super().setUp()
        self.mocking_assistant = NetworkMockingAssistant()
        self.throttler = AsyncThrottler(CONSTANTS.RATE_LIMITS)
        api_factory = WebAssistantsFactory()
        self.data_source = GateIoAPIOrderBookDataSource(
            self.throttler, trading_pairs=[self.trading_pair], api_factory=api_factory
        )
        self.data_source.logger().setLevel(1)
        self.data_source.logger().addHandler(self)

        self.log_records = []
        self.async_tasks: List[asyncio.Task] = []
    async def trading_pair_symbol_map(
            cls,
            domain: Optional[str] = CONSTANTS.DOMAIN,
            throttler: Optional[AsyncThrottler] = None,
            api_factory: WebAssistantsFactory = None) -> Mapping[str, str]:
        if not cls.trading_pair_symbol_map_ready(domain=domain):
            api_factory = WebAssistantsFactory(throttler)
            async with cls._mapping_initialization_lock:
                # Check condition again (could have been initialized while waiting for the lock to be released)
                if not cls.trading_pair_symbol_map_ready(domain=domain):
                    await cls.init_trading_pair_symbols(
                        domain, throttler, api_factory)

        return cls._trading_pair_symbol_map[domain]
def build_api_factory(throttler: AsyncThrottler,
                      auth: Optional[AuthBase] = None) -> WebAssistantsFactory:
    """
    Builds an API factory with custom REST preprocessors

    :param throttler: throttler instance to enforce rate limits
    :param auth: authentication class for private requests

    :return: API factory
    """
    api_factory = WebAssistantsFactory(
        throttler=throttler,
        auth=auth,
        rest_pre_processors=[AscendExRESTPreProcessor()])
    return api_factory
def build_api_factory(
        throttler: Optional[AsyncThrottler] = None,
        time_synchronizer: Optional[TimeSynchronizer] = None,
        time_provider: Optional[Callable] = None,
        auth: Optional[AuthBase] = None, ) -> WebAssistantsFactory:
    throttler = throttler or create_throttler()
    time_synchronizer = time_synchronizer or TimeSynchronizer()
    time_provider = time_provider or (lambda: get_current_server_time(throttler=throttler))
    api_factory = WebAssistantsFactory(
        throttler=throttler,
        auth=auth,
        rest_pre_processors=[
            TimeSynchronizerRESTPreProcessor(synchronizer=time_synchronizer, time_provider=time_provider),
        ])
    return api_factory
示例#12
0
def build_api_factory(
    throttler: Optional[AsyncThrottler] = None,
    time_synchronizer: Optional[TimeSynchronizer] = None,
    domain: str = CONSTANTS.DEFAULT_DOMAIN,
    time_provider: Optional[Callable] = None,
    auth: Optional[AuthBase] = None,
) -> WebAssistantsFactory:
    time_synchronizer = time_synchronizer or TimeSynchronizer()
    time_provider = time_provider or (lambda: get_current_server_time(
        throttler=throttler,
        domain=domain,
    ))
    api_factory = WebAssistantsFactory(auth=auth,
                                       rest_pre_processors=[
                                           TimeSynchronizerRESTPreProcessor(
                                               synchronizer=time_synchronizer,
                                               time_provider=time_provider),
                                       ])
    return api_factory
    def __init__(
        self,
        trading_pairs: List[str] = None,
        domain: str = CONSTANTS.DOMAIN,
        throttler: Optional[AsyncThrottler] = None,
        api_factory: Optional[WebAssistantsFactory] = None,
    ):
        super().__init__(trading_pairs)
        self._api_factory: WebAssistantsFactory = WebAssistantsFactory(
            throttler)
        self._api_factory: WebAssistantsFactory = api_factory or web_utils.build_api_factory(
        )
        self._ws_assistant: Optional[WSAssistant] = None
        self._order_book_create_function = lambda: OrderBook()
        self._domain = domain
        self._throttler = throttler or self._get_throttler_instance()
        self._funding_info: Dict[str, FundingInfo] = {}

        self._message_queue: Dict[int,
                                  asyncio.Queue] = defaultdict(asyncio.Queue)
示例#14
0
 def __init__(self,
              binance_api_key: str,
              binance_api_secret: str,
              trading_pairs: Optional[List[str]] = None,
              trading_required: bool = True,
              domain="com"):
     self._domain = domain
     self._binance_time_synchronizer = TimeSynchronizer()
     super().__init__()
     self._trading_required = trading_required
     self._auth = BinanceAuth(api_key=binance_api_key,
                              secret_key=binance_api_secret,
                              time_provider=self._binance_time_synchronizer)
     self._api_factory = WebAssistantsFactory(auth=self._auth)
     self._rest_assistant = None
     self._throttler = AsyncThrottler(CONSTANTS.RATE_LIMITS)
     self._order_book_tracker = BinanceOrderBookTracker(
         trading_pairs=trading_pairs,
         domain=domain,
         api_factory=self._api_factory,
         throttler=self._throttler)
     self._user_stream_tracker = BinanceUserStreamTracker(
         auth=self._auth, domain=domain, throttler=self._throttler)
     self._ev_loop = asyncio.get_event_loop()
     self._poll_notifier = asyncio.Event()
     self._last_timestamp = 0
     self._order_not_found_records = {
     }  # Dict[client_order_id:str, count:int]
     self._trading_rules = {}  # Dict[trading_pair:str, TradingRule]
     self._trade_fees = {
     }  # Dict[trading_pair:str, (maker_fee_percent:Decimal, taken_fee_percent:Decimal)]
     self._last_update_trade_fees_timestamp = 0
     self._status_polling_task = None
     self._user_stream_event_listener_task = None
     self._trading_rules_polling_task = None
     self._last_poll_timestamp = 0
     self._last_trades_poll_binance_timestamp = 0
     self._order_tracker: ClientOrderTracker = ClientOrderTracker(
         connector=self)
示例#15
0
def build_api_factory(auth: Optional[AuthBase] = None) -> WebAssistantsFactory:
    api_factory = WebAssistantsFactory(
        auth=auth, rest_pre_processors=[BinancePerpetualRESTPreProcessor()])
    return api_factory
示例#16
0
def build_api_factory_without_time_synchronizer_pre_processor(
) -> WebAssistantsFactory:
    api_factory = WebAssistantsFactory()
    return api_factory
def build_api_factory_without_time_synchronizer_pre_processor(
        throttler: AsyncThrottler) -> WebAssistantsFactory:
    return WebAssistantsFactory(throttler=throttler,
                                ws_pre_processors=[LatokenWSPreProcessor()],
                                ws_post_processors=[LatokenWSPostProcessor()])
示例#18
0
    def test_get_ws_assistant(self):
        factory = WebAssistantsFactory()

        ws_assistant = self.async_run_with_timeout(factory.get_ws_assistant())

        self.assertIsInstance(ws_assistant, WSAssistant)
示例#19
0
def build_api_factory() -> WebAssistantsFactory:
    throttler = AsyncThrottler(rate_limits=[])
    api_factory = WebAssistantsFactory(
        throttler=throttler, ws_post_processors=[HuobiWSPostProcessor()])
    return api_factory
def build_api_factory() -> WebAssistantsFactory:
    api_factory = WebAssistantsFactory(throttler=AsyncThrottler(
        rate_limits=[]))
    return api_factory
def build_api_factory_without_time_synchronizer_pre_processor(
        throttler: AsyncThrottler) -> WebAssistantsFactory:
    api_factory = WebAssistantsFactory(
        throttler=throttler,
        rest_pre_processors=[BinancePerpetualRESTPreProcessor()])
    return api_factory
示例#22
0
def build_api_factory(throttler: AsyncThrottler) -> WebAssistantsFactory:
    api_factory = WebAssistantsFactory(throttler=throttler)
    return api_factory
示例#23
0
def build_api_factory(throttler: AsyncThrottlerBase) -> WebAssistantsFactory:
    throttler = throttler or AsyncThrottler(rate_limits=[])
    api_factory = WebAssistantsFactory(throttler=throttler)
    return api_factory
def build_api_factory_without_time_synchronizer_pre_processor(throttler: AsyncThrottler) -> WebAssistantsFactory:
    api_factory = WebAssistantsFactory(throttler=throttler)
    return api_factory
示例#25
0
def build_api_factory() -> WebAssistantsFactory:
    api_factory = WebAssistantsFactory()
    return api_factory
示例#26
0
def build_api_factory() -> WebAssistantsFactory:
    api_factory = WebAssistantsFactory(
        ws_post_processors=[HuobiWSPostProcessor()])
    return api_factory
示例#27
0
def build_coinbase_pro_web_assistant_factory(auth: Optional['CoinbaseProAuth'] = None) -> WebAssistantsFactory:
    """The web-assistant's composition root."""
    throttler = AsyncThrottler(rate_limits=[])
    api_factory = WebAssistantsFactory(throttler=throttler, auth=auth)
    return api_factory