Trading system for automated algorithmic trading on Binance Futures and BitMEX.
Author is not responsible for any damage caused by this software. Be careful and test your strategy using very small sizes for some time to make sure it does what you expect it to do.
- API and Websocket implementation for both Binance Futures and BitMEX
- Supports all pairs
- Event-driven
- all types of orders supported including majority of parameters/combinations - if you miss any, you can request
- Supports custom strategies
- Backtesting
- Testnet only for BitMEX (todo Binance Futures testnet)
- Stub trading
- TA-lib indicators, you can request an indicator as well if its missing
- Very easy strategy implementation, should be easy enough to migrate most pine script(tradingview) strategies - see Sample strategy
- Channel Breakout
- Cross SMA
- RCI
- Open Close Cross Strategy
- Trading View Strategy (implemented but not supported in the current implementation via gmail) - maybe in the future todo tradingview webhooks implementation, until then this project is recommended for tradingview webhooks trading: https://github.com/CryptoMF/frostybot
- Python: 3.6.5
$ brew install ta-lib
$ git clone https://github.com/TheFourGreatErrors/alpha-rptr.git
$ cd alpha-rptr/
$ pip install -r requirements.txt
$ wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
$ tar xvzf ta-lib-0.4.0-src.tar.gz
$ cd ta-lib/
$ ./configure --prefix=/usr
$ make
$ sudo make install
$ git clone https://github.com/TheFourGreatErrors/alpha-rptr.git
$ cd alpha-rptr/
$ pip install -r requirements.txt
Set your API keys in src / config.py
file.
config = {
"binance_keys": {
"binanceaccount1":{"API_KEY": "", "SECRET_KEY": ""},
"binanceaccount2": {"API_KEY": "", "SECRET_KEY": ""}
},
"bitmex_keys": {
"bitmexaccount1":{"API_KEY": "", "SECRET_KEY": ""},
"bitmexaccount2": {"API_KEY": "", "SECRET_KEY": ""}
},
"bitmex_test_keys": {
"bitmextest1":{"API_KEY": "", "SECRET_KEY": ""},
"bitmextest2": {"API_KEY": "", "SECRET_KEY": ""}
},
"line_apikey": {"API_KEY": ""}
}
If you want to send notifications to LINE, set LINE's API key as well. #todo discord and telegram notifications implementation as well.
$ python main.py --account binanceaccount1 --exchange binance --pair BTCUSDT --strategy Sample
By changing the values of ACCOUNT
EXCHANGE
PAIR
STRATEGY
you can switch accounts, exchanges, piars, strategies.
$ python main.py --account bitmexaccount1 --exchange bitmex --pair XBTUSD --strategy Doten
$ python main.py --account binanceaccount1 --exchange binance --pair BTCUSDT --strategy Sample
It is possible to trade on BitMEX testnet. (todo Binance Futures testnet)
$ python main.py --demo --account bitmexaccount1 --exchange bitmex --pair XBTUSD --strategy Sample
$ python main.py --test --account binanceaccount1 --exchange binance --pair BTCUSDT --strategy Sample
$ python main.py --hyperopt --account binanceaccount1 --exchange binance --pair BTCUSDT --strategy Sample
$ python main.py --stub --account binanceaccount1 --exchange binance --pair BTCUSDT --strategy Sample
You can add a strategy by creating a new class in src / strategy.py
.
Follow this example, which hopefully explains a lot of questions.
# sample strategy
class Sample(Bot):
# set variables
long_entry_signal_history = []
short_entry_signal_history = []
def __init__(self):
# set time frame here
Bot.__init__(self, '1m')
# this for parameter optimization in hyperopt mode - see other reference strategies
def options(self):
return {}
def strategy(self, open, close, high, low, volume):
# get lot or set your own value which will be used to size orders
# careful default lot is about 20x your account size !!!
lot = self.exchange.get_lot()
# indicator lengths
fast_len = self.input('fast_len', int, 6)
slow_len = self.input('slow_len', int, 18)
# setting indicators, they usually take source and length as arguments
sma1 = sma(close, fast_len)
sma2 = sma(close, slow_len)
# entry conditions
long_entry_condition = crossover(sma1, sma2)
short_entry_condition = crossunder(sma1, sma2)
# setting a simple stop loss and profit target in % using built-in simple profit take and stop loss implementation
# which is placing the sl and tp automatically after entering a position
self.exchange.sltp(profit_long=1.25, profit_short=1.25, stop_long=1, stop_short=1.1, round_decimals=0)
# example of calculation of stop loss price 0.8% round on 2 decimals hardcoded inside this class
# sl_long = round(close[-1] - close[-1]*0.8/100, 2)
# sl_short = round(close[-1] - close[-1]*0.8/100, 2)
# order execution logic
if long_entry_condition:
# entry - True means long for every other order other than entry use self.exchange.order() function
self.exchange.entry("Long", True, lot/20)
# stop loss hardcoded inside this class
#self.exchange.order("SLLong", False, lot/20, stop=sl_long, reduce_only=True, when=False)
if short_entry_condition:
# entry - False means short for every other order other than entry use self.exchange.order() function
self.exchange.entry("Short", False, lot/20)
# stop loss hardcoded inside this class
# self.exchange.order("SLShort", True, lot/20, stop=sl_short, reduce_only=True, when=False)
# storing history for entry signals, you can store any variable this way to keep historical values
self.long_entry_signal_history.append(long_entry_condition)
self.short_entry_signal_history.append(short_entry_condition)
# OHLCV and indicator data, you can access history using list index
# log indicator values
logger.info(f"sma1: {sma1[-1]}")
logger.info(f"second last sma2: {sma2[-2]}")
# log last candle OHLCV values
logger.info(f"open: {open[-1]}")
logger.info(f"high: {high[-1]}")
logger.info(f"low: {low[-1]}")
logger.info(f"close: {close[-1]}")
logger.info(f"volume: {volume[-1]}")
#second last candle OHLCV values
logger.info(f"second last open: {open[-2]}")
logger.info(f"second last high: {high[-2]}")
logger.info(f"second last low: {low[-2]}")
logger.info(f"second last close: {close[-2]}")
logger.info(f"second last volume: {volume[-2]}")
# log history entry signals
logger.info(f"long_entry_hist: {self.long_entry_signal_history}")
logger.info(f"short_entry_hist: {self.short_entry_signal_history}")
This server is dedicated for bug reporting, feature requests and support. https://discord.gg/ah3MGeN
if you find this software useful and want to support the development, please feel free to donate.
BTC address: ETH address: