Skip to content

Commit

Permalink
refactor Readme and Changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
migueltg committed Apr 12, 2021
1 parent 0ad14d6 commit 9b773da
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 239 deletions.
25 changes: 14 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
243 changes: 79 additions & 164 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,219 +1,134 @@
# passivbot_futures
<h1 align="center">
passivbot_futures
</h1>

**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)
Loading

0 comments on commit 9b773da

Please sign in to comment.