Skip to content

Commit

Permalink
(feat) update oracle settings on trading pair configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nullably committed Apr 1, 2021
1 parent 1f586ef commit a87eaa0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 35 deletions.
2 changes: 2 additions & 0 deletions hummingbot/client/command/create_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ async def prompt_a_config(self, # type: HummingbotApplication

if self.app.to_stop_config:
return
config.value = parse_cvar_value(config, input_value)
err_msg = await config.validate(input_value)
if err_msg is not None:
self._notify(err_msg)
config.value = None
await self.prompt_a_config(config)
else:
config.value = parse_cvar_value(config, input_value)
Expand Down
60 changes: 38 additions & 22 deletions hummingbot/strategy/arbitrage/arbitrage_config_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ def secondary_market_on_validated(value: str):
settings.required_exchanges.append(value)


def use_oracle_conversion_rate_on_validated(value: str):
use_oracle = parse_cvar_value(arbitrage_config_map["use_oracle_conversion_rate"], value)
first_base, first_quote = arbitrage_config_map["primary_market_trading_pair"].value.split("-")
second_base, second_quote = arbitrage_config_map["secondary_market_trading_pair"].value.split("-")
def update_oracle_settings(value: str):
c_map = arbitrage_config_map
if not (c_map["use_oracle_conversion_rate"].value is not None and
c_map["primary_market_trading_pair"].value is not None and
c_map["secondary_market_trading_pair"].value is not None):
return
use_oracle = parse_cvar_value(c_map["use_oracle_conversion_rate"], c_map["use_oracle_conversion_rate"].value)
first_base, first_quote = c_map["primary_market_trading_pair"].value.split("-")
second_base, second_quote = c_map["secondary_market_trading_pair"].value.split("-")
if use_oracle and (first_base != second_base or first_quote != second_quote):
settings.required_rate_oracle = True
settings.rate_oracle_pairs = []
Expand All @@ -56,60 +61,71 @@ def use_oracle_conversion_rate_on_validated(value: str):


arbitrage_config_map = {
"strategy":
ConfigVar(key="strategy",
prompt="",
default="arbitrage"),
"strategy": ConfigVar(
key="strategy",
prompt="",
default="arbitrage"
),
"primary_market": ConfigVar(
key="primary_market",
prompt="Enter your primary spot connector >>> ",
prompt_on_new=True,
validator=validate_exchange,
on_validated=lambda value: settings.required_exchanges.append(value)),
on_validated=lambda value: settings.required_exchanges.append(value),
),
"secondary_market": ConfigVar(
key="secondary_market",
prompt="Enter your secondary spot connector >>> ",
prompt_on_new=True,
validator=validate_exchange,
on_validated=secondary_market_on_validated),
on_validated=secondary_market_on_validated,
),
"primary_market_trading_pair": ConfigVar(
key="primary_market_trading_pair",
prompt=primary_trading_pair_prompt,
prompt_on_new=True,
validator=validate_primary_market_trading_pair),
validator=validate_primary_market_trading_pair,
on_validated=update_oracle_settings,
),
"secondary_market_trading_pair": ConfigVar(
key="secondary_market_trading_pair",
prompt=secondary_trading_pair_prompt,
prompt_on_new=True,
validator=validate_secondary_market_trading_pair),
validator=validate_secondary_market_trading_pair,
on_validated=update_oracle_settings,
),
"min_profitability": ConfigVar(
key="min_profitability",
prompt="What is the minimum profitability for you to make a trade? (Enter 1 to indicate 1%) >>> ",
prompt_on_new=True,
default=Decimal("0.3"),
validator=lambda v: validate_decimal(v, Decimal(-100), Decimal("100"), inclusive=True),
type_str="decimal"),
type_str="decimal",
),
"use_oracle_conversion_rate": ConfigVar(
key="use_oracle_conversion_rate",
type_str="bool",
prompt="Do you want to use rate oracle on unmatched trading pairs? (Yes/No) >>> ",
prompt_on_new=True,
validator=lambda v: validate_bool(v),
on_validated=use_oracle_conversion_rate_on_validated),
on_validated=update_oracle_settings,
),
"secondary_to_primary_base_conversion_rate": ConfigVar(
key="secondary_to_primary_base_conversion_rate",
prompt="Enter conversion rate for secondary base asset value to primary base asset value, e.g. "
"if primary base asset is USD, secondary is DAI and 1 USD is worth 1.25 DAI, "
"the conversion rate is 0.8 (1 / 1.25) >>> ",
"if primary base asset is USD and the secondary is DAI, 1 DAI is valued at 1.25 USD, "
"the conversion rate is 1.25 >>> ",
default=Decimal("1"),
validator=lambda v: validate_decimal(v, Decimal(0), Decimal("100"), inclusive=False),
type_str="decimal"),
validator=lambda v: validate_decimal(v, Decimal(0), inclusive=False),
type_str="decimal",
),
"secondary_to_primary_quote_conversion_rate": ConfigVar(
key="secondary_to_primary_quote_conversion_rate",
prompt="Enter conversion rate for secondary quote asset value to primary quote asset value, e.g. "
"if primary quote asset is USD, secondary is DAI and 1 USD is worth 1.25 DAI, "
"the conversion rate is 0.8 (1 / 1.25) >>> ",
"if primary quote asset is USD and the secondary is DAI and 1 DAI is valued at 1.25 USD, "
"the conversion rate is 1.25 >>> ",
default=Decimal("1"),
validator=lambda v: validate_decimal(v, Decimal(0), Decimal("100"), inclusive=False),
type_str="decimal"),
validator=lambda v: validate_decimal(v, Decimal(0), inclusive=False),
type_str="decimal",
),
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,15 @@ def taker_market_on_validated(value: str):
settings.required_exchanges.append(value)


