def test_show_ticker(self, notify_mock): self.client_config_map.db_mode = DBSqliteMode() captures = [] notify_mock.side_effect = lambda s: captures.append(s) exchange_name = "paper" exchange = MockPaperExchange( client_config_map=ClientConfigAdapter(ClientConfigMap())) self.app.markets[exchange_name] = exchange trading_pair = "BTC-USDT" exchange.set_balanced_order_book( trading_pair, mid_price=10, min_price=8.5, max_price=11.5, price_step_size=1, volume_step_size=1, ) self.async_run_with_timeout( self.app.show_ticker(exchange=exchange_name, live=False)) self.assertEqual(1, len(captures)) df_str_expected = ( " Market: mock_paper_exchange" "\n+------------+------------+-------------+--------------+" "\n| Best Bid | Best Ask | Mid Price | Last Trade |" "\n|------------+------------+-------------+--------------|" "\n| 9.5 | 10.5 | 10 | nan |" "\n+------------+------------+-------------+--------------+") self.assertEqual(df_str_expected, captures[0])
def test_adjust_candidate_insufficient_funds_for_flat_fees_and_percent_fees_third_token( self): fc_token = "PFC" trade_fee_schema = TradeFeeSchema( percent_fee_token=fc_token, maker_percent_fee_decimal=Decimal("0.01"), taker_percent_fee_decimal=Decimal("0.01"), maker_fixed_fees=[TokenAmount(fc_token, Decimal("1"))]) exchange = MockPaperExchange(client_config_map=ClientConfigAdapter( ClientConfigMap()), trade_fee_schema=trade_fee_schema) pfc_quote_pair = combine_to_hb_trading_pair(self.quote_asset, fc_token) exchange.set_balanced_order_book( # the quote to pfc price will be 1:2 trading_pair=pfc_quote_pair, mid_price=1.5, min_price=1, max_price=2, price_step_size=1, volume_step_size=1, ) budget_checker: BudgetChecker = exchange.budget_checker exchange.set_balance(self.quote_asset, Decimal("20")) exchange.set_balance( fc_token, Decimal("1.2") ) # 0.2 less than required; will result in 50% order reduction order_candidate = OrderCandidate( trading_pair=self.trading_pair, is_maker=True, order_type=OrderType.LIMIT, order_side=TradeType.BUY, amount=Decimal("10"), price=Decimal("2"), ) adjusted_candidate = budget_checker.adjust_candidate(order_candidate, all_or_none=False) self.assertEqual(Decimal("5"), adjusted_candidate.amount) self.assertEqual(self.quote_asset, adjusted_candidate.order_collateral.token) self.assertEqual(Decimal("10"), adjusted_candidate.order_collateral.amount) self.assertEqual(fc_token, adjusted_candidate.percent_fee_collateral.token) self.assertEqual(Decimal("0.2"), adjusted_candidate.percent_fee_collateral.amount) self.assertEqual(fc_token, adjusted_candidate.percent_fee_value.token) self.assertEqual(Decimal("0.2"), adjusted_candidate.percent_fee_value.amount) self.assertEqual(1, len(adjusted_candidate.fixed_fee_collaterals)) fixed_fee_collateral = adjusted_candidate.fixed_fee_collaterals[0] self.assertEqual(fc_token, fixed_fee_collateral.token) self.assertEqual(Decimal("1"), fixed_fee_collateral.amount) self.assertEqual(self.base_asset, adjusted_candidate.potential_returns.token) self.assertEqual(Decimal("5"), adjusted_candidate.potential_returns.amount)
def test_populate_collateral_fields_percent_fees_in_third_token(self): pfc_token = "PFC" trade_fee_schema = TradeFeeSchema( percent_fee_token=pfc_token, maker_percent_fee_decimal=Decimal("0.01"), taker_percent_fee_decimal=Decimal("0.01"), ) exchange = MockPaperExchange(client_config_map=ClientConfigAdapter( ClientConfigMap()), trade_fee_schema=trade_fee_schema) pfc_quote_pair = combine_to_hb_trading_pair(self.quote_asset, pfc_token) exchange.set_balanced_order_book( # the quote to pfc price will be 1:2 trading_pair=pfc_quote_pair, mid_price=1.5, min_price=1, max_price=2, price_step_size=1, volume_step_size=1, ) budget_checker: BudgetChecker = exchange.budget_checker order_candidate = OrderCandidate( trading_pair=self.trading_pair, is_maker=True, order_type=OrderType.LIMIT, order_side=TradeType.BUY, amount=Decimal("10"), price=Decimal("2"), ) populated_candidate = budget_checker.populate_collateral_entries( order_candidate) self.assertEqual(self.quote_asset, populated_candidate.order_collateral.token) self.assertEqual(Decimal("20"), populated_candidate.order_collateral.amount) self.assertEqual(pfc_token, populated_candidate.percent_fee_collateral.token) self.assertEqual(Decimal("0.4"), populated_candidate.percent_fee_collateral.amount) self.assertEqual(pfc_token, populated_candidate.percent_fee_value.token) self.assertEqual(Decimal("0.4"), populated_candidate.percent_fee_value.amount) self.assertEqual(0, len(populated_candidate.fixed_fee_collaterals)) self.assertEqual(self.base_asset, populated_candidate.potential_returns.token) self.assertEqual(Decimal("10"), populated_candidate.potential_returns.amount)