Skip to main content

bitmex-backtest is a python library for backtest with bitmex fx trade rest api on Python 3.7 and above.

Project description


PyPI License: MIT codecov Build Status PyPI - Python Version Downloads

bitmex-backtest is a python library for backtest with bitmex fx trade rest api on Python 3.7 and above.


$ pip install bitmex-backtest



from bitmex_backtest import Backtest

bt = Backtest()
fast_ma = bt.sma(period=5)
slow_ma = bt.sma(period=25)
bt.sell_exit = bt.buy_entry = (fast_ma > slow_ma) & (fast_ma.shift() <= slow_ma.shift())
bt.buy_exit = bt.sell_entry = (fast_ma < slow_ma) & (fast_ma.shift() >= slow_ma.shift())


from bitmex_backtest import Backtest

bt = Backtest(test=True)
filepath = "xbtusd-60.csv"
if bt.exists(filepath):
    params = {
        "resolution": "60",  # 1 hour candlesticks (default=1) 1,3,5,15,30,60,120,180,240,360,720,1D,3D,1W,2W,1M
        "count": "5000" # 5000 candlesticks (default=500)
    bt.candles("XBTUSD", params)

fast_ma = bt.sma(period=10)
slow_ma = bt.sma(period=30)
exit_ma = bt.sma(period=5)
bt.buy_entry = (fast_ma > slow_ma) & (fast_ma.shift() <= slow_ma.shift())
bt.sell_entry = (fast_ma < slow_ma) & (fast_ma.shift() >= slow_ma.shift())
bt.buy_exit = (bt.C < exit_ma) & (bt.C.shift() >= exit_ma.shift())
bt.sell_exit = (bt.C > exit_ma) & (bt.C.shift() <= exit_ma.shift())

bt.quantity = 100 # default=1
bt.stop_loss = 200 # stop loss (default=0)
bt.take_profit = 1000 # take profit (default=0)

total profit       -342200.000
total trades           162.000
win rate                32.716
profit factor            0.592
maximum drawdown    470950.000
recovery factor         -0.727
riskreward ratio         1.295
sharpe ratio            -0.127
average return         -20.325
stop loss               23.000
take profit              1.000


Supported indicators

  • Simple Moving Average 'sma'
  • Exponential Moving Average 'ema'
  • Moving Average Convergence Divergence 'macd'
  • Relative Strenght Index 'rsi'
  • Bollinger Bands 'bband'
  • Stochastic Oscillator 'stoch'
  • Market Momentum 'mom'

Getting started

For help getting started with bitmex REST API, view our online documentation.


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for bitmex-backtest, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size bitmex_backtest-0.1.3-py3-none-any.whl (6.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size bitmex-backtest-0.1.3.tar.gz (6.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page