diff --git a/dexbot/__init__.py b/dexbot/__init__.py
index bddc4043d..5b90af327 100644
--- a/dexbot/__init__.py
+++ b/dexbot/__init__.py
@@ -1,4 +1,4 @@
APP_NAME = 'dexbot'
-VERSION = '0.4.5'
+VERSION = '0.4.6'
AUTHOR = 'Codaone Oy'
__version__ = VERSION
diff --git a/dexbot/basestrategy.py b/dexbot/basestrategy.py
index fbaa8bdd5..465f1ccdf 100644
--- a/dexbot/basestrategy.py
+++ b/dexbot/basestrategy.py
@@ -186,7 +186,7 @@ def __init__(
logging.getLogger('dexbot.orders_log'), {}
)
- def calculate_center_price(self, suppress_errors=False):
+ def _calculate_center_price(self, suppress_errors=False):
ticker = self.market.ticker()
highest_bid = ticker.get("highestBid")
lowest_ask = ticker.get("lowestAsk")
@@ -208,43 +208,47 @@ def calculate_center_price(self, suppress_errors=False):
center_price = highest_bid['price'] * math.sqrt(lowest_ask['price'] / highest_bid['price'])
return center_price
- def calculate_offset_center_price(self, spread, center_price=None, order_ids=None, manual_offset=0):
+ def calculate_center_price(self, center_price=None,
+ asset_offset=False, spread=None, order_ids=None, manual_offset=0):
""" Calculate center price which shifts based on available funds
"""
if center_price is None:
# No center price was given so we simply calculate the center price
- calculated_center_price = self.calculate_center_price()
- center_price = calculated_center_price
+ calculated_center_price = self._calculate_center_price()
else:
# Center price was given so we only use the calculated center price
# for quote to base asset conversion
- calculated_center_price = self.calculate_center_price(True)
+ calculated_center_price = self._calculate_center_price(True)
if not calculated_center_price:
calculated_center_price = center_price
- total_balance = self.total_balance(order_ids)
- total = (total_balance['quote'] * calculated_center_price) + total_balance['base']
+ if center_price:
+ calculated_center_price = center_price
- if not total: # Prevent division by zero
- balance = 0
- else:
- # Returns a value between -1 and 1
- balance = (total_balance['base'] / total) * 2 - 1
-
- if balance < 0:
- # With less of base asset center price should be offset downward
- offset_center_price = calculated_center_price / math.sqrt(1 + spread * (balance * -1))
- elif balance > 0:
- # With more of base asset center price will be offset upwards
- offset_center_price = calculated_center_price * math.sqrt(1 + spread * balance)
- else:
- offset_center_price = calculated_center_price
+ if asset_offset:
+ total_balance = self.total_balance(order_ids)
+ total = (total_balance['quote'] * calculated_center_price) + total_balance['base']
+
+ if not total: # Prevent division by zero
+ balance = 0
+ else:
+ # Returns a value between -1 and 1
+ balance = (total_balance['base'] / total) * 2 - 1
+
+ if balance < 0:
+ # With less of base asset center price should be offset downward
+ calculated_center_price = calculated_center_price / math.sqrt(1 + spread * (balance * -1))
+ elif balance > 0:
+ # With more of base asset center price will be offset upwards
+ calculated_center_price = calculated_center_price * math.sqrt(1 + spread * balance)
+ else:
+ calculated_center_price = calculated_center_price
# Calculate final_offset_price if manual center price offset is given
if manual_offset:
- offset_center_price = center_price + (center_price * manual_offset)
+ calculated_center_price = calculated_center_price + (calculated_center_price * manual_offset)
- return offset_center_price
+ return calculated_center_price
@property
def orders(self):
diff --git a/dexbot/controllers/strategy_controller.py b/dexbot/controllers/strategy_controller.py
index 7b738f846..1e151e7e5 100644
--- a/dexbot/controllers/strategy_controller.py
+++ b/dexbot/controllers/strategy_controller.py
@@ -115,6 +115,14 @@ def set_config_values(self, worker_data):
widget.lower_bound_input.setValue(worker_data.get('lower_bound', 0.000001))
widget.upper_bound_input.setValue(worker_data.get('upper_bound', 1000000))
+ self.view.strategy_widget.center_price_input.setValue(worker_data.get('center_price', 0))
+
+ if worker_data.get('center_price_dynamic', True):
+ self.view.strategy_widget.center_price_dynamic_checkbox.setChecked(True)
+ else:
+ self.view.strategy_widget.center_price_dynamic_checkbox.setChecked(False)
+ self.view.strategy_widget.center_price_input.setDisabled(False)
+
@gui_error
def on_value_change(self):
base_asset = self.worker_controller.view.base_asset_input.currentText()
@@ -173,6 +181,8 @@ def values(self):
data = {
'amount': self.view.strategy_widget.amount_input.value(),
'spread': self.view.strategy_widget.spread_input.value(),
+ 'center_price': self.view.strategy_widget.center_price_input.value(),
+ 'center_price_dynamic': self.view.strategy_widget.center_price_dynamic_checkbox.isChecked(),
'increment': self.view.strategy_widget.increment_input.value(),
'lower_bound': self.view.strategy_widget.lower_bound_input.value(),
'upper_bound': self.view.strategy_widget.upper_bound_input.value()
diff --git a/dexbot/strategies/relative_orders.py b/dexbot/strategies/relative_orders.py
index c57850e8d..d5eb07a91 100644
--- a/dexbot/strategies/relative_orders.py
+++ b/dexbot/strategies/relative_orders.py
@@ -46,7 +46,8 @@ def __init__(self, *args, **kwargs):
self.center_price = self.worker["center_price"]
self.is_relative_order_size = self.worker['amount_relative']
- self.is_center_price_offset = self.worker.get('center_price_offset', False)
+ self.is_asset_offset = self.worker.get('center_price_offset', False)
+ self.manual_offset = self.worker.get('manual_offset', 0) / 100
self.order_size = float(self.worker['amount'])
self.spread = self.worker.get('spread') / 100
@@ -85,15 +86,21 @@ def amount_base(self):
def calculate_order_prices(self):
if self.is_center_price_dynamic:
- if self.is_center_price_offset:
- self.center_price = self.calculate_offset_center_price(
- self.spread, order_ids=self['order_ids'])
- else:
- self.center_price = self.calculate_center_price()
+ self.center_price = self.calculate_center_price(
+ None,
+ self.is_asset_offset,
+ self.spread,
+ self['order_ids'],
+ self.manual_offset
+ )
else:
- if self.is_center_price_offset:
- self.center_price = self.calculate_offset_center_price(
- self.spread, self.center_price, self['order_ids'])
+ self.center_price = self.calculate_center_price(
+ self.center_price,
+ self.is_asset_offset,
+ self.spread,
+ self['order_ids'],
+ self.manual_offset
+ )
self.buy_price = self.center_price / math.sqrt(1 + self.spread)
self.sell_price = self.center_price * math.sqrt(1 + self.spread)
diff --git a/dexbot/strategies/staggered_orders.py b/dexbot/strategies/staggered_orders.py
index a778aab2b..9508b9cc2 100644
--- a/dexbot/strategies/staggered_orders.py
+++ b/dexbot/strategies/staggered_orders.py
@@ -16,6 +16,12 @@ def configure(cls):
ConfigElement(
'amount', 'float', 1.0,
'The amount of buy/sell orders', (0.0, None)),
+ ConfigElement(
+ 'center_price_dynamic', 'bool', True,
+ 'Dynamic centre price', None),
+ ConfigElement(
+ 'center_price', 'float', 0.0,
+ 'Initial center price', (0, 0, None)),
ConfigElement(
'spread', 'float', 6.0,
'The percentage difference between buy and sell (Spread)', (0.0, None)),
@@ -73,7 +79,12 @@ def init_strategy(self):
self.cancel_all()
self.clear_orders()
- center_price = self.calculate_center_price()
+ # Dynamic / Manual center price
+ if self.worker.get('center_price_dynamic', True):
+ center_price = self.calculate_center_price()
+ else:
+ center_price = self.worker.get('center_price')
+
amount = self.amount
spread = self.spread
increment = self.increment
diff --git a/dexbot/views/ui/forms/relative_orders_widget.ui b/dexbot/views/ui/forms/relative_orders_widget.ui
index 079d4fc73..9d8f6d94c 100644
--- a/dexbot/views/ui/forms/relative_orders_widget.ui
+++ b/dexbot/views/ui/forms/relative_orders_widget.ui
@@ -158,7 +158,7 @@
8
- -999999999.998999953269958
+ 0.000000000000000
999999999.998999953269958
diff --git a/dexbot/views/ui/forms/staggered_orders_widget.ui b/dexbot/views/ui/forms/staggered_orders_widget.ui
index b2e7cb3b3..2eda84934 100644
--- a/dexbot/views/ui/forms/staggered_orders_widget.ui
+++ b/dexbot/views/ui/forms/staggered_orders_widget.ui
@@ -32,6 +32,65 @@
Worker Parameters
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 110
+ 0
+
+
+
+
+ 110
+ 16777215
+
+
+
+ Amount
+
+
+ spread_input
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 151
+ 0
+
+
+
+
+
+
+
+
+
+ 8
+
+
+ 100000.000000000000000
+
+
+ 0.000000000000000
+
+
+
-
@@ -200,7 +259,7 @@
- -
+
-
@@ -228,7 +287,7 @@
- -
+
-
@@ -256,62 +315,78 @@
- -
-
+
-
+
-
+
0
0
- 151
+ 110
0
-
-
-
-
-
-
-
- 8
+
+
+ 110
+ 16777215
+
-
- 100000.000000000000000
+
+ Center Price
-
- 0.000000000000000
+
+ center_price_input
- -
-
+
-
+
+
+ false
+
-
+
0
0
- 110
+ 140
0
-
-
- 110
- 16777215
-
+
+
+
+
+ false
+
+ false
+
+
+ 8
+
+
+ 0.000000000000000
+
+
+ 999999999.998999953269958
+
+
+
+ -
+
- Amount
+ Calculate center price dynamically
-
- spread_input
+
+ true
@@ -376,5 +451,22 @@
-
+
+
+ center_price_dynamic_checkbox
+ clicked(bool)
+ center_price_input
+ setDisabled(bool)
+
+
+ 252
+ 165
+
+
+ 208
+ 136
+
+
+
+