This is a simple yet effective approach to Day Trade any Cryptocurrency.
- Using the RSI indicator (Relative strength index) we can determine whether we should buy or sell. ultimately our goal is to buy low sell high.
- depending on the day period we choose and rsi overbought/oversold triggers we implement will drastically change the outcome of our algorithm.
- the bot will use the Binance API to connect to your account and automate trading
- ** I have had mixed results with this bot I have been hitting around a 3% to 20% ROI in 3 months' time.
- Running in Visual Studio Code
Code
import websocket, json, pprint, talib, numpy import config from binance.client import Client from binance.enums import * SOCKET = "wss://stream.binance.com:9443/ws/ethusdt@kline_1m" RSI_PERIOD = 14 RSI_OVERBOUGHT = 70 RSI_OVERSOLD = 30 TRADE_SYMBOL = 'ETHUSD' TRADE_QUANTITY = 0.05 closes = [] in_position = False client = Client(config.API_KEY, config.API_SECRET, tld='us') def order(side, quantity, symbol,order_type=ORDER_TYPE_MARKET): try: print("sending order") order=client.create_order(symbol=symbol, side=side, type=order_type, quantity=quantity) print(order) exceptExceptionase: print("an exception occured - {}".format(e)) returnFalse returnTrue def on_open(ws): print('opened connection') def on_close(ws): print('closed connection') def on_message(ws, message): globalcloses, in_position print('received message') json_message=json.loads(message) pprint.pprint(json_message) candle=json_message['k'] is_candle_closed=candle['x'] close=candle['c'] ifis_candle_closed: print("candle closed at {}".format(close)) closes.append(float(close)) print("closes") print(closes) iflen(closes) >RSI_PERIOD: np_closes=numpy.array(closes) rsi=talib.RSI(np_closes, RSI_PERIOD) print("all rsis calculated so far") print(rsi) last_rsi=rsi[-1] print("the current rsi is {}".format(last_rsi)) iflast_rsi>RSI_OVERBOUGHT: ifin_position: print("Overbought! Sell! Sell! Sell!") # put binance sell logic here order_succeeded=order(SIDE_SELL, TRADE_QUANTITY, TRADE_SYMBOL) iforder_succeeded: in_position=False else: print("It is overbought, but we don't own any. Nothing to do.") iflast_rsi<RSI_OVERSOLD: ifin_position: print("It is oversold, but you already own it, nothing to do.") else: print("Oversold! Buy! Buy! Buy!") # put binance buy order logic here order_succeeded=order(SIDE_BUY, TRADE_QUANTITY, TRADE_SYMBOL) iforder_succeeded: in_position=True ws = websocket.WebSocketApp(SOCKET, on_open=on_open, on_close=on_close, on_message=on_message) ws.run_forever()
config.py
API_KEY = 'yourbinanceapikey' API_SECRET = 'yourbinanceapisecret
reqiurements.txt
python-binance TA-Lib numpy websocket_client