bitmex-backtest
bitmex-backtest is a python library for backtest with bitmex fx trade rest api on Python 3.7 and above.
Installation
$ pip install bitmex-backtest
Usage
basic
from bitmex_backtest import Backtest
bt = Backtest()
bt.candles("XBTUSD")
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())
bt.run()
bt.plot()
advanced
from bitmex_backtest import Backtest
bt = Backtest(test=True)
filepath = "xbtusd-60.csv"
if bt.exists(filepath):
bt.read_csv(filepath)
else:
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)
bt.to_csv(filepath)
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)
print(bt.run())
bt.plot("backtest.png")
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.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
Metadata
Release files for bitmex-backtest 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bitmex-backtest-0.1.3.tar.gz | 6.5 kB | Without provenance | Details for bitmex-backtest-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bitmex_backtest-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for bitmex_backtest-0.1.3-py3-none-any.whl |
Total release size: 13.4 kB
Release files / bitmex-backtest-0.1.3.tar.gz
| Download URL | bitmex-backtest-0.1.3.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3b27bcf7e24f9e353466bff7c3a0672583178beac8a67baffe7c74d166d3e7c0
|
|
BLAKE2b-256 checksum How to use checksums |
670aae26b1bc8409c7519fe7f3ea0d5391dfee449eb53d34ee21e18767c5b26d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.2
|
Release files / bitmex_backtest-0.1.3-py3-none-any.whl
| Download URL | bitmex_backtest-0.1.3-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a000d353cbfd78df831c8b4d585b43f0fa0e3006136f5fe0b0fdc18edd9aaf01
|
|
BLAKE2b-256 checksum How to use checksums |
d3beff6ff644f4e1ea2f3fba8ee127e2b3e52bd7101b0e5d7a0468a0e9085c67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.2
|
Security for bitmex-backtest 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.