{"id":13504344,"url":"https://github.com/Haehnchen/crypto-trading-bot","last_synced_at":"2025-03-29T21:30:32.772Z","repository":{"id":37390977,"uuid":"150290884","full_name":"Haehnchen/crypto-trading-bot","owner":"Haehnchen","description":"Cryptocurrency trading bot in javascript for Bitfinex, Bitmex, Binance, Bybit ... (public edition)","archived":false,"fork":false,"pushed_at":"2024-10-03T08:14:22.000Z","size":4669,"stargazers_count":3266,"open_issues_count":114,"forks_count":1005,"subscribers_count":186,"default_branch":"master","last_synced_at":"2025-03-27T06:01:40.366Z","etag":null,"topics":["binance","bitfinex","bitmex","bot","bybit","ccxt","coinbase","crypto","cryptocurrency","docker","exchange","javascript","margin","nodejs","trading","trading-bot","trading-strategies","tradingview","websocket"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/Haehnchen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2018-09-25T15:48:11.000Z","updated_at":"2025-03-26T08:38:15.000Z","dependencies_parsed_at":"2024-12-11T15:00:31.963Z","dependency_job_id":"c5a5d0fb-878c-4a73-9fa8-2f5f1eab091c","html_url":"https://github.com/Haehnchen/crypto-trading-bot","commit_stats":{"total_commits":820,"total_committers":17,"mean_commits":48.23529411764706,"dds":"0.15487804878048783","last_synced_commit":"a5d92b153c6cbe8770a28c693309640bb30cfea1"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Haehnchen%2Fcrypto-trading-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Haehnchen%2Fcrypto-trading-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Haehnchen%2Fcrypto-trading-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Haehnchen%2Fcrypto-trading-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Haehnchen","download_url":"https://codeload.github.com/Haehnchen/crypto-trading-bot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246249116,"owners_count":20747164,"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":["binance","bitfinex","bitmex","bot","bybit","ccxt","coinbase","crypto","cryptocurrency","docker","exchange","javascript","margin","nodejs","trading","trading-bot","trading-strategies","tradingview","websocket"],"created_at":"2024-08-01T00:00:32.686Z","updated_at":"2025-03-29T21:30:32.751Z","avatar_url":"https://github.com/Haehnchen.png","language":"JavaScript","funding_links":[],"categories":["Trading Bots","JavaScript","Uncategorized","Open source bots","Just for fun","Trading Bots and Bot Frameworks","TypeScript","⚙️ Backend \u0026 APIs"],"sub_categories":["Crypto Trading","Uncategorized","Flutter SDK / Libraries","Derivative Exchanges"],"readme":"# Crypto Trading Bot\n\n[![Build Status](https://github.com/Haehnchen/crypto-trading-bot/actions/workflows/node.js.yml/badge.svg)](https://github.com/Haehnchen/crypto-trading-bot/actions/workflows/node.js.yml)\n\nA **work in progress** Cryptocurrency for common exchanges like Bitfinex, Bitmex and Binance.\nAs most trading bots just provide basic buy and sell signals they provide many stuff to get profitable eg exchange orders like stop-losses or stop-limits are not supported by main bots. Also the limitation of fixed timeframe and technical indicators must be broken\n\n**Not production ready** only basic functionality\n\n## Features\n\n- Fully use Websocket for exchange communication to react as fast as possible on market\n- Multi pair support in one instance\n- sqlite3 storage for candles, tickers, ...\n- Webserver UI\n- Support for going \"Short\" and \"Long\"\n- Signal browser dashboard for pairs\n- Slack and email notification\n- Join foreign exchange candles (eg. Trade on Bitmex with the faster moving Binance trades / candles)\n\n### Exchanges\n\n- [Bitmex](https://www.bitmex.com/register/jS4mLN) with leverage configuration\n- [Bitmex Testnet](https://www.bitmex.com/register/jS4mLN)\n- [Binance](https://www.binance.com/?ref=17569916)\n- [Binance Margin](https://www.binance.com/?ref=17569916)\n- [Binance Futures](https://www.binance.com/en/futures/ref/302644)\n- [Coinbase Pro](https://www.coinbase.com/join/5a2ae60e76531100d3af2ee5)\n- [Bitfinex](https://www.bitfinex.com/?refcode=kDLceRHa) (margin wallet)\n- [Bybit](https://www.bybit.com/app/register?ref=46AK7)\n  - [USDT Perpetual Futures (v2) APIs](https://bybit-exchange.github.io/docs/futuresV2/linear/#t-introduction)\n  - [Inverse Perpetual Futures (v2) APIs](https://bybit-exchange.github.io/docs/futuresV2/inverse/#t-introduction) \n  \nTODOS:\n\n- [Huobi Global](https://www.hbg.com/) (margin)\n\n## Technical stuff and packages\n\n- node.js\n- sqlite3\n- [technicalindicators](https://github.com/anandanand84/technicalindicators)\n- [tulipindicators - tulind](https://tulipindicators.org/list)\n- [TA-Lib](https://mrjbq7.github.io/ta-lib/)\n- twig\n- express\n- Bootstrap v4\n- Tradingview widgets\n\n## How to use\n\n### [optional] Preinstall\n\nThe tulip library is used for indicators; which sometimes is having some issues on `npm install` because of code compiling:\n\nInstall build tools\n\n```\nsudo apt-get install build-essential\n```\n\nThe nodejs wrapper for tulipindicators is called [Tulip Node (tuind)](https://www.npmjs.com/package/tulind), check out installation instructions there.\n\nAlso the build from source is not supporting all nodejs version. It looks like versions \u003c= 10 are working. You can use nodejs 12 if you compiled it once via older version.\n\n### Install packages\n\n```\n➜ npm install --production\n➜ npm run postinstall\n```\n\nCreate instance file for pairs and changes\n\n```\ncp instance.js.dist instance.js\n```\n\nProvide a configuration with your exchange credentials\n\n```\ncp conf.json.dist conf.json\n```\n\nCreate a new sqlite database use bot.sql scheme to create the tables\n\n```\nsqlite3 bot.db \u003c bot.sql\n```\n\nLets start it\n\n```\nnpm start\n```\n\n## How to use: Docker\n\nFor initialize the configuration once\n\n```\n➜ cp instance.js.dist instance.js \u0026\u0026 cp conf.json.dist conf.json \u0026\u0026 sqlite3 bot.db \u003c bot.sql\n➜ docker-compose build\n➜ docker-compose up -d\n```\n\nAfter this you can use `docker-compose` which will give you a running bot via \u003chttp://127.0.0.1:8080\u003e\n\n## Setting Up Telegram Bot\n\nFirst, you'll need to create a bot for Telegram. Just talk to [BotFather](https://telegram.me/botfather) and follow simple steps until it gives you a token for it.\nYou'll also need to create a Telegram group, the place where you and crypto-trading-bot will communicate. After creating it, add the bot as administrator (make sure to uncheck \"All Members Are Admins\").\n\n### Retrieving Chat IDs\n\nInvite `@RawDataBot` to your group and get your group id in sended chat id field\n\n```text\nMessage\n ├ message_id: 338\n ├ from\n ┊  ├ id: *****\n ┊  ├ is_bot: false\n ┊  ├ first_name: 사이드\n ┊  ├ username: ******\n ┊  └ language_code: en\n ├ chat\n ┊  ├ id: -1001118554477\n ┊  ├ title: Test Group\n ┊  └ type: supergroup\n ├ date: 1544948900\n └ text: A\n```\n\nLook for id: -1001118554477 is your chat id (with the negative sign).\n\n### Log messages to Telegram\n\nFor example setup, check `conf.json.dist file`, log.telegram section , set chatId, token, level (default is info). Check more options https://github.com/ivanmarban/winston-telegram#readme\n\n## Webserver\n\nSome browser links\n\n- UI: http://127.0.0.1:8080\n- Signals: http://127.0.0.1:8080/signals\n- Tradingview: http://127.0.0.1:8080/tradingview/BTCUSD\n- Backtesting: http://127.0.0.1:8080/backtest\n- Order \u0026 Pair Management: http://127.0.0.1:8080/pairs\n\n### Security / Authentication\n\nAs the webserver provides just basic auth for access you should combine some with eh a https for public server. Here s simple `proxy_pass` for nginx.\n\n```\n# /etc/nginx/sites-available/YOURHOST\nserver {\n    server_name YOURHOST;\n\n    location / {\n        proxy_pass http://127.0.0.1:8080;\n    }\n\n    listen 443 ssl; # managed by Certbot\n    ssl_certificate /etc/letsencrypt/live/YOURHOST/fullchain.pem; # managed by Certbot\n    ssl_certificate_key /etc/letsencrypt/live/YOURHOST/privkey.pem; # managed by Certbot\n    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot\n    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot\n}\n\n```\n\nYou should also set the listen ip to a local one\n\n```\n# config.json\nwebserver.ip: 127.0.0.1\n\n```\n\n## Web UI\n\n### Dashboard\n\n![Webserver UI](documentation/cryptobot.png 'Webserver UI')\n\n### Trades / Positions / Orders\n\n![Webserver UI](documentation/trades.png 'Trades / Positions / Orders')\n\n### Backtesting\n\nCurrently there is a the UI for backtesting\n\n![Webserver UI](documentation/backtest_result.png 'Backtest Result')\n\n### Manual Orders\n\n![Webserver UI](documentation/manual_order.png 'Manual Orders')\n\n## Build In Strategies\n\nCommon strategy with indicators are inside, which most of the time are not profitable. See some more advanced strategy in the list below\n\n- [dip_catcher](src/modules/strategy/strategies/dip_catcher/README.md)\n- [dca_dipper](src/modules/strategy/strategies/dca_dipper/README.md) - **Long term invest** Dollar-Cost Averaging (DCA) Dip Investor Strategy\n\nFind some example strategies inside [src/modules/strategy/strategies](src/modules/strategy/strategies)\n\n## Custom Strategies\n\nFor custom strategies use [var/strategies](var/strategies) folder.\n\n```\n# simple file structure\nvar/strategies/your_strategy.js\n\n# or wrap strategy into any sub folder depth\nvar/strategies/my_strategy/my_strategy.js\nvar/strategies/subfolder1/our_strategy/our_strategy.js\n```\n\n## Tools / Watchdog\n\n- `order_adjust` Keep open orders in bid / ask of the orderbook in first position\n\n### Watchdog\n\n- `stoploss` provide general stoploss order in percent of entry price (Exchange Order)\n- `risk_reward_ratio` Creates Risk Reward order for take profit and stoploss (Exchange Order Limit+Stop)\n- `stoploss_watch` Close open position if ticker price falls below the percent lose; use this for exchange that dont support stop_loss order liek Binance\n- `trailing_stop` Use native exchange trailing stop; if supported by exchange eg `Bitfinex`\n\n```\n    'watchdogs': [\n        {\n            'name': 'stoploss',\n            'percent': 3,\n        },\n        {\n            'name': 'risk_reward_ratio',\n            'target_percent': 6,\n            'stop_percent': 3,\n        },\n        {\n            'name': 'stoploss_watch',\n            'stop': 1.2,\n        },\n        {\n            'name': 'trailing_stop',\n            'target_percent': 1.2,\n            'stop_percent': 0.5\n        }\n    ],\n```\n\n### Tick Interval\n\nPer default every strategy is \"ticked\" every full minute with a ~10sec time window. If you want to tick every 15 minutes or less see possible examples below.\n\nSupported units are \"m\" (minute) and \"s\" (seconds)\n\n```json\n{\n  \"strategies\": [\n    {\n      \"strategy\": \"cci\",\n      \"interval\": \"15m\"\n    },\n    {\n      \"strategy\": \"cci2\",\n      \"interval\": \"30s\"\n    },\n    {\n      \"strategy\": \"cci3\",\n      \"interval\": \"60m\"\n    }\n  ]\n}\n```\n\n## Trading\n\n### Capital\n\nTo allow the bot to trade you need to give some \"playing capital\". You can allow to by via asset or currency amount, see examples below.\nYou should only provide one of them, first wins.\n\n```\n    c.symbols.push({\n        'symbol': 'BTC-EUR',\n        'exchange': 'coinbase_pro',\n        'trade': {\n            'capital': 0.015, // this will buy 0.015 BTC\n            'currency_capital': 50,  // this will use 50 EUR and buys the equal amount of BTC (example: BTC price 3000 use 50 EUR. will result in 0.016 BTC)\n            'balance_percent': 75,  // this will use 75 % of your exchange margin tradable balance. Currently implemented only on Bitfinex exchange.\n        },\n    })\n```\n\n### Live Strategy\n\nEvery strategy stat should be live must be places inside `trade`.\n\n```json\n{\n  \"trade\": {\n    \"strategies\": [\n      {\n        \"strategy\": \"dip_catcher\",\n        \"interval\": \"15m\",\n        \"options\": {\n          \"period\": \"15m\"\n        }\n      }\n    ]\n  }\n}\n```\n\nInside logs, visible via browser ui, you can double check the strategies init process after the application started.\n\n```\n[info] Starting strategy intervals\n[info] \"binance_futures\" - \"ETHUSDT\" - \"trade\" - init strategy \"dip_catcher\" (15m) in 11.628 minutes\n[info] \"binance_futures\" - \"BTCUSDT\" - \"trade\" first strategy run \"dip_catcher\" now every 15.00 minutes\n```\n\n### Full Trade Example\n\nAn example `instance.js` which trades can be found inside `instance.js.dist_trade`. Rename it or move the content to you file.\n\n```js\nconst c = (module.exports = {});\n\nc.symbols = [\n  {\n    symbol: 'ETHUSDT',\n    exchange: 'binance_futures',\n    periods: ['1m', '15m', '1h'],\n    trade: {\n      currency_capital: 10,\n      strategies: [\n        {\n          strategy: 'dip_catcher',\n          interval: '15m',\n          options: {\n            period: '15m'\n          }\n        }\n      ]\n    },\n    watchdogs: [\n      {\n        name: 'risk_reward_ratio',\n        target_percent: 3.1,\n        stop_percent: 2.1\n      }\n    ]\n  }\n];\n```\n\n### Margin / Leverage\n\nPer pair you can set used margin before orders are created; depending on exchange\n\n```\n    c.symbols.push({\n        'symbol': 'BTCUSD',\n        'exchange': 'bitmex',\n        'extra': {\n            'bitmex_leverage': 5,\n        },\n    })\n\n    c.symbols.push({\n        'symbol': 'EOSUSD',\n        'exchange': 'bybit',\n        'extra': {\n            'bybit_leverage': 5,\n        },\n    })\n```\n\n## Tools\n\n### Fill data\n\n_outdated_, but there as an automatic filling on startup ~1000 candles from the past (depending on exchange) and continuously fetched when running\n\n```\nnode index.js backfill -e bitmex -p 1m -s XRPZ18\n```\n\n## Signals\n\n### Slack\n\n![Webserver UI](documentation/slack_signals.png 'Slack signals')\n\n## Tests\n\n```\nnpm test\n```\n\n## Related Links\n\n### Trading Bots Inspiration\n\nOther bots with possible design pattern\n\n- https://github.com/DeviaVir/zenbot\n- https://github.com/magic8bot/magic8bot\n- https://github.com/askmike/gekko\n- https://github.com/freqtrade/freqtrade\n- https://github.com/Ekliptor/WolfBot\n- https://github.com/andresilvasantos/bitprophet\n- https://github.com/kavehs87/PHPTradingBot\n- https://github.com/Superalgos/Superalgos\n\n### Strategies\n\nSome strategies based on technical indicators for collection some ideas\n\n- https://github.com/freqtrade/freqtrade-strategies\n- https://github.com/freqtrade/freqtrade-strategies/tree/master/user_data/strategies/berlinguyinca\n- https://github.com/xFFFFF/Gekko-Strategies\n- https://github.com/sthewissen/Mynt/tree/master/src/Mynt.Core/Strategies\n- https://github.com/Ekliptor/WolfBot/tree/master/src/Strategies\n- https://github.com/Superalgos/Strategy-BTC-WeakHandsBuster\n- https://github.com/Superalgos/Strategy-BTC-BB-Top-Bounce\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHaehnchen%2Fcrypto-trading-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FHaehnchen%2Fcrypto-trading-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHaehnchen%2Fcrypto-trading-bot/lists"}