{"id":20115370,"url":"https://github.com/tistaharahap/mexjs","last_synced_at":"2026-06-05T02:31:33.347Z","repository":{"id":98774565,"uuid":"196573002","full_name":"tistaharahap/mexjs","owner":"tistaharahap","description":"Full featured Bitmex trading bot","archived":false,"fork":false,"pushed_at":"2020-06-05T16:52:23.000Z","size":683,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-02T19:19:08.101Z","etag":null,"topics":["bitmex","bot","cryptocurrency","strategy","trading"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tistaharahap.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-12T12:08:57.000Z","updated_at":"2020-12-18T04:26:14.000Z","dependencies_parsed_at":"2023-03-16T08:01:07.167Z","dependency_job_id":null,"html_url":"https://github.com/tistaharahap/mexjs","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/tistaharahap/mexjs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tistaharahap%2Fmexjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tistaharahap%2Fmexjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tistaharahap%2Fmexjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tistaharahap%2Fmexjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tistaharahap","download_url":"https://codeload.github.com/tistaharahap/mexjs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tistaharahap%2Fmexjs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33927314,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-05T02:00:06.157Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["bitmex","bot","cryptocurrency","strategy","trading"],"created_at":"2024-11-13T18:35:00.100Z","updated_at":"2026-06-05T02:31:33.332Z","avatar_url":"https://github.com/tistaharahap.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MexJS\n\n`MexJS` is a `BitMex` trading bot with custom strategies. It is coded with [RxJs 5.5.x](https://rxjs.dev) to direct streams although in practice the codes are not pure functional, side effects are still welcomed.\n\nThe core of the bot are as follows:\n\n* Candlestream - Poller to get new candles every 10 seconds\n* Realtime Feed - Websocket feed to get new prices as they're submitted to Bitmex\n* Strategies - Basically a rule engine filtering only what we want when we make an entry\n\nYou'd notice the absence of an exit strategy. As of this writing, exit is done by setting TP limits. Through env vars described below, you can choose to set TP based on pips or percentages. As traders would have different styles in exiting, customizing exit strategies is within the feature plans.\n\nIn pseudocode, the flow of `mexjs` is as follows:\n\n```\n## Cancel all orders\ncancel all order\n\n## Get Candle Data\nget candlestream\napply indicators to candlestream\n\n## Check remaining open positions\nget open position\nif any open position:\n  get latest_price\n  set tp_price = tp_in_percentage * entry_price\n  set cl_price = sl_in_percentage * entry_price\n  if latest_price \u003e tp_price\n    tp_price = latest_price +/- 1 pip\n\n  create take profit using limit (close)\n  create stop loss order using market (index price, close) \n\n## Apply Filter\nconnect ws\nfilter state\nfilter based on strategy\nset leverage position\ncreate entry order using limit\nwhile not trade timeout or order status = filled:\n  get entry order status\n\nif not filled:\n  break\nif filled or partially filled:\n  cancel order nya\n  get quantity yg didapet\n\ncreate take profit using limit (close)\ncreate stop loss order using market (index price, close)\n\n## Polling\nIf any active order\n  get orders detail\n  if take profit order or stop loss order closed\n    cancel remaining order\n    set state\n    send message to telegram\n```\n\n### Versions\n\nComplete log of versions starting from `0.6.7`.\n\n#### 0.6.7\n\nAs of this version, the core is becoming stable. The mechanics and error handlings have matured. \n\nIntroducing these new env vars:\n\n* `TP_STRATEGY`\n* `TP_IN_PERCENTAGE`\n* `TP_IN_PIP`\n* `SL_STRATEGY`\n* `SL_IN_PERCENTAGE`\n* `SL_IN_PIP`\n\nNow TP and SL can have different strategies.\n\n## Indicators\n\nWe can calculate our own indicators or use the excellent [technicalindicators](https://github.com/anandanand84/technicalindicators) library.\n\nUse [candlestream.js](src/candlestream.js) to plug your indicator to candles. Strategies will look for indicators from candlesticks.\n\nYou can develop your own or alias something from the `technicalindicators` library in [indicators.js](src/indicators.js).\n\n## Strategies\n\nAll strategy classes must extend the base `Strategy` class [here](src/strategies/base.js). The constructor accepts 2 arguments which are `candlesticks` and `feed`.\n\nAppend `-long` and `-short` suffixes for your strategy name to be loaded [here](src/strategies/index.js). If you don't do this, you will not be able to trade.\n\nAll strategy classes must implement a `filter()` method returnin `true` or `false` for conditions met or unmet for the strategy.\n\nMost of the strategies written by the first commiters are based on [Bill Williams' trading strategies](https://www.amazon.com/Trading-Chaos-Technical-Techniques-Marketplace-ebook/dp/B008NC0YIK). You can mix and match multiple strategies into a new strategy like so:\n\n```javascript\nimport SuperLongStrategy from './super-long.js'\nimport DefinitelyLongStrategy from './definitely-long.js'\n\nclass MixedStrategy extends Strategy {\n  filter() {\n    return new SuperLongStrategy(this.candlesticks, this.feed).filter() \u0026\u0026\n      new DefinitelyLongStrategy(this.candlesticks, this.feed).filter()\n  }\n}\n```\n\nOr you can mix other strategies with more new filters:\n\n```javascript\nimport SuperLongStrategy from './super-long.js'\nimport DefinitelyLongStrategy from './definitely-long.js'\n\nclass MixedStrategy extends Strategy {\n  filter() {\n    return new SuperLongStrategy(this.candlesticks, this.feed).filter() \u0026\u0026\n      new DefinitelyLongStrategy(this.candlesticks, this.feed).filter() \u0026\u0026\n      this.getRidOfFakeSignals()\n  }\n\n  getRidOfFakeSignals() {\n    // ...\n  }\n}\n```\n\n### VWMA Long (vwma-long)\n\nRequired env var values:\n\n* `TRADE_ON_CLOSE=1`\n\n### VWMA Short (vwma-short)\n\nRequired env var values:\n\n* `TRADE_ON_CLOSE=1`\n\n### Nektrabar Long (nektrabar-long)\n\nRequired env var values:\n\n* `TRADE_ON_CLOSE=1`\n\n### Nektrabar Short (nektrabar-short)\n\nRequired env var values:\n\n* `TRADE_ON_CLOSE=1`\n\n### Fractal Breakout Long (fractalbreakout-long)\n\nRequired env var values:\n\n* `TRADE_ON_CLOSE=0`\n\n### Fractal Breakout Short (fractalbreakout-short)\n\nRequired env var values:\n\n* `TRADE_ON_CLOSE=0`\n\n### Fractal3 Breakout Long (fractal3breakout-long)\n\nRequired env var values:\n\n* `TRADE_ON_CLOSE=0`\n\n### Fractalligator Long (fractalligator-long)\n\nRequired env var values:\n\n* `TRADE_ON_CLOSE=0`\n\n### Fractalligator Short (fractalligator-short)\n\nRequired env var values:\n\n* `TRADE_ON_CLOSE=0`\n\n### Wisemen 3 Long (wisemen3-long)\n\nRequired env var values:\n\n* `TRADE_ON_CLOSE=0`\n\n### Wisemen 3 Short (wisemen3-short)\n\nRequired env var values:\n\n* `TRADE_ON_CLOSE=0`\n\n### Pengen Opit Long (pengenopit-long)\n\nRequired env var values:\n\n* `TRADE_ON_CLOSE=0`\n\n### Pengen Opit Short (pengenopit-short)\n\nRequired env var values:\n\n* `TRADE_ON_CLOSE=0`\n\n## Env Vars\n\n| Name | Description |\n| :--- | :--- |\n| `API_KEY` | Bitmex API Key, defaults to `*blank*` |\n| `API_SECRET` | Bitmex API Secret, defaults to `*blank*` |\n| `CANDLE_INTERVAL_IN_SECONDS` | Interval to fetch new candles, defaults to `10` |\n| `TF` | Timeframe for candles, defaults to `5m`, valid choices are `1m  5m  1h  1d` |\n| `SYMBOL` | The symbol in Bitmex we're trading for, defaults to `XBTUSD` |\n| `TP_STRATEGY` | Take profit strategy, defaults to `PERCENTAGE`, valid options are `PERCENTAGE PIP OTHERS` |\n| `TP_IN_PERCENTAGE` | Take profit in percentage, defaults to `0.4` |\n| `TP_IN_PIP` | Take profit in pip, defaults to `25.0` |\n| `SL_STRATEGY` | Stop profit strategy, defaults to `PERCENTAGE`, valid options are `PERCENTAGE PIP OTHERS` |\n| `SL_IN_PERCENTAGE` | Stop loss in percentage, defaults to `0.5` |\n| `SL_IN_PIP` | Stop loss in pip, defaults to `25.0` |\n| `USE_TESTNET` | Use testnet or not, defaults to `0`, valid choices are `0  1` |\n| `ORDER_QUANTITY` | Order quantity for each order, defaults to `50` |\n| `MARGIN` | Leverage to be used, defaults to `50` |\n| `STRATEGY` | Strategy to be used, defaults to `nektrabar-short` |\n| `TRADE_ON_CLOSE` | When to trade, defaults to `1`, valid options are `0 1` |\n| `ORDER_RETRIES` | Max retries when order fails to submit, defaults to `3` |\n| `IDEAL_FRACTALS_ONLY` | Only calculate ideal fractals as last fractals, defaults to `0` |\n| `VWMA_SL_BUFFER` | Buffer to be added to VWMA SL when `TRADE_ON_CLOSE=0`, defaults to `0` |\n\n## Running\n\nDocker is recommended.\n\n```shell\n$ docker run -d --name mexjs -e API_KEY=your_api_key -e API_SECRET=your_api_secret -e NAME=name_your_container -e STRATEGY=wisemen3-long -e ORDER_QUANTITY=10000 -e MARGIN=50 -e TF=5m -e TP_STRATEGY=PERCENTAGE -e TP_IN_PERCENTAGE=0.25 -e TP_IN_PIP=25.0 -e SL_STRATEGY=PERCENTAGE -e SL_IN_PERCENTAGE=0.25 -e SL_IN_PIP=25.0 -e VWMA_SL_BUFFER=10.0 -e IDEAL_FRACTALS_ONLY=0 -e USE_TESTNET=0 -e TRADE_ON_CLOSE=0 --restart unless-stopped tistaharahap/mexjs:latest\n```\n\n## Contributors\n\nThank you for the people named here for their contributions.\n\n* [Rifky Ali](https://github.com/rifkyali)\n* [Gungde Yaya](https://github.com/gungde)\n\n### Contributing Codes\n\nPlease follow these guidelines to contribute:\n\n* ES6 strictly unless there's a good reason not to\n* All methods and functions should be documented with [JSDoc](https://devdocs.io/jsdoc/)\n\n### Contributing Something Other Than Codes\n\nYou can always sign up to Bitmex by using the affiliate link below:\n\n[Sign Up to Bitmex](https://www.bitmex.com/register/Xyjltd)\n\nOr send some coins here:\n\n* BTC - `3BMEXqkCzqoGzrw4Y3dTfAzPD9qD9JxAmt`\n\n## License\n\nCopyright (c) \u003c2019\u003e \u003cTradeBro, represented by Batista Harahap\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftistaharahap%2Fmexjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftistaharahap%2Fmexjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftistaharahap%2Fmexjs/lists"}