Crypto Algo In 5 Minutes

It's that easy to trade with code

It’s So Easy to Algo

Algotrading can be for everyone

How Easy Is It?

When I ask people if they’ve algo traded, typically, they look at me in surprise. Algo trading is a complex operation, requiring detailed market knowledge, careful forethought and expert level coding skills. Even then, the risks must be considered - consider a small typo… runaway code… Doesn’t bare thinking about. Right?

Au contraire…

On exchanges like BitMEX, you can trade with as little as 1 cent (though you’ll be liquidated as soon as the market goes against you). At any level of trading - even just playing with a few dollars you’re an equal peer with everyone else. You can limit your risks to be as low as you wish them to be. (But note: exchanges get upset if you make too many small trades - they may ban you, so be warned!)

Okay - but it’s complex to do it - there’s a steep learning curve - isn’t there?

No not really get some coin and create a BitMEX account and then, using the CCXT Python package:

pip install ccxt

and - once you’ve generated a BitMEX API key and secret (under Key Permissions choose Order)

import ccxt

API = ccxt.bitmex({'apiKey': 'ABCDEfghijkLMNOPqrstuvwxyz', 'secret': 'abcdefg1234567ZYXWVUT9876543HIJKLMOpqrstuv654321'})

payload = {'orders': [{
	'symbol': 'XBTUSD',
	'orderQty': 100,
	'ordType': 'Market'
}]}

API.privatePostOrderBulk(payload)

There - you just bought 100 contracts - effectively $100 worth of Bitcoin. Try it yourself right now!

Not Quite An Algo - Bring on the Market Data!

To make the above code into an algo is basically putting it in a loop. Of course it must buy at the appropriate levels and probably sell at others. You need to know what the market’s doing and respond by placing orders that obey a strategy.

Getting this market data can be a major pain. Thankfully, if you sign up with ProfitView (even on our free tier!) we’ll stream this data to you in real-time. You just have to fill in the blanks.

import os
import socketio

sio = socketio.Client()

class Strategy(socketio.ClientNamespace):

    def __init__(self):
        super().__init__()

    def on_connected(self, data):
        sio.emit('subscribe', ['trade:bitmex:XBTUSD'])

    def on_trade(self, data):
        print(data) # <-- ******* replace me with your strategy! *******

sio.register_namespace(Strategy())
sio.connect(f'https://markets.profitview.net?api_key=ABCDEfghijkLMNOPqrstuvwxyz01234567890ABCDEF', transports=['websocket'])

This time you get the API key from the Settings > Account tab once you’ve fully signed up to your ProfitView account - as I say, even on the free tier.

If you run this code you get results like these:

Then, you just replace that print statement with your own code, using the symbol, size, side and price as input for your algo. Yeah, it’s that easy!

Various strategies are well-known and reasonable - and that’s where it gets fun. You’re now in competition with all the other traders (algo or not).

It’s best if you start with an example to build on - here’s a simple RSI (Relative Strength Index) implementation you’re free to take and develop: github.com/profitviews/rsi-strategy-python.

Note that it’s not likely to make you any money! You’ll need to add your own insight. You’d be wise to back test extensively and start out trading with a small amount you wouldn’t worry about losing.

Subscribe to our Newsletter