def setUpClass(cls): cls.ev_loop = asyncio.get_event_loop() if API_MOCK_ENABLED: cls.web_app = MockWebServer.get_instance() cls.web_app.add_host_to_mock(API_HOST, ["/products", "/currencies"]) cls.web_app.start() cls.ev_loop.run_until_complete(cls.web_app.wait_til_started()) cls._patcher = mock.patch("aiohttp.client.URL") cls._url_mock = cls._patcher.start() cls._url_mock.side_effect = cls.web_app.reroute_local cls.web_app.update_response("get", API_HOST, "/fiat_accounts", FixtureLiquid.FIAT_ACCOUNTS) cls.web_app.update_response("get", API_HOST, "/crypto_accounts", FixtureLiquid.CRYPTO_ACCOUNTS) cls.web_app.update_response("get", API_HOST, "/orders", FixtureLiquid.ORDERS_GET) cls._t_nonce_patcher = unittest.mock.patch( "hummingbot.connector.exchange.liquid.liquid_exchange.get_tracking_nonce") cls._t_nonce_mock = cls._t_nonce_patcher.start() cls.clock: Clock = Clock(ClockMode.REALTIME) cls.market: LiquidExchange = LiquidExchange( API_KEY, API_SECRET, poll_interval=5, trading_pairs=['CEL-ETH'], ) # cls.ev_loop.run_until_complete(cls.market._update_balances()) print("Initializing Liquid market... this will take about a minute.") cls.clock.add_iterator(cls.market) cls.stack: contextlib.ExitStack = contextlib.ExitStack() cls._clock = cls.stack.enter_context(cls.clock) cls.ev_loop.run_until_complete(cls.wait_til_ready()) print("Ready.")
def setUpClass(cls): cls.ev_loop: asyncio.BaseEventLoop = asyncio.get_event_loop() if MOCK_API_ENABLED: cls.web_app = MockWebServer.get_instance() cls.web_app.add_host_to_mock(API_BASE_URL, []) cls.web_app.start() cls.ev_loop.run_until_complete(cls.web_app.wait_til_started()) cls._patcher = mock.patch("aiohttp.client.URL") cls._url_mock = cls._patcher.start() cls._url_mock.side_effect = cls.web_app.reroute_local # mock_account_id = FixtureOKEx.GET_ACCOUNTS["data"][0]["id"] # warning: second parameter starts with / cls.web_app.update_response( "get", API_BASE_URL, cls.strip_host_from_okex_url(OKEX_INSTRUMENTS_URL), FixtureOKEx.OKEX_INSTRUMENTS_URL) cls.web_app.update_response( "get", API_BASE_URL, cls.strip_host_from_okex_url(OKEX_PRICE_URL).format( trading_pair='ETH-USDT'), FixtureOKEx.INSTRUMENT_TICKER) cls.web_app.update_response( "get", API_BASE_URL, cls.strip_host_from_okex_url(OKEX_DEPTH_URL).format( trading_pair='ETH-USDT'), FixtureOKEx.OKEX_ORDER_BOOK) cls.web_app.update_response( "get", API_BASE_URL, cls.strip_host_from_okex_url(OKEX_TICKERS_URL), FixtureOKEx.OKEX_TICKERS) cls.web_app.update_response("get", API_BASE_URL, '/' + OKEX_BALANCE_URL, FixtureOKEx.OKEX_BALANCE_URL) cls.web_app.update_response("get", API_BASE_URL, '/' + OKEX_SERVER_TIME, FixtureOKEx.TIMESTAMP) # cls.web_app.update_response("POST", API_BASE_URL, '/' + OKEX_PLACE_ORDER, FixtureOKEx.ORDER_PLACE) # cls.web_app.update_response("get", OKEX_BASE_URL, f"/v1/account/accounts/{mock_account_id}/balance", # FixtureOKEx.GET_BALANCES) cls._t_nonce_patcher = unittest.mock.patch( "hummingbot.connector.exchange.okex.okex_exchange.get_tracking_nonce" ) cls._t_nonce_mock = cls._t_nonce_patcher.start() cls.clock: Clock = Clock(ClockMode.REALTIME) cls.market: OkexExchange = OkexExchange(API_KEY, API_SECRET, API_PASSPHRASE, trading_pairs=["ETH-USDT"]) # Need 2nd instance of market to prevent events mixing up across tests cls.market_2: OkexExchange = OkexExchange(API_KEY, API_SECRET, API_PASSPHRASE, trading_pairs=["ETH-USDT"]) cls.clock.add_iterator(cls.market) cls.clock.add_iterator(cls.market_2) cls.stack = contextlib.ExitStack() cls._clock = cls.stack.enter_context(cls.clock) cls.ev_loop.run_until_complete(cls.wait_til_ready())
def setUpClass(cls): global MAINNET_RPC_URL cls.ev_loop = asyncio.get_event_loop() if API_MOCK_ENABLED: cls.web_app = MockWebServer.get_instance() cls.web_app.add_host_to_mock(cls.base_api_url, ["/api/v1/ping", "/api/v1/time", "/api/v1/ticker/24hr"]) cls.web_app.start() cls.ev_loop.run_until_complete(cls.web_app.wait_til_started()) cls._patcher = mock.patch("aiohttp.client.URL") cls._url_mock = cls._patcher.start() cls._url_mock.side_effect = cls.web_app.reroute_local cls._req_patcher = unittest.mock.patch.object(requests.Session, "request", autospec=True) cls._req_url_mock = cls._req_patcher.start() cls._req_url_mock.side_effect = MockWebServer.reroute_request cls.web_app.update_response("get", cls.base_api_url, "/api/v3/account", FixtureBinance.BALANCES) cls.web_app.update_response("get", cls.base_api_url, "/api/v1/exchangeInfo", FixtureBinance.MARKETS) cls.web_app.update_response("get", cls.base_api_url, "/wapi/v3/tradeFee.html", FixtureBinance.TRADE_FEES) cls.web_app.update_response("post", cls.base_api_url, "/api/v1/userDataStream", FixtureBinance.LISTEN_KEY) cls.web_app.update_response("put", cls.base_api_url, "/api/v1/userDataStream", FixtureBinance.LISTEN_KEY) cls.web_app.update_response("get", cls.base_api_url, "/api/v1/depth", FixtureBinance.LINKETH_SNAP, params={'symbol': 'LINKETH'}) cls.web_app.update_response("get", cls.base_api_url, "/api/v1/depth", FixtureBinance.ZRXETH_SNAP, params={'symbol': 'ZRXETH'}) cls.web_app.update_response("get", cls.base_api_url, "/api/v3/myTrades", {}, params={'symbol': 'ZRXETH'}) cls.web_app.update_response("get", cls.base_api_url, "/api/v3/myTrades", {}, params={'symbol': 'LINKETH'}) ws_base_url = "wss://stream.binance.com:9443/ws" cls._ws_user_url = f"{ws_base_url}/{FixtureBinance.LISTEN_KEY['listenKey']}" MockWebSocketServerFactory.start_new_server(cls._ws_user_url) MockWebSocketServerFactory.start_new_server(f"{ws_base_url}/linketh@depth/zrxeth@depth") cls._ws_patcher = unittest.mock.patch("websockets.connect", autospec=True) cls._ws_mock = cls._ws_patcher.start() cls._ws_mock.side_effect = MockWebSocketServerFactory.reroute_ws_connect cls._t_nonce_patcher = unittest.mock.patch( "hummingbot.connector.exchange.binance.binance_exchange.get_tracking_nonce") cls._t_nonce_mock = cls._t_nonce_patcher.start() cls.current_nonce = 1000000000000000 cls.clock: Clock = Clock(ClockMode.REALTIME) cls.market: BinanceExchange = BinanceExchange(API_KEY, API_SECRET, ["LINK-ETH", "ZRX-ETH"], True) print("Initializing Binance market... this will take about a minute.") cls.ev_loop: asyncio.BaseEventLoop = asyncio.get_event_loop() cls.clock.add_iterator(cls.market) cls.stack: contextlib.ExitStack = contextlib.ExitStack() cls._clock = cls.stack.enter_context(cls.clock) cls.ev_loop.run_until_complete(cls.wait_til_ready()) print("Ready.")
def setUpClass(cls): cls.ev_loop: asyncio.BaseEventLoop = asyncio.get_event_loop() if MOCK_API_ENABLED: cls.web_app = MockWebServer.get_instance() cls.web_app.add_host_to_mock(API_BASE_URL, []) cls.web_app.start() cls.ev_loop.run_until_complete(cls.web_app.wait_til_started()) cls._patcher = mock.patch("aiohttp.client.URL") cls._url_mock = cls._patcher.start() cls._url_mock.side_effect = cls.web_app.reroute_local cls.web_app.update_response( "get", API_BASE_URL, cls.strip_host_from_mexc_url(MEXC_SYMBOL_URL), FixtureMEXC.MEXC_MARKET_SYMBOL) cls.web_app.update_response("get", API_BASE_URL, MEXC_PRICE_URL.split("?")[:1][0], FixtureMEXC.MEXC_TICKERS, params={"symbol": "ETH-USDT"}) cls.web_app.update_response("get", API_BASE_URL, MEXC_DEPTH_URL.split("?")[:1][0], FixtureMEXC.MEXC_ORDER_BOOK, params={ "symbol": "ETH-USDT", "depth": 200 }) # cls.web_app.update_response("get", API_BASE_URL, MEXC_TICKERS_URL, FixtureMEXC.MEXC_TICKERS) cls.web_app.update_response("get", API_BASE_URL, MEXC_BALANCE_URL, FixtureMEXC.MEXC_BALANCE_URL) cls.web_app.update_response("get", API_BASE_URL, MEXC_DEAL_DETAIL, FixtureMEXC.ORDER_DEAL_DETAIL) cls.web_app.update_response("get", API_BASE_URL, MEXC_PING_URL, FixtureMEXC.PING_DATA) cls._t_nonce_patcher = unittest.mock.patch( "hummingbot.connector.exchange.mexc.mexc_exchange.get_tracking_nonce" ) cls._t_nonce_mock = cls._t_nonce_patcher.start() cls.clock: Clock = Clock(ClockMode.REALTIME) cls.market: MexcExchange = MexcExchange(API_KEY, API_SECRET, trading_pairs=["ETH-USDT"]) # Need 2nd instance of market to prevent events mixing up across tests cls.market_2: MexcExchange = MexcExchange(API_KEY, API_SECRET, trading_pairs=["ETH-USDT"]) # a = cls.market cls.clock.add_iterator(cls.market) cls.clock.add_iterator(cls.market_2) cls.stack = contextlib.ExitStack() cls._clock = cls.stack.enter_context(cls.clock) cls.ev_loop.run_until_complete(cls.wait_til_ready())
def setUpClass(cls) -> None: cls.ev_loop: asyncio.AbstractEventLoop = asyncio.get_event_loop() cls.web_app: MockWebServer = MockWebServer.get_instance() cls.host = "www.google.com" cls.web_app.add_host_to_mock(cls.host) cls.web_app.start() cls.ev_loop.run_until_complete(cls.web_app.wait_til_started()) cls._patcher = unittest.mock.patch("aiohttp.client.URL") cls._url_mock = cls._patcher.start() cls._url_mock.side_effect = MockWebServer.reroute_local cls._req_patcher = unittest.mock.patch.object(requests.Session, "request", autospec=True) cls._req_url_mock = cls._req_patcher.start() cls._req_url_mock.side_effect = MockWebServer.reroute_request
def setUpClass(cls): cls.ev_loop = asyncio.get_event_loop() trading_pair = "ETH-USDC" if API_MOCK_ENABLED: cls.web_app = MockWebServer.get_instance() cls.web_app.add_host_to_mock( API_BASE_URL, ["/time", "/products", f"/products/{trading_pair}/book"]) cls.web_app.start() cls.ev_loop.run_until_complete(cls.web_app.wait_til_started()) cls._patcher = mock.patch("aiohttp.client.URL") cls._url_mock = cls._patcher.start() cls._url_mock.side_effect = cls.web_app.reroute_local cls.web_app.update_response("get", API_BASE_URL, "/accounts", FixtureCoinbasePro.BALANCES) cls.web_app.update_response("get", API_BASE_URL, "/fees", FixtureCoinbasePro.TRADE_FEES) cls.web_app.update_response("get", API_BASE_URL, "/orders", FixtureCoinbasePro.ORDERS_STATUS) MockWebSocketServerFactory.start_new_server(WS_BASE_URL) cls._ws_patcher = unittest.mock.patch("websockets.connect", autospec=True) cls._ws_mock = cls._ws_patcher.start() cls._ws_mock.side_effect = MockWebSocketServerFactory.reroute_ws_connect cls._t_nonce_patcher = unittest.mock.patch( "hummingbot.connector.exchange.coinbase_pro.coinbase_pro_exchange.get_tracking_nonce" ) cls._t_nonce_mock = cls._t_nonce_patcher.start() cls.clock: Clock = Clock(ClockMode.REALTIME) cls.market: CoinbaseProExchange = CoinbaseProExchange( API_KEY, API_SECRET, API_PASSPHRASE, trading_pairs=[trading_pair]) print( "Initializing Coinbase Pro market... this will take about a minute." ) cls.clock.add_iterator(cls.market) cls.stack = contextlib.ExitStack() cls._clock = cls.stack.enter_context(cls.clock) cls.ev_loop.run_until_complete(cls.wait_til_ready()) print("Ready.")
def setUpClass(cls): global MAINNET_RPC_URL cls.ev_loop = asyncio.get_event_loop() if API_MOCK_ENABLED: cls.web_app = MockWebServer.get_instance() cls.web_app.add_host_to_mock(base_api_url) cls.web_app.start() cls.ev_loop.run_until_complete(cls.web_app.wait_til_started()) cls._patcher = mock.patch("aiohttp.client.URL") cls._url_mock = cls._patcher.start() cls._url_mock.side_effect = cls.web_app.reroute_local cls.web_app.update_response("get", base_api_url, "/api", {"status": "ok"}) cls.web_app.update_response("get", base_api_url, "/eth/uniswap/start", {"success": True}) cls.web_app.update_response("post", base_api_url, "/eth/balances", Fixture.BALANCES) cls.web_app.update_response("post", base_api_url, "/eth/allowances", Fixture.APPROVALS) cls._t_nonce_patcher = unittest.mock.patch( "hummingbot.connector.connector.uniswap.uniswap_connector.get_tracking_nonce" ) cls._t_nonce_mock = cls._t_nonce_patcher.start() cls.current_nonce = 1000000000000000 cls.clock: Clock = Clock(ClockMode.REALTIME) cls.connector = UniswapV3Connector(["ZRX-ETH"], WALLET_KEY, rpc_url, True) print( "Initializing Uniswap v3 connector... this will take a few seconds." ) # cls.ev_loop: asyncio.BaseEventLoop = asyncio.get_event_loop() cls.clock.add_iterator(cls.connector) cls.stack: contextlib.ExitStack = contextlib.ExitStack() cls._clock = cls.stack.enter_context(cls.clock) cls.ev_loop.run_until_complete(cls.wait_til_ready()) print("Ready.")
def setUpClass(cls): cls.ev_loop: asyncio.BaseEventLoop = asyncio.get_event_loop() if API_MOCK_ENABLED: cls.web_app = MockWebServer.get_instance() cls.web_app.add_host_to_mock(API_BASE_URL, [ "/api/v1/timestamp", "/api/v1/symbols", "/api/v1/bullet-public", "/api/v2/market/orderbook/level2" ]) cls.web_app.start() cls.ev_loop.run_until_complete(cls.web_app.wait_til_started()) cls._patcher = mock.patch("aiohttp.client.URL") cls._url_mock = cls._patcher.start() cls._url_mock.side_effect = cls.web_app.reroute_local cls.web_app.update_response("get", API_BASE_URL, "/api/v1/accounts", FixtureKucoin.BALANCES) cls._t_nonce_patcher = unittest.mock.patch( "hummingbot.connector.exchange.kucoin.kucoin_exchange.get_tracking_nonce" ) cls._t_nonce_mock = cls._t_nonce_patcher.start() cls._exch_order_id = 20001 cls.clock: Clock = Clock(ClockMode.REALTIME) cls.market: KucoinExchange = KucoinExchange( kucoin_api_key=API_KEY, kucoin_passphrase=API_PASSPHRASE, kucoin_secret_key=API_SECRET, trading_pairs=["ETH-USDT"]) # Need 2nd instance of market to prevent events mixing up across tests cls.market_2: KucoinExchange = KucoinExchange( kucoin_api_key=API_KEY, kucoin_passphrase=API_PASSPHRASE, kucoin_secret_key=API_SECRET, trading_pairs=["ETH-USDT"]) cls.clock.add_iterator(cls.market) cls.clock.add_iterator(cls.market_2) cls.stack = contextlib.ExitStack() cls._clock = cls.stack.enter_context(cls.clock) cls.ev_loop.run_until_complete(cls.wait_til_ready())
def setUpClass(cls): cls.ev_loop: asyncio.BaseEventLoop = asyncio.get_event_loop() if API_MOCK_ENABLED: cls.web_app = MockWebServer.get_instance() cls.web_app.add_host_to_mock(API_BASE_URL, [ "/v1/common/timestamp", "/v1/common/symbols", "/market/tickers", "/market/depth" ]) cls.web_app.start() cls.ev_loop.run_until_complete(cls.web_app.wait_til_started()) cls._patcher = mock.patch("aiohttp.client.URL") cls._url_mock = cls._patcher.start() cls._url_mock.side_effect = cls.web_app.reroute_local mock_account_id = FixtureHuobi.GET_ACCOUNTS["data"][0]["id"] cls.web_app.update_response("get", API_BASE_URL, "/v1/account/accounts", FixtureHuobi.GET_ACCOUNTS) cls.web_app.update_response( "get", API_BASE_URL, f"/v1/account/accounts/{mock_account_id}/balance", FixtureHuobi.BALANCES) cls._t_nonce_patcher = unittest.mock.patch( "hummingbot.connector.exchange.huobi.huobi_exchange.get_tracking_nonce" ) cls._t_nonce_mock = cls._t_nonce_patcher.start() cls.clock: Clock = Clock(ClockMode.REALTIME) cls.market: HuobiExchange = HuobiExchange(API_KEY, API_SECRET, trading_pairs=["ETH-USDT"]) # Need 2nd instance of market to prevent events mixing up across tests cls.market_2: HuobiExchange = HuobiExchange(API_KEY, API_SECRET, trading_pairs=["ETH-USDT"]) cls.clock.add_iterator(cls.market) cls.clock.add_iterator(cls.market_2) cls.stack = contextlib.ExitStack() cls._clock = cls.stack.enter_context(cls.clock) cls.ev_loop.run_until_complete(cls.wait_til_ready())
def setUpClass(cls): cls.ev_loop: asyncio.BaseEventLoop = asyncio.get_event_loop() if API_MOCK_ENABLED: cls.web_app = MockWebServer.get_instance() cls.web_app.add_host_to_mock(PRIVET_API_BASE_URL, []) cls.web_app.add_host_to_mock(PUBLIC_API_BASE_URL, []) cls.web_app.start() cls.ev_loop.run_until_complete(cls.web_app.wait_til_started()) cls._patcher = mock.patch("aiohttp.client.URL") cls._url_mock = cls._patcher.start() cls._url_mock.side_effect = cls.web_app.reroute_local cls.web_app.update_response("get", PUBLIC_API_BASE_URL, "/api/v2/symbols", FixtureBeaxy.SYMBOLS) cls.web_app.update_response("get", PUBLIC_API_BASE_URL, "/api/v2/symbols/DASHBTC/book", FixtureBeaxy.TRADE_BOOK) cls.web_app.update_response("get", PUBLIC_API_BASE_URL, "/api/v2/symbols/DASHBTC/rate", FixtureBeaxy.EXCHANGE_RATE) cls.web_app.update_response("get", PRIVET_API_BASE_URL, "/api/v2/health", FixtureBeaxy.HEALTH) cls.web_app.update_response("get", PRIVET_API_BASE_URL, "/api/v2/wallets", FixtureBeaxy.BALANCES) cls.web_app.update_response("get", PRIVET_API_BASE_URL, "/api/v2/tradingsettings", FixtureBeaxy.TRADE_SETTINGS) cls.web_app.update_response("get", PRIVET_API_BASE_URL, "/api/v2/orders/open", FixtureBeaxy.ORDERS_OPEN_EMPTY) cls.web_app.update_response("get", PRIVET_API_BASE_URL, "/api/v2/orders/closed", FixtureBeaxy.ORDERS_CLOSED_EMPTY) cls._t_nonce_patcher = unittest.mock.patch( "hummingbot.connector.exchange.beaxy.beaxy_exchange.get_tracking_nonce" ) cls._t_nonce_mock = cls._t_nonce_patcher.start() MockWebSocketServerFactory.url_host_only = True MockWebSocketServerFactory.start_new_server( BeaxyConstants.TradingApi.WS_BASE_URL) MockWebSocketServerFactory.start_new_server( BeaxyConstants.PublicApi.WS_BASE_URL) cls._ws_patcher = unittest.mock.patch("websockets.connect", autospec=True) cls._ws_mock = cls._ws_patcher.start() cls._ws_mock.side_effect = MockWebSocketServerFactory.reroute_ws_connect cls._auth_confirm_patcher = unittest.mock.patch( "hummingbot.connector.exchange.beaxy.beaxy_auth.BeaxyAuth._BeaxyAuth__login_confirm" ) cls._auth_confirm_mock = cls._auth_confirm_patcher.start() cls._auth_session_patcher = unittest.mock.patch( "hummingbot.connector.exchange.beaxy.beaxy_auth.BeaxyAuth._BeaxyAuth__get_session_data" ) cls._auth_session_mock = cls._auth_session_patcher.start() cls._auth_session_mock.return_value = { "sign_key": 123, "session_id": '123' } cls._auth_headers_patcher = unittest.mock.patch( "hummingbot.connector.exchange.beaxy.beaxy_auth.BeaxyAuth.get_token" ) cls._auth_headers_mock = cls._auth_headers_patcher.start() cls._auth_headers_mock.return_value = '123' cls._auth_poll_patcher = unittest.mock.patch( "hummingbot.connector.exchange.beaxy.beaxy_auth.BeaxyAuth._auth_token_polling_loop" ) cls._auth_poll_mock = cls._auth_poll_patcher.start() cls.clock: Clock = Clock(ClockMode.REALTIME) cls.market: BeaxyExchange = BeaxyExchange(API_KEY, API_SECRET, trading_pairs=["DASH-BTC"]) if API_MOCK_ENABLED: async def mock_status_polling_task(): pass # disable status polling as it will make orders update inconsistent from mock view cls.market._status_polling_task = asyncio.ensure_future( mock_status_polling_task()) cls.ev_loop.run_until_complete(cls.market._update_balances()) print("Initializing Beaxy market... this will take about a minute.") cls.clock.add_iterator(cls.market) cls.stack: contextlib.ExitStack = contextlib.ExitStack() cls._clock = cls.stack.enter_context(cls.clock) cls.ev_loop.run_until_complete(cls.wait_til_ready()) print("Ready.")
def setUpClass(cls): cls.ev_loop: asyncio.BaseEventLoop = asyncio.get_event_loop() if API_MOCK_ENABLED: cls.web_app = MockWebServer.get_instance() cls.web_app.add_host_to_mock(API_BASE_URL, []) cls.web_app.start() cls.ev_loop.run_until_complete(cls.web_app.wait_til_started()) cls._patcher = mock.patch("aiohttp.client.URL") cls._url_mock = cls._patcher.start() cls._url_mock.side_effect = cls.web_app.reroute_local cls.web_app.update_response("get", API_BASE_URL, "/v3/ping", FixtureBittrex.PING) cls.web_app.update_response("get", API_BASE_URL, "/v3/markets", FixtureBittrex.MARKETS) cls.web_app.update_response("get", API_BASE_URL, "/v3/markets/tickers", FixtureBittrex.MARKETS_TICKERS) cls.web_app.update_response("get", API_BASE_URL, "/v3/balances", FixtureBittrex.BALANCES) cls.web_app.update_response("get", API_BASE_URL, "/v3/orders/open", FixtureBittrex.ORDERS_OPEN) cls._t_nonce_patcher = unittest.mock.patch( "hummingbot.connector.exchange.bittrex.bittrex_exchange.get_tracking_nonce" ) cls._t_nonce_mock = cls._t_nonce_patcher.start() cls._us_patcher = unittest.mock.patch( "hummingbot.connector.exchange.bittrex.bittrex_api_user_stream_data_source." "BittrexAPIUserStreamDataSource._transform_raw_message", autospec=True) cls._us_mock = cls._us_patcher.start() cls._us_mock.side_effect = _transform_raw_message_patch cls._ob_patcher = unittest.mock.patch( "hummingbot.connector.exchange.bittrex.bittrex_api_order_book_data_source." "BittrexAPIOrderBookDataSource._transform_raw_message", autospec=True) cls._ob_mock = cls._ob_patcher.start() cls._ob_mock.side_effect = _transform_raw_message_patch MockWebSocketServerFactory.url_host_only = True ws_server = MockWebSocketServerFactory.start_new_server( WS_BASE_URL) cls._ws_patcher = unittest.mock.patch("websockets.connect", autospec=True) cls._ws_mock = cls._ws_patcher.start() cls._ws_mock.side_effect = MockWebSocketServerFactory.reroute_ws_connect ws_server.add_stock_response( "queryExchangeState", FixtureBittrex.WS_ORDER_BOOK_SNAPSHOT.copy()) cls.clock: Clock = Clock(ClockMode.REALTIME) cls.market: BittrexExchange = BittrexExchange( bittrex_api_key=API_KEY, bittrex_secret_key=API_SECRET, trading_pairs=["ETH-USDT"]) print("Initializing Bittrex market... this will take about a minute. ") cls.clock.add_iterator(cls.market) cls.stack = contextlib.ExitStack() cls._clock = cls.stack.enter_context(cls.clock) cls.ev_loop.run_until_complete(cls.wait_til_ready()) print("Ready.")
def setUpClass(cls): cls.ev_loop = asyncio.get_event_loop() BinanceAPIOrderBookDataSource._trading_pair_symbol_map = { "com": bidict({ "ETHBTC": "ETH-BTC", "LTCBTC": "LTC-BTC", "BTCUSDT": "BTC-USDT", "SCRTBTC": "SCRT-BTC" }), "us": bidict({ "BTCUSD": "BTC-USD", "ETHUSD": "ETH-USD" }) } cls.web_app = MockWebServer.get_instance() cls.web_app.add_host_to_mock(URL(RateOracle.binance_price_url).host) cls.web_app.add_host_to_mock(URL(RateOracle.binance_us_price_url).host) cls.web_app.add_host_to_mock( URL(RateOracle.coingecko_supported_vs_tokens_url).host) cls.web_app.add_host_to_mock(URL(RateOracle.kucoin_price_url).host) cls.web_app.add_host_to_mock(URL(RateOracle.ascend_ex_price_url).host) cls.web_app.start() cls.ev_loop.run_until_complete(cls.web_app.wait_til_started()) cls._patcher = mock.patch("aiohttp.client.URL") cls._url_mock = cls._patcher.start() cls._url_mock.side_effect = cls.web_app.reroute_local cls.web_app.update_response("get", URL(RateOracle.binance_price_url).host, URL(RateOracle.binance_price_url).path, Fixture.Binance) cls.web_app.update_response("get", URL(RateOracle.binance_us_price_url).host, URL(RateOracle.binance_us_price_url).path, Fixture.BinanceUS) cls.web_app.update_response( "get", URL(RateOracle.coingecko_supported_vs_tokens_url).host, URL(RateOracle.coingecko_supported_vs_tokens_url).path, Fixture.CoinGeckoVSCurrencies) cls.web_app.update_response("get", URL(RateOracle.kucoin_price_url).host, URL(RateOracle.kucoin_price_url).path, Fixture.Kucoin) cls.web_app.update_response("get", URL(RateOracle.ascend_ex_price_url).host, URL(RateOracle.ascend_ex_price_url).path, Fixture.AscendEx) cls.web_app.update_response( "get", URL(RateOracle.coingecko_usd_price_url).host, URL(RateOracle.coingecko_usd_price_url).path, Fixture.CoinGeckoPage1, params={"page": 1}) cls.web_app.update_response( "get", URL(RateOracle.coingecko_usd_price_url).host, URL(RateOracle.coingecko_usd_price_url).path, Fixture.CoinGeckoPage2, params={"page": 2}) cls.web_app.update_response( "get", URL(RateOracle.coingecko_usd_price_url).host, URL(RateOracle.coingecko_usd_price_url).path, Fixture.CoinGeckoPage3, params={"page": 3}) cls.web_app.update_response( "get", URL(RateOracle.coingecko_usd_price_url).host, URL(RateOracle.coingecko_usd_price_url).path, Fixture.CoinGeckoPage4, params={"page": 4})
def setUpClass(cls): cls.ev_loop = asyncio.get_event_loop() cls.web_app = MockWebServer.get_instance() cls.web_app.add_host_to_mock(URL(RateOracle.binance_price_url).host) cls.web_app.add_host_to_mock(URL(RateOracle.binance_us_price_url).host) cls.web_app.add_host_to_mock( URL(RateOracle.coingecko_supported_vs_tokens_url).host) cls.web_app.add_host_to_mock(URL(RateOracle.kucoin_price_url).host) cls.web_app.add_host_to_mock(URL(RateOracle.ascend_ex_price_url).host) cls.web_app.start() cls.ev_loop.run_until_complete(cls.web_app.wait_til_started()) cls._patcher = mock.patch("aiohttp.client.URL") cls._url_mock = cls._patcher.start() cls._url_mock.side_effect = cls.web_app.reroute_local cls.web_app.update_response("get", URL(RateOracle.binance_price_url).host, URL(RateOracle.binance_price_url).path, Fixture.Binance) cls.web_app.update_response("get", URL(RateOracle.binance_us_price_url).host, URL(RateOracle.binance_us_price_url).path, Fixture.BinanceUS) cls.web_app.update_response( "get", URL(RateOracle.coingecko_supported_vs_tokens_url).host, URL(RateOracle.coingecko_supported_vs_tokens_url).path, Fixture.CoinGeckoVSCurrencies) cls.web_app.update_response("get", URL(RateOracle.kucoin_price_url).host, URL(RateOracle.kucoin_price_url).path, Fixture.Kucoin) cls.web_app.update_response("get", URL(RateOracle.ascend_ex_price_url).host, URL(RateOracle.ascend_ex_price_url).path, Fixture.AscendEx) cls.web_app.update_response( "get", URL(RateOracle.coingecko_usd_price_url).host, URL(RateOracle.coingecko_usd_price_url).path, Fixture.CoinGeckoPage1, params={"page": 1}) cls.web_app.update_response( "get", URL(RateOracle.coingecko_usd_price_url).host, URL(RateOracle.coingecko_usd_price_url).path, Fixture.CoinGeckoPage2, params={"page": 2}) cls.web_app.update_response( "get", URL(RateOracle.coingecko_usd_price_url).host, URL(RateOracle.coingecko_usd_price_url).path, Fixture.CoinGeckoPage3, params={"page": 3}) cls.web_app.update_response( "get", URL(RateOracle.coingecko_usd_price_url).host, URL(RateOracle.coingecko_usd_price_url).path, Fixture.CoinGeckoPage4, params={"page": 4})
def setUpClass(cls): cls.clock: Clock = Clock(ClockMode.REALTIME) cls.ev_loop: asyncio.BaseEventLoop = asyncio.get_event_loop() if API_MOCK_ENABLED: cls.web_app = MockWebServer.get_instance() cls.web_app.add_host_to_mock(cls.base_api_url, []) cls.web_app.start() cls.ev_loop.run_until_complete(cls.web_app.wait_til_started()) cls._req_patcher = mock.patch.object(requests.Session, "request", autospec=True) cls._req_url_mock = cls._req_patcher.start() cls._req_url_mock.side_effect = MockWebServer.reroute_request cls.web_app.update_response("get", cls.base_api_url, f"/v1/accounts/{WALLET_ADDRESS}", FixtureDydx.BALANCES, params={'number': f'{ACCOUNT_NUMBER}'}) cls.web_app.update_response("get", cls.base_api_url, "/v2/markets", FixtureDydx.MARKETS) cls.web_app.update_response("get", cls.base_api_url, "/v1/orderbook/WETH-USDC", FixtureDydx.WETHUSDC_SNAP) cls._buy_order_exchange_id = "0xb0751a113c759779ff5fd6a53b37b26211a9\ f8845d443323b9f877f32d9aafd9" cls._sell_order_exchange_id = "0x03dfd18edc2f26fc9298edcd28ca6cad4971\ bd1f44d40253d5154b0d1f217680" cls.web_app.update_response( "delete", cls.base_api_url, f"/v2/orders/{cls._buy_order_exchange_id}", FixtureDydx.CANCEL_ORDER_BUY) cls.web_app.update_response( "delete", cls.base_api_url, f"/v2/orders/{cls._sell_order_exchange_id}", FixtureDydx.CANCEL_ORDER_SELL) ws_base_url = "wss://api.dydx.exchange/v1/ws" cls._ws_user_url = f"{ws_base_url}" MockWebSocketServerFactory.start_new_server(cls._ws_user_url) MockWebSocketServerFactory.start_new_server(f"{ws_base_url}") cls._ws_patcher = unittest.mock.patch("websockets.connect", autospec=True) cls._ws_mock = cls._ws_patcher.start() cls._ws_mock.side_effect = MockWebSocketServerFactory.reroute_ws_connect cls._t_nonce_patcher = unittest.mock.patch( "hummingbot.connector.exchange.dydx.\ dydx_exchange.get_tracking_nonce") cls._t_nonce_mock = cls._t_nonce_patcher.start() cls.market: DydxExchange = DydxExchange( dydx_eth_private_key=PRIVATE_KEY, dydx_node_address=NODE_ADDRESS, poll_interval=10.0, trading_pairs=['WETH-USDC'], trading_required=True) print("Initializing Dydx market... ") cls.clock.add_iterator(cls.market) cls.stack = contextlib.ExitStack() cls._clock = cls.stack.enter_context(cls.clock) cls.ev_loop.run_until_complete(cls.wait_til_ready()) print("Ready.")