diff --git a/.gitignore b/.gitignore
index 29d8e5422..e70fb1f1b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -338,18 +338,21 @@ $RECYCLE.BIN/
*.lnk
# Backtest files
-!/backtest_configs/xmr.hjson
-/backtest_configs/*
-/plots/
-/backtest_results/
+!backtest_configs/xmr.hjson
+backtest_configs/*
+plots/
+backtest_results/
# Run files
-/historical_data/
+historical_data/
# Config files
-!/api_key_secrets/binance/example_user.json
-!/api_key_secrets/bybit/example_user.json
-/api_key_secrets/*
-!/live_settings/binance/default.json
-!/live_settings/bybit/default.json
-/live_settings/*
+!api_key_secrets/binance/example_user.json
+!api_key_secrets/bybit/example_user.json
+api_key_secrets/*
+!live_settings/binance/default.json
+!live_settings/bybit/default.json
+live_settings/*
+
+# Reports
+reports/*
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 000000000..b76e6a5a8
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2012-2021 Scott Chacon and others
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
diff --git a/README.md b/README.md
index 742970178..b08a5f794 100644
--- a/README.md
+++ b/README.md
@@ -1,219 +1,134 @@
-# passivbot_futures
+
+ passivbot_futures
+
-**Version: 3.3.3**
+![passivbot_futures Version](https://img.shields.io/badge/passivbot__futures-3.3.3-blue)
+![GitHub issues](https://img.shields.io/github/issues/enarjord/passivbot_futures)
+![GitHub](https://img.shields.io/github/license/enarjord/passivbot_futures)
-trading bot running on bybit and binance futures using hedge mode when possible
+## Trading bot running on Bybit and Binance Futures using hedge mode when possible
-use at own risk
+:warning: **Use at own risk** :warning:
-requires python >= 3.8
+## Overview
-dependencies, install with pip:
+The bot's purpose is to accumulate tokens over time
-`pip install -r requirements.txt`
+It is a market maker bot working in futures markets, making multiple post only limit orders above and below current
+price
-discord
+It listens to websocket live stream of trades, and updates its orders continuously
-https://discord.gg/QAF2H2UmzZ
+If there is a long position, it creates reentry bids below pos price, and reduce-only asks above pos price:
-telegram
+`reentry_bid_price = pos_price * (1 - grid_spacing * (1 + (position_margin / wallet_balance) * grid_coefficient))`
-https://t.me/passivbot_futures
+If there is a short position, it creates reentry asks above pos price, and reduce-only closing bids below pos price:
-for a repository of settings and their backtesting results, see
+`reentry_ask_price = pos_price * (1 + grid_spacing * (1 + (position_margin / wallet_balance) * grid_coefficient))`
-https://github.com/JohnKearney1/PassivBot-Configurations
+In hedge mode, stop loss works thusly:
-for more detailed documentation on this project, see the wiki at:
-
-https://github.com/enarjord/passivbot_futures/wiki
-
-bybit ref:
-https://www.bybit.com/en-US/register?affiliate_id=16464&language=en-US&group_id=0&group_type=1
-
-binance ref:
-https://www.binance.cc/en/register?ref=TII4B07C
-
-------------------------------------------------------------------
-change log
-
-2021-03-12 v3.0.0
-- binance hedge mode implemented (bybit not yet supported)
-- emas removed
-- stop loss removed
-
-2021-03-18 v3.0.1
-- hedge mode backtester implemented
-- emas added back
-
-2021-03-21 v3.1.0
-- removed setting min_close_qty_multiplier
-- added setting close_qty_pct, which complements entry_qty_pct
-- rewrote iter_long/shrt_closes
-- fixed memory leak bug
-
-2021-03-23 v3.2.0
-- implemented particle swarm optimizationg algorithm, replacing jackrabbit
-- bybit hedge mode with inverse futures
-- removed config param close_qty_pct
-- removed config param balance_pct
-- removed config param max_markup
-- added config param markup_range
-
-2021-03-25 v3.2.1
-- bug fixes
-- bybit backtester improvements and bug fixes
-- numba is now enabled by default, use --nojit to disable numba
-- several renamings
-
-2021-03-30 v3.3.0
-- bybit usdt linear perpetual and bybit inverse perpetual markets now supported
-- new downloader for historical backtesting data
-
-2021-04-01 v3.3.1
-- binance inverse futures coin margined markets now supported
-
-2021-04-05 v3.3.2
-- changed api key format. put api key/secret in api-keys.json in main dir.
-- changed name of live_settings dir to live_configs, removed subdirs binance/bybit
-- changed how to use start_bot.py. see updated startup instructions
-- improved backtester multiprocessing memory usage
-
-2021-04-05 v3.3.3
-- added stop loss
-- todo: backtester with stop loss
-
-
-see `changelog.txt` for earlier changes
-
-
-
-------------------------------------------------------------------
+```
+if diff(liq_price, last_price) < stop_loss_liq_diff:
+ if available margin:
+ enter opposite side
+ else:
+ close same side at a loss
+```
-released freely -- anybody may copy, redistribute, modify, use for commercial, non-commercial, educational or non-educational purposes, censor, claim as one's own or otherwise do or not do whatever without permission from anybody
+In both cases liq price will be pushed away
-------------------------------------------------------------------
+### Requirements
-usage:
+- Python >= 3.8
+- [requirements.txt](requirements.txt) dependencies
-supports exchanges bybit futures and binance futures, using hedge mode when supported
+### Setup dependencies
-add api key and secret in file `api-keys.json`
+```bash
+ pip install -r requirements.txt
+```
-run in terminal: `python3 start_bot.py {account_name} {symbol} {path/to/config.json}`
+### Usage:
-for example
+#### Supports exchanges Bybit futures and Binance futures, using hedge mode when supported
-`python3 start_bot.py binance_01 XMRUSDT live_configs/binance_default.json`
+1. Add your api key and secret in file [api-keys.json](api-keys.json)
+2. ```bash
+ python3 start_bot.py {account_name} {symbol} {path/to/config.json}
+ ```
-run in docker: modify command with exchange and user_name in docker-compose and start with `docker-compose up -d` (-d for background run). all code and files generated are in original git folder.
+Example:
-for graceful stopping of the bot, set do_long and do_shrt both to false, and bot will continue as normal, opening no new positions, until all existing positions are closed
+```bash
+python3 start_bot.py binance_01 XMRUSDT live_configs/binance_default.json
+```
-------------------------------------------------------------------
-overview
+#### Run with docker
-the bot's purpose is to accumulate tokens over time
+Modify command with exchange and user_name in [docker-compose.yml](docker-compose.yml) and start
+with `docker-compose up -d` (-d for background run). All code and files generated are in original git folder.
-it is a market maker bot working in futures markets, making multiple post only limit orders above and below current price
+#### Stopping bot
-it listens to websocket live stream of trades, and updates its orders continuously
+For graceful stopping of the bot, set `do_long`and `do_shrt` both to `false`, and bot will continue as normal, opening
+no new positions, until all existing positions are closed.
-if there is a long position, it creates reentry bids below pos price, and reduce-only asks above pos price
+### Documentation [WIP], see the wiki at:
-reentry_bid_price = pos_price * (1 - grid_spacing * (1 + (position_margin / wallet_balance) * grid_coefficient))
+https://github.com/enarjord/passivbot_futures/wiki
-if there is a short position, it creates reentry asks above pos price, and reduce-only closing bids below pos price
+### Support
-reentry_ask_price = pos_price * (1 + grid_spacing * (1 + (position_margin / wallet_balance) * grid_coefficient))
+[![Discord](https://img.shields.io/badge/Discord-7289DA?style=for-the-badge&logo=discord&logoColor=white)](https://t.me/passivbot_futures)
-in hedge mode, stop loss works thusly:
-```
-if diff(liq_price, last_price) < stop_loss_liq_diff:
- if available margin:
- enter opposite side
- else:
- close same side at a loss
-```
+[![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white)](https://discord.gg/QAF2H2UmzZ)
-in both cases liq price will be pushed away
+### Resources
+- Repository of settings and their backtesting results: https://github.com/JohnKearney1/PassivBot-Configurations
-------------------------------------------------------------------
+### [Changelog](changelog.md)
-a backtester is included
+### License
-go to `backtest_configs/{config_name}.hjson` and adjust
+Released freely, anybody may copy, redistribute, modify, use for commercial, non-commercial, educational or
+non-educational purposes, censor, claim as one's own or otherwise do or not do whatever without permission from anybody.
-run with
+## Backtester
-`python3 backtest.py {config_name}`
+A backtester is included
-will use numba's just in time compiler by default to speed up backtesting
+1. go to `backtest_configs/{config_name}.hjson` and adjust it
+2. run with `python3 backtest.py {config_name}`
-add argument --nojit to disable numba:
+Will use numba's just in time compiler by default to speed up backtesting, add argument `--nojit` to disable numba:
`python3 backtest.py {config_name} --nojit`
-see wiki for more info on backtesting
-
-------------------------------------------------------------------
-
-about live settings, bybit example:
-
-{
-
- "config_name": "BTCUSD_default", # arbitrary name given to settings.
-
- "qty_pct": 0.005, # percentage of balance * leverage used as min order qty.
-
- "ddown_factor": 0.02, # next reentry_qty is max(initial_entry_qty, abs(pos_size) * ddown_factor).
- # if set to 1.0, each reentry qty will be equal to 1x pos size, i.e. doubling pos size after every reentry.
- # if set to 1.5, each reentry qty will be equal to 1.5x pos size.
- # if set to 0.0, each reentry qty will be equal to initial_entry_qty.
-
- "ema_span": 10000, # tick ema is not based on ohlcvs, but calculated based on sequence of raw trades.
- "ema_spread": 0.001 # if no pos, bid = min(ema * (1 - spread), highest_bid) and ask = max(ema * (1 + spread), lowest_ask)
-
- "do_long": true, # if true, will allow long positions
- "do_shrt": true # if true, will allow short posisions
-
- "grid_coefficient": 245.0, # next entry price is pos_price * (1 +- grid_spacing * (1 + (pos_margin / balance) * grid_coefficient)).
- "grid_spacing": 0.0026, #
-
- "leverage": 100, # leverage (irrelevant in bybit because cross mode in is always max leverage).
- "logging_level": 0, # if logging_level > 0,
- # will log positions, open orders, order creations and order cancellations in logs/{exchange}/{config_name}.log.
+See [wiki](https://github.com/enarjord/passivbot_futures/wiki) for more info on backtesting
- "min_markup": 0.0002, # when there's a position, bot makes a grid of n_close_orders whose prices are
- "markup_range": 0.0159, # evenly distributed between min_markup and (min_markup + markup_range), and whose qtys are pos_size // n_close_orders.
-
- "n_close_orders": 20, # max n close orders.
- "n_entry_orders": 8, # max n entry orders.
-
- "stop_loss_liq_diff": 0.2 # if difference between liq price and last price is less than 20%, ...
- "stop_loss_pos_pct": 0.01 # ... if available margin, increase opposite side pos by 1%, otherwise reduce same side pos by 1%
- "symbol": "BTCUSD" # only one symbol at a time.
+## Live settings
-}
-
+- [Binance](live_configs/binance_default.json)
+- [Bybit](live_configs/bybit_default.json)
-------------------------------------------------------------------
+## Support the project
-feel free to make a donation to show support of the work
+### Feel free to make a donation to show support of the work
-XMR: 49gUQ1jasDK23tJTMCvP4mQUUwndeLWAwSgdCFn6ovmRKXZAjQnVp2JZ2K4UuDDdYMNam1HE8ELZoWdeJPRfYEa9QSEK6XZ
+- XMR: `49gUQ1jasDK23tJTMCvP4mQUUwndeLWAwSgdCFn6ovmRKXZAjQnVp2JZ2K4UuDDdYMNam1HE8ELZoWdeJPRfYEa9QSEK6XZ`
-Nano: nano_1nf3knbhapee5ruwg7i8sqekx3zmifdeijr8495t9kgp3uyunik7b9cuyhf5
+- Nano: `nano_1nf3knbhapee5ruwg7i8sqekx3zmifdeijr8495t9kgp3uyunik7b9cuyhf5`
-EOS: nbt4rhnhpjan
+- EOS: `nbt4rhnhpjan`
-XLM: GDSTC6KQR6BCTA7BH45B3MTSY52EVZ4UZTPZEBAZHJMJHTUQQ5SM57S7
+- XLM: `GDSTC6KQR6BCTA7BH45B3MTSY52EVZ4UZTPZEBAZHJMJHTUQQ5SM57S7`
-USDT TRC20 (binance): TJr3KYY8Bz7wRU7QLwoYQHk88LcaBJqQN5
+- USDT TRC20 (Binance): `TJr3KYY8Bz7wRU7QLwoYQHk88LcaBJqQN5`
-bybit ref:
-https://www.bybit.com/en-US/register?affiliate_id=16464&language=en-US&group_id=0&group_type=1
+### Referrals
-binance ref:
-https://www.binance.cc/en/register?ref=TII4B07C
+- [Bybit](https://www.bybit.com/en-US/register?affiliate_id=16464&language=en-US&group_id=0&group_type=1)
+- [Binance](https://www.binance.cc/en/register?ref=TII4B07C)
diff --git a/changelog.txt b/changelog.md
similarity index 51%
rename from changelog.txt
rename to changelog.md
index e4762d2db..8ebdb84ff 100644
--- a/changelog.txt
+++ b/changelog.md
@@ -1,92 +1,198 @@
-2021-01-19
-- renamed settings["margin_limit"] to settings["balance"]
-- bug fixes and changes in trade data downloading
-- if there already is historical trade data downloaded, run the script `rename_trade_data_csvs.py` to rename all files
+# Changelog
-2021-01-23
-- removed static mode
-- added indicator ema
-- rewrote backtester
+All notable changes to this project will be documented in this file.
-2021-01-30
-- changed backtesting results formatting
-- fixed insufficient margin error
-- many other fixes and changes...
-- added possibility of running same backtest in two or more terminals for better cpu utilization
+## [Unreleased]
+- added backtester with stoploss
+
+## [v3.3.3] - 2021-04-05
+
+- added stop loss
+- todo: backtester with stop loss
+
+## [v3.3.2] - 2021-04-05
+
+- changed api key format. put api key/secret in api-keys.json in main dir.
+- changed name of live_settings dir to live_configs, removed subdirs binance/bybit
+- changed how to use start_bot.py. see updated startup instructions
+- improved backtester multiprocessing memory usage
+
+## [v3.1.1] - 2021-04-01
+
+- binance inverse futures coin margined markets now supported
+
+## [v3.3.0] - 2021-03-30
+
+- bybit usdt linear perpetual and bybit inverse perpetual markets now supported
+- new downloader for historical backtesting data
+
+## [v3.2.1] - 2021-03-25
-2021-02-03
-- backtester break conditions change
- bug fixes
+- bybit backtester improvements and bug fixes
+- numba is now enabled by default, use --nojit to disable numba
+- several renamings
-2021-02-08
-- added min_close_qty_multiplier
+## [v3.2.0] - 2021-03-23
-2021-02-09
-- added classic stop loss
+- implemented particle swarm optimizationg algorithm, replacing jackrabbit
+- bybit hedge mode with inverse futures
+- removed config param close_qty_pct
+- removed config param balance_pct
+- removed config param max_markup
+- added config param markup_range
-2021-02-10
-- renamed settings["default_qty"] to settings["entry_qty_pct"]
-- settings["entry_qty_pct"] may now also be a positive value
-- renamed settings["balance"] to settings["balance_pct"]
-- settings["balance_pct"] may now also be a positive value
-- added balance_pct to backtester. backtester will now behave like live bot, taking balance_pct into account
- - actual balance is used for liq price calc, otherwise balance * balance_pct is used
+## [v3.1.0] - 2021-03-21
+
+- removed setting min_close_qty_multiplier
+- added setting close_qty_pct, which complements entry_qty_pct
+- rewrote iter_long/shrt_closes
+- fixed memory leak bug
+
+## [v3.0.1] - 2021-03-18
+
+- hedge mode backtester implemented
+- emas added back
+
+## [v3.0.0] - 2021-03-12
+
+- binance hedge mode implemented (bybit not yet supported)
+- emas removed
+- stop loss removed
+
+## [v2.0.3] - 2021-03-02
+
+- new default bybit config
+- behavior change: reentry qtys may now be smaller than initial entry qty
+- backtest iterates a numpy array instead of a python list of dicts for reduced ram usage
+
+## [v2.0.2] - 2021-03-01
+
+- more jit'ed calcs
+
+## [v2.0.1] - 2021-02-28
+
+- added optional just-in-time compiling for faster backtesting
+
+## [v2.0.0] - 2021-02-23
+
+- major update to backtester
+- new backtest usage syntax
+- other changes
+
+## [v1.3.3] - 2021-02-18
+
+- minor refactoring
+
+## [v1.3.0] - 2021-02-17
+
+- added indicator_settings["tick_ema"]["spread"] to live bot and backtester
+ - optional setting -- ema_spread defaults to 0.0 if not present in config file
+
+## [v1.2.1] - 2021-02-17
+
+- backtester will cache exchange fetched settings after first run
+- backtester will prevent using leverage higher than max leverage, in case max leverage set in ranges.json was too high
+
+## [v1.2.0] - 2021-02-17
+
+- bug fixes
+- change in backtesting_notes.ipynb
+ - automatic plot dump
+ - other changes
+- backtester now fetches relevant data from exchanges instead of user having to input them manually
+
+## [v1.1.0] - 2021-02-16
+
+- bug fixes v1.0.2
+- updated default bybit live settings v1.1.0
+
+## 2021-02-12
-2021-02-12
- added indicator_settings["funding_fee_collect_mode"]
- - if true, will enter long only if predicted fundig rate is negative and enter short only if predicted funding rate is positive
+ - if true, will enter long only if predicted fundig rate is negative and enter short only if predicted funding rate
+ is positive
- added indicator rsi (not finished, not active)
- changed entry_qty_pct formula
- before initial_entry_qty = balance_ito_contracts * entry_qty_pct
- - now initial_entry_qty = balance_ito_contracts * leverage * entry_qty_pct
+ - now initial_entry_qty = balance_ito_contracts * leverage * entry_qty_pct
- added logging
- added "config_name" and "logging_level" to live settings
- added break_on condition: break if balance + pnl < starting_balance
-2021-02-16
-- bug fixes v1.0.2
-- updated default bybit live settings v1.1.0
+## 2021-02-10
+
+- renamed settings["default_qty"] to settings["entry_qty_pct"]
+- settings["entry_qty_pct"] may now also be a positive value
+- renamed settings["balance"] to settings["balance_pct"]
+- settings["balance_pct"] may now also be a positive value
+- added balance_pct to backtester. backtester will now behave like live bot, taking balance_pct into account
+ - actual balance is used for liq price calc, otherwise balance * balance_pct is used
+
+## 2021-02-09
+
+- added classic stop loss
+
+## 2021-02-08
+
+- added min_close_qty_multiplier
-2021-02-17 v1.2.0
+## 2021-02-03
+
+- backtester break conditions change
- bug fixes
-- change in backtesting_notes.ipynb
- - automatic plot dump
- - other changes
-- backtester now fetches relevant data from exchanges instead of user having to input them manually
-2021-02-17 v1.2.1
-- backtester will cache exchange fetched settings after first run
-- backtester will prevent using leverage higher than max leverage, in case max leverage set in ranges.json was too high
+## 2021-01-30
+
+- changed backtesting results formatting
+- fixed insufficient margin error
+- many other fixes and changes...
+- added possibility of running same backtest in two or more terminals for better cpu utilization
+
+## 2021-01-23
+
+- removed static mode
+- added indicator ema
+- rewrote backtester
+
+## 2021-01-19
+
+- renamed settings["margin_limit"] to settings["balance"]
+- bug fixes and changes in trade data downloading
+- if there already is historical trade data downloaded, run the script `rename_trade_data_csvs.py` to rename all files
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-2021-02-17 v1.3.0
-- added indicator_settings["tick_ema"]["spread"] to live bot and backtester
- - optional setting -- ema_spread defaults to 0.0 if not present in config file
-2021-02-18 v1.3.3
-- minor refactoring
-2021-02-23 v2.0.0
-- major update to backtester
-- new backtest usage syntax
-- other changes
-2021-02-23 v2.0.0_beta
-- major update to backtester
-- new backtest usage syntax
-- other changes
-2021-02-27 v2.0.0
-- bug fixes
-- new default configs for bybit and binance
-2021-02-28 v2.0.1
-- added optional just-in-time compiling for faster backtesting
-2021-03-01 v2.0.2
-- more jit'ed calcs
-2021-03-02 v2.0.3
-- new default bybit config
-- behavior change: reentry qtys may now be smaller than initial entry qty
-- backtest iterates a numpy array instead of a python list of dicts for reduced ram usage