Skip to content

Commit

Permalink
Merge pull request hummingbot#3145 from TheHolyRoger/fix/rate_oracle_…
Browse files Browse the repository at this point in the history
…on_xemm

Fix / Rate oracle conversions on XEMM strategy
  • Loading branch information
Nullably authored Apr 2, 2021
2 parents 03dc1c5 + 3202168 commit 4090b76
Showing 1 changed file with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1135,13 +1135,16 @@ cdef class CrossExchangeMarketMakingStrategy(StrategyBase):
object order_price = active_order.price
ExchangeBase maker_market = market_pair.maker.market
ExchangeBase taker_market = market_pair.taker.market

object quote_asset_amount = maker_market.c_get_balance(market_pair.maker.quote_asset) if is_buy else \
taker_market.c_get_balance(market_pair.taker.quote_asset)
object base_asset_amount = taker_market.c_get_balance(market_pair.taker.base_asset) if is_buy else \
maker_market.c_get_balance(market_pair.maker.base_asset)
object order_size_limit

quote_pair, quote_rate_source, quote_rate, base_pair, base_rate_source, base_rate = \
self.get_taker_to_maker_conversion_rate()

quote_asset_amount = maker_market.c_get_balance(market_pair.maker.quote_asset) if is_buy else \
taker_market.c_get_balance(market_pair.taker.quote_asset) * quote_rate
base_asset_amount = taker_market.c_get_balance(market_pair.taker.base_asset) * base_rate if is_buy else \
maker_market.c_get_balance(market_pair.maker.base_asset)

order_size_limit = min(base_asset_amount, quote_asset_amount / order_price)
quantized_size_limit = maker_market.c_quantize_order_amount(active_order.trading_pair, order_size_limit)

Expand All @@ -1161,11 +1164,8 @@ cdef class CrossExchangeMarketMakingStrategy(StrategyBase):
"""
Return price conversion rate for a taker market (to convert it into maker base asset value)
"""
if not self._use_oracle_conversion_rate:
return self._taker_to_maker_quote_conversion_rate / self._taker_to_maker_base_conversion_rate
else:
_, _, quote_rate, _, _, base_rate = self.get_taker_to_maker_conversion_rate()
return quote_rate / base_rate
_, _, quote_rate, _, _, base_rate = self.get_taker_to_maker_conversion_rate()
return quote_rate / base_rate
# else:
# market_pairs = list(self._market_pairs.values())[0]
# quote_pair = f"{market_pairs.taker.quote_asset}-{market_pairs.maker.quote_asset}"
Expand Down Expand Up @@ -1202,15 +1202,15 @@ cdef class CrossExchangeMarketMakingStrategy(StrategyBase):
True,
bid_size
)
effective_hedging_price_adjusted = effective_hedging_price * self.market_conversion_rate()
effective_hedging_price_adjusted = effective_hedging_price / self.market_conversion_rate()
if self._logging_options & self.OPTION_LOG_CREATE_ORDER:
self.log_with_clock(
logging.INFO,
f"({market_pair.maker.trading_pair}) Creating limit bid order for "
f"{bid_size} {market_pair.maker.base_asset} at "
f"{bid_price} {market_pair.maker.quote_asset}. "
f"Current hedging price: {effective_hedging_price} {market_pair.taker.quote_asset} "
f"(Rate adjusted: {effective_hedging_price_adjusted:.2f} {market_pair.taker.quote_asset})."
f"Current hedging price: {effective_hedging_price:.8f} {market_pair.maker.quote_asset} "
f"(Rate adjusted: {effective_hedging_price_adjusted:.8f} {market_pair.taker.quote_asset})."
)
order_id = self.c_place_order(market_pair, True, True, bid_size, bid_price)
else:
Expand Down Expand Up @@ -1241,15 +1241,15 @@ cdef class CrossExchangeMarketMakingStrategy(StrategyBase):
False,
ask_size
)
effective_hedging_price_adjusted = effective_hedging_price
effective_hedging_price_adjusted = effective_hedging_price / self.market_conversion_rate()
if self._logging_options & self.OPTION_LOG_CREATE_ORDER:
self.log_with_clock(
logging.INFO,
f"({market_pair.maker.trading_pair}) Creating limit ask order for "
f"{ask_size} {market_pair.maker.base_asset} at "
f"{ask_price} {market_pair.maker.quote_asset}. "
f"Current hedging price: {effective_hedging_price} {market_pair.maker.quote_asset} "
f"(Rate adjusted: {effective_hedging_price_adjusted:.2f} {market_pair.maker.quote_asset})."
f"Current hedging price: {effective_hedging_price:.8f} {market_pair.maker.quote_asset} "
f"(Rate adjusted: {effective_hedging_price_adjusted:.8f} {market_pair.taker.quote_asset})."
)
order_id = self.c_place_order(market_pair, False, True, ask_size, ask_price)
else:
Expand Down

0 comments on commit 4090b76

Please sign in to comment.