def use_oracle_conversion_rate_on_validated(value: str):
use_oracle = parse_cvar_value(cross_exchange_market_making_config_map["use_oracle_conversion_rate"], value)
first_base, first_quote = cross_exchange_market_making_config_map["maker_market_trading_pair"].value.split("-")
second_base, second_quote = cross_exchange_market_making_config_map["taker_market_trading_pair"].value.split("-")
def update_oracle_settings(value: str):
c_map = cross_exchange_market_making_config_map
if not (c_map["use_oracle_conversion_rate"].value is not None and
c_map["maker_market_trading_pair"].value is not None and
c_map["taker_market_trading_pair"].value is not None):
return
use_oracle = parse_cvar_value(c_map["use_oracle_conversion_rate"], c_map["use_oracle_conversion_rate"].value)
first_base, first_quote = c_map["maker_market_trading_pair"].value.split("-")
second_base, second_quote = c_map["taker_market_trading_pair"].value.split("-")
if use_oracle and (first_base != second_base or first_quote != second_quote):
settings.required_rate_oracle = True
settings.rate_oracle_pairs = []
Expand Down Expand Up @@ -111,13 +116,15 @@ def use_oracle_conversion_rate_on_validated(value: str):
key="maker_market_trading_pair",
prompt=maker_trading_pair_prompt,
prompt_on_new=True,
validator=validate_maker_market_trading_pair
validator=validate_maker_market_trading_pair,
on_validated=update_oracle_settings
),
"taker_market_trading_pair": ConfigVar(
key="taker_market_trading_pair",
prompt=taker_trading_pair_prompt,
prompt_on_new=True,
validator=validate_taker_market_trading_pair
validator=validate_taker_market_trading_pair,
on_validated=update_oracle_settings
),
"min_profitability": ConfigVar(
key="min_profitability",
Expand Down Expand Up @@ -216,23 +223,23 @@ def use_oracle_conversion_rate_on_validated(value: str):
prompt="Do you want to use rate oracle on unmatched trading pairs? (Yes/No) >>> ",
prompt_on_new=True,
validator=lambda v: validate_bool(v),
on_validated=use_oracle_conversion_rate_on_validated),
on_validated=update_oracle_settings),
"taker_to_maker_base_conversion_rate": ConfigVar(
key="taker_to_maker_base_conversion_rate",
prompt="Enter conversion rate for taker base asset value to maker base asset value, e.g. "
"if maker base asset is USD, taker is DAI and 1 USD is worth 1.25 DAI, "
"the conversion rate is 0.8 (1 / 1.25) >>> ",
"if maker base asset is USD and the taker is DAI, 1 DAI is valued at 1.25 USD, "
"the conversion rate is 1.25 >>> ",
default=Decimal("1"),
validator=lambda v: validate_decimal(v, Decimal(0), Decimal("100"), inclusive=False),
validator=lambda v: validate_decimal(v, Decimal(0), inclusive=False),
type_str="decimal"
),
"taker_to_maker_quote_conversion_rate": ConfigVar(
key="taker_to_maker_quote_conversion_rate",
prompt="Enter conversion rate for taker quote asset value to maker quote asset value, e.g. "
"if taker quote asset is USD, maker is DAI and 1 USD is worth 1.25 DAI, "
"the conversion rate is 0.8 (1 / 1.25) >>> ",
"if maker quote asset is USD and the taker is DAI, 1 DAI is valued at 1.25 USD, "
"the conversion rate is 1.25 >>> ",
default=Decimal("1"),
validator=lambda v: validate_decimal(v, Decimal(0), Decimal("100"), inclusive=False),
validator=lambda v: validate_decimal(v, Decimal(0), inclusive=False),
type_str="decimal"
),
}

0 comments on commit a87eaa0

Please sign in to comment.