def test_added_to_cost_perpetual_fee_created_when_opening_positions(self): schema = TradeFeeSchema( maker_percent_fee_decimal=Decimal("1"), taker_percent_fee_decimal=Decimal("1"), buy_percent_fee_deducted_from_returns=False, ) fee = TradeFeeBase.new_perpetual_fee( fee_schema=schema, position_action=PositionAction.OPEN, percent=Decimal("1.1"), percent_token="HBOT", flat_fees=[TokenAmount(token="COINALPHA", amount=Decimal("20"))]) self.assertEqual(AddedToCostTradeFee, type(fee)) self.assertEqual(Decimal("1.1"), fee.percent) self.assertEqual("HBOT", fee.percent_token) self.assertEqual( [TokenAmount(token="COINALPHA", amount=Decimal("20"))], fee.flat_fees) schema.percent_fee_token = "HBOT" fee = TradeFeeBase.new_perpetual_fee( fee_schema=schema, position_action=PositionAction.OPEN, percent=Decimal("1.1"), percent_token="HBOT", flat_fees=[TokenAmount(token="COINALPHA", amount=Decimal("20"))]) self.assertEqual(AddedToCostTradeFee, type(fee))
def test_deducted_from_return_spot_fee_created_for_sell(self): schema = TradeFeeSchema( percent_fee_token="HBOT", maker_percent_fee_decimal=Decimal("1"), taker_percent_fee_decimal=Decimal("1"), buy_percent_fee_deducted_from_returns=False, ) fee = TradeFeeBase.new_spot_fee( fee_schema=schema, trade_type=TradeType.SELL, percent=Decimal("1.1"), percent_token="HBOT", flat_fees=[TokenAmount(token="COINALPHA", amount=Decimal("20"))]) self.assertEqual(DeductedFromReturnsTradeFee, type(fee)) self.assertEqual(Decimal("1.1"), fee.percent) self.assertEqual("HBOT", fee.percent_token) self.assertEqual( [TokenAmount(token="COINALPHA", amount=Decimal("20"))], fee.flat_fees) schema.percent_fee_token = None schema.buy_percent_fee_deducted_from_returns = True fee = TradeFeeBase.new_spot_fee( fee_schema=schema, trade_type=TradeType.SELL, percent=Decimal("1.1"), percent_token="HBOT", flat_fees=[TokenAmount(token="COINALPHA", amount=Decimal("20"))]) self.assertEqual(DeductedFromReturnsTradeFee, type(fee))
def _superimpose_overrides(cls, exchange: str, trade_fee_schema: TradeFeeSchema): trade_fee_schema.percent_fee_token = ( fee_overrides_config_map.get(f"{exchange}_percent_fee_token").value or trade_fee_schema.percent_fee_token) trade_fee_schema.maker_percent_fee_decimal = ( fee_overrides_config_map.get(f"{exchange}_maker_percent_fee").value / Decimal("100") if fee_overrides_config_map.get(f"{exchange}_maker_percent_fee").value is not None else trade_fee_schema.maker_percent_fee_decimal) trade_fee_schema.taker_percent_fee_decimal = ( fee_overrides_config_map.get(f"{exchange}_taker_percent_fee").value / Decimal("100") if fee_overrides_config_map.get(f"{exchange}_taker_percent_fee").value is not None else trade_fee_schema.taker_percent_fee_decimal) trade_fee_schema.buy_percent_fee_deducted_from_returns = ( fee_overrides_config_map.get( f"{exchange}_buy_percent_fee_deducted_from_returns").value if fee_overrides_config_map.get( f"{exchange}_buy_percent_fee_deducted_from_returns").value is not None else trade_fee_schema.buy_percent_fee_deducted_from_returns) trade_fee_schema.maker_fixed_fees = ( fee_overrides_config_map.get(f"{exchange}_maker_fixed_fees").value or trade_fee_schema.maker_fixed_fees) trade_fee_schema.maker_fixed_fees = [ TokenAmount(*maker_fixed_fee) for maker_fixed_fee in trade_fee_schema.maker_fixed_fees ] trade_fee_schema.taker_fixed_fees = ( fee_overrides_config_map.get(f"{exchange}_taker_fixed_fees").value or trade_fee_schema.taker_fixed_fees) trade_fee_schema.taker_fixed_fees = [ TokenAmount(*taker_fixed_fee) for taker_fixed_fee in trade_fee_schema.taker_fixed_fees ] trade_fee_schema.validate_schema() return trade_fee_schema