Skip to content

Commit

Permalink
spread calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
bamooxa authored and edeng23 committed Nov 13, 2021
1 parent 86cc395 commit 0347c42
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions .user.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ hourToKeepScoutHistory=1
use_margin=no
scout_multiplier=5
scout_margin=0.8
spead=auto
scout_sleep_time=1
strategy=default
buy_timeout=0
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Create a .cfg file named `user.cfg` based off `.user.cfg.example`, then add your
- **use_margin** - 'yes' to use scout_margin. 'no' to use scout_multiplier.
- **scout_multiplier** - Controls the value by which the difference between the current state of coin ratios and previous state of ratios is multiplied. For bigger values, the bot will wait for bigger margins to arrive before making a trade.
- **scout_margin** - Minimum percentage coin gain per trade. 0.8 translates to a scout multiplier of 5 at 0.1% fee.
- **spread** - "auto" to estimate based on current spread, or input a value. This value is the percentage difference between the buy price and sell price, as sell price is always cheaper.
- **strategy** - The trading strategy to use. See [`binance_trade_bot/strategies`](binance_trade_bot/strategies/README.md) for more information
- **buy_timeout/sell_timeout** - Controls how many minutes to wait before cancelling a limit order (buy/sell) and returning to "scout" mode. 0 means that the order will never be cancelled prematurely.
- **scout_sleep_time** - Controls how many seconds bot should wait between analysis of current prices. Since the bot now operates on websockets this value should be set to something low (like 1), the reasons to set it above 1 are when you observe high CPU usage by bot or you got api errors about requests weight limit.
Expand Down
12 changes: 11 additions & 1 deletion binance_trade_bot/auto_trader.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,19 @@ def _get_ratios(self, coin: Coin, coin_price):
to_fee = self.manager.get_fee(pair.to_coin, self.config.BRIDGE, False)
transaction_fee = from_fee + to_fee - from_fee * to_fee


# Spread
if self.config.SPREAD == "auto":
coinBuyPrice = self.manager.get_buy_price(pair.to_coin + self.config.BRIDGE)
coinSellPrice = self.manager.get_sell_price(pair.to_coin + self.config.BRIDGE)
spread = coinBuyPrice / coinSellPrice - 1
else:
spread = float(self.config.SPREAD) / 100


if self.config.USE_MARGIN == "yes":
ratio_dict[pair] = (
(1- transaction_fee) * coin_opt_coin_ratio / pair.ratio - 1 - self.CONFIG.SCOUT_MARGIN / 100
(1- transaction_fee - spread) * coin_opt_coin_ratio / pair.ratio - 1 - self.CONFIG.SCOUT_MARGIN / 100
)
else:
ratio_dict[pair] = (
Expand Down
2 changes: 2 additions & 0 deletions binance_trade_bot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(self):
"use_margin": "no",
"scout_multiplier": "5",
"scout_margin": "0.8",
"spread": "auto",
"scout_sleep_time": "5",
"hourToKeepScoutHistory": "1",
"tld": "com",
Expand Down Expand Up @@ -75,3 +76,4 @@ def __init__(self):

self.USE_MARGIN = os.environ.get("USE_MARGIN") or config.get(USER_CFG_SECTION, "use_margin")
self.SCOUT_MARGIN = os.environ.get("SCOUT_MARGIN") or config.get(USER_CFG_SECTION, "scout_margin")
self.SPREAD = os.environ.get("SPREAD") or config.get(USER_CFG_SECTION, "spread")

0 comments on commit 0347c42

Please sign in to comment.