{"id":24496862,"url":"https://github.com/10mohi6/bitmex-backtest-python","last_synced_at":"2025-09-11T13:33:04.168Z","repository":{"id":35766666,"uuid":"219193734","full_name":"10mohi6/bitmex-backtest-python","owner":"10mohi6","description":"bitmex-backtest is a python library for backtest with bitmex fx trade rest api on Python 3.7 and above.","archived":false,"fork":false,"pushed_at":"2022-12-08T07:43:44.000Z","size":324,"stargazers_count":12,"open_issues_count":4,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T04:14:20.553Z","etag":null,"topics":["api","backtest","bitmex","btc","fx","python","trade","xbt"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/10mohi6.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-02T18:05:54.000Z","updated_at":"2024-09-09T14:59:00.000Z","dependencies_parsed_at":"2023-01-16T05:48:55.447Z","dependency_job_id":null,"html_url":"https://github.com/10mohi6/bitmex-backtest-python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10mohi6%2Fbitmex-backtest-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10mohi6%2Fbitmex-backtest-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10mohi6%2Fbitmex-backtest-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10mohi6%2Fbitmex-backtest-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/10mohi6","download_url":"https://codeload.github.com/10mohi6/bitmex-backtest-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248819408,"owners_count":21166477,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","backtest","bitmex","btc","fx","python","trade","xbt"],"created_at":"2025-01-21T21:19:11.729Z","updated_at":"2025-04-14T04:14:27.052Z","avatar_url":"https://github.com/10mohi6.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bitmex-backtest\n\n[![PyPI](https://img.shields.io/pypi/v/bitmex-backtest)](https://pypi.org/project/bitmex-backtest/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![codecov](https://codecov.io/gh/10mohi6/bitmex-backtest-python/branch/master/graph/badge.svg)](https://codecov.io/gh/10mohi6/bitmex-backtest-python)\n[![Build Status](https://travis-ci.com/10mohi6/bitmex-backtest-python.svg?branch=master)](https://travis-ci.com/10mohi6/bitmex-backtest-python)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/bitmex-backtest)](https://pypi.org/project/bitmex-backtest/)\n[![Downloads](https://pepy.tech/badge/bitmex-backtest)](https://pepy.tech/project/bitmex-backtest)\n\nbitmex-backtest is a python library for backtest with bitmex fx trade rest api on Python 3.7 and above.\n\n\n## Installation\n\n    $ pip install bitmex-backtest\n\n## Usage\n\n### basic\n```python\nfrom bitmex_backtest import Backtest\n\nbt = Backtest()\nbt.candles(\"XBTUSD\")\nfast_ma = bt.sma(period=5)\nslow_ma = bt.sma(period=25)\nbt.sell_exit = bt.buy_entry = (fast_ma \u003e slow_ma) \u0026 (fast_ma.shift() \u003c= slow_ma.shift())\nbt.buy_exit = bt.sell_entry = (fast_ma \u003c slow_ma) \u0026 (fast_ma.shift() \u003e= slow_ma.shift())\nbt.run()\nbt.plot()\n```\n\n### advanced\n```python\nfrom bitmex_backtest import Backtest\n\nbt = Backtest(test=True)\nfilepath = \"xbtusd-60.csv\"\nif bt.exists(filepath):\n    bt.read_csv(filepath)\nelse:\n    params = {\n        \"resolution\": \"60\",  # 1 hour candlesticks (default=1) 1,3,5,15,30,60,120,180,240,360,720,1D,3D,1W,2W,1M\n        \"count\": \"5000\" # 5000 candlesticks (default=500)\n    }\n    bt.candles(\"XBTUSD\", params)\n    bt.to_csv(filepath)\n\nfast_ma = bt.sma(period=10)\nslow_ma = bt.sma(period=30)\nexit_ma = bt.sma(period=5)\nbt.buy_entry = (fast_ma \u003e slow_ma) \u0026 (fast_ma.shift() \u003c= slow_ma.shift())\nbt.sell_entry = (fast_ma \u003c slow_ma) \u0026 (fast_ma.shift() \u003e= slow_ma.shift())\nbt.buy_exit = (bt.C \u003c exit_ma) \u0026 (bt.C.shift() \u003e= exit_ma.shift())\nbt.sell_exit = (bt.C \u003e exit_ma) \u0026 (bt.C.shift() \u003c= exit_ma.shift())\n\nbt.quantity = 100 # default=1\nbt.stop_loss = 200 # stop loss (default=0)\nbt.take_profit = 1000 # take profit (default=0)\n\nprint(bt.run())\nbt.plot(\"backtest.png\")\n```\n\n```python\ntotal profit       -342200.000\ntotal trades           162.000\nwin rate                32.716\nprofit factor            0.592\nmaximum drawdown    470950.000\nrecovery factor         -0.727\nriskreward ratio         1.295\nsharpe ratio            -0.127\naverage return         -20.325\nstop loss               23.000\ntake profit              1.000\n```\n![advanced.png](https://raw.githubusercontent.com/10mohi6/bitmex-backtest-python/master/tests/advanced.png)\n\n\n## Supported indicators\n- Simple Moving Average 'sma'\n- Exponential Moving Average 'ema'\n- Moving Average Convergence Divergence 'macd'\n- Relative Strenght Index 'rsi'\n- Bollinger Bands 'bband'\n- Stochastic Oscillator 'stoch'\n- Market Momentum 'mom'\n\n\n## Getting started\n\nFor help getting started with bitmex REST API, view our online [documentation](https://www.bitmex.com/app/restAPI).\n\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F10mohi6%2Fbitmex-backtest-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F10mohi6%2Fbitmex-backtest-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F10mohi6%2Fbitmex-backtest-python/lists"}