{"id":19188721,"url":"https://github.com/theexplainthis/chatgpt-trading-bot","last_synced_at":"2026-01-28T14:05:15.554Z","repository":{"id":138126546,"uuid":"607957886","full_name":"TheExplainthis/ChatGPT-Trading-Bot","owner":"TheExplainthis","description":"This repository will teach you how to use ChatGPT to implement trading code and automate trading.","archived":false,"fork":false,"pushed_at":"2023-03-18T04:35:18.000Z","size":1216,"stargazers_count":140,"open_issues_count":2,"forks_count":77,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-20T20:51:37.110Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","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/TheExplainthis.png","metadata":{"files":{"readme":"README.en.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":"2023-03-01T02:34:20.000Z","updated_at":"2025-08-16T20:30:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"401274b7-d928-41d2-9918-d657424b90e5","html_url":"https://github.com/TheExplainthis/ChatGPT-Trading-Bot","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/TheExplainthis/ChatGPT-Trading-Bot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheExplainthis%2FChatGPT-Trading-Bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheExplainthis%2FChatGPT-Trading-Bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheExplainthis%2FChatGPT-Trading-Bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheExplainthis%2FChatGPT-Trading-Bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheExplainthis","download_url":"https://codeload.github.com/TheExplainthis/ChatGPT-Trading-Bot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheExplainthis%2FChatGPT-Trading-Bot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28846058,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T13:02:32.985Z","status":"ssl_error","status_checked_at":"2026-01-28T13:02:04.945Z","response_time":57,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-11-09T11:25:47.613Z","updated_at":"2026-01-28T14:05:15.534Z","avatar_url":"https://github.com/TheExplainthis.png","language":"Python","funding_links":["https://www.buymeacoffee.com/explainthis"],"categories":[],"sub_categories":[],"readme":"# ChatGPT Trading Bot\n\n[中文](README.md) | English\n\n[![license](https://img.shields.io/pypi/l/ansicolortags.svg)](LICENSE) [![Release](https://img.shields.io/github/v/release/TheExplainthis/ChatGPT-Trading-Bot)](https://github.com/TheExplainthis/ChatGPT-Trading-Bot/releases/)\n\n\n![Demo](https://github.com/TheExplainthis/ChatGPT-Trading-Bot/blob/main/demo/demo0.png)\n\nThis repository teaches you how to use ChatGPT to help you write trading programs and deploy the code to Heroku to achieve automated trading. The exchange used for this article is Binance, but if you have other trading platforms, you can connect them yourself.\n\n## ChatGPT Training Method\n\n1. First, I asked NotionAI to come up with ten possible trading strategies for me, as follows:\n    - A momentum trading strategy based on price and volume data\n    - A mean reversion strategy using Bollinger Bands and RSI indicators\n    - A trend following strategy using moving averages and MACD indicator\n    - A breakout trading strategy based on support and resistance levels\n    - A pairs trading strategy using cointegration analysis\n    - A news-based trading strategy using sentiment analysis on financial news\n    - An arbitrage trading strategy using cross-market analysis\n    - A swing trading strategy using candlestick patterns and chart analysis\n    - A quantitative trading strategy based on statistical models and machine learning algorithms\n    - A position trading strategy using fundamental analysis and value investing principles\n2. Tell ChatGPT like this: `Give me pipescript code with version 4 running on TradingView for {trading strategy}`, so an example is as follows:\n    ```\n    Give me pipescript code with version 4 running on TradingView for A momentum trading strategy based on price and volume data.\n    ```\n3. Copy the ChatGPT code, some parts need to be adjusted\n    - For the second line of the code, sometimes ChatGPT will give you `study` and you need to change it to `strategy`.\n    - Sometimes for the entry/exit code, he will give you the following code, which needs to be modified to trigger during backtesting:\n        ```python\n        if buy_signal\n            alert(\"Buy Signal\")\n        if sell_signal\n            alert(\"Sell Signal\")\n        ```\n    - Modify it to the following code:\n        ```python\n        if buy_signal\n            strategy.entry(\"Buy\", strategy.long)\n        if sell_signal\n            strategy.entry(\"Sell\", strategy.short)\n        ```\n    - Add the parameter `alert_message` after Buy, Sell, Buy Exit, and Sell Exit, so that the subsequent Notification setup won't go wrong.\n        ```python\n        if long_bb and long_ma and macd_above_signal and time \u003e= start_time\n            strategy.entry(\"Buy\", strategy.long, alert_message=\"Buy\")\n        if short_bb and short_ma and macd_below_signal and time \u003e= start_time\n            strategy.entry(\"Sell\", strategy.short, alert_message=\"Sell\")\n\n        if exit_bb or exit_ma\n            strategy.exit('Buy Exit', 'Buy', alert_message=\"Buy_Exit\")\n            strategy.exit('Sell Exit', 'Sell', alert_message=\"Sell_Exit\")\n\n        ```\n    \u003e Note: Sometimes the code provided by ChatGPT may not work, so you can ask him multiple times or provide him with the error message.\n4. Adjust the parameters to get the best results, as shown in the figure below:\n\n![Demo](https://github.com/TheExplainthis/ChatGPT-Trading-Bot/blob/main/demo/demo1.png)\n\n\n## Automated Installation Steps\n### Token Acquisition\n1. Log in to [Binance](https://www.binance.com/en)\n2. On the left side after logging in, there is an `API Management` option. Click on it and then click `Create` in the upper right corner.\n3. You will then receive an `API Key` and `Secret Key`.\n\n### Project Setup\n1. Fork Github repository:\n    1. Register/Login to [GitHub](https://github.com/).\n    2. Go to [ChatGPT-Trading-Bot](https://github.com/TheExplainthis/ChatGPT-Trading-Bot).\n    3. Click `Star` to support the developer.\n    4. Click `Fork` to copy all the code to your own repository.\n2. Space deployment registration (free space):\n    1. Register/Login to [Heroku](https://www.heroku.com/).\n    2. In the upper right corner, click `New` -\u003e `Create new app`.\n    3. App Name: `Enter the App name`, `Region`: `Europe`.\n    4. Click `Create app`.\n\n### Project Execution\n1. Environment Variable Configuration\n    1. Click on `Settings` -\u003e `Reveal Config Vars`\n    2. Add environment variables, that include:\n        1. API Key：\n            - key: `API_KEY`\n            - value: `[obtained from step one above]`\n        2. API SECRET KEY：\n            - key: `API_SECRET_KEY`\n            - value: `[obtained from step one above]`\n        3. PASSPHRASE -\u003e Used as a Token when TradingView sends a Request to the Server to avoid making the API available to everyone.\n            - key: `PASSPHRASE`\n            - value: `User-generated, will be used in step four`\n2. Deployment Steps\n    1. Enter the folder where `ChatGPT-Trading-Bot` is located using the Terminal\n    2. Check if the folder is the same as the following with `ls`\n        ```\n        Procfile\n        demo\n        src\n        main.py\n        runtime.txt\n        README.md\n        README.en.md\n        requirements.txt \n        ```\n    3. Install [Heroku cli](https://devcenter.heroku.com/articles/heroku-cli#install-the-heroku-cli)\n    4. Deploy, refer to the process in the Deploy page below\n        - Log in to Heroku, enter in the Terminal:\n            ```\n            $ heroku login\n            ```\n        - Add location, enter in the Terminal:\n            ```\n            $ heroku git:remote -a [Your App Name]\n            ```\n    5. Push the repo to Heroku, enter in the Terminal:\n        ```\n        $ git push heroku main\n        ```\n    6. After successful deployment, your URL will be in `Settings` -\u003e `Domains`\n    7. After clicking the link, you will see `Hello, World!`\n    8. Enter `heroku logs --tail` in the Terminal and find the location of \"My IP\". Copy the IP address.\n        For example:\n        ```\n        2023-03-05T13:38:36.171417+00:00 app[web.1]: My IP: 54.78.178.135\n        ```\n    9. Go back to [Binance](https://www.binance.com/en), click `Edit restrictions ` for the Token you just created -\u003e check `Restrict access to trusted IPs only (Recommended)` under `IP access restrictions` -\u003e add the IP from the previous step. \n    10. Check the box for `Enable Futures` at the top.\n    11. Click `Save`\n3. CronJob Scheduled Request Sending\n    1. Register/Login to [cron-job.org](https://cron-job.org/en/)\n    2. Choose `CREATE CRONJOB` in the right upper corner of the backend\n    3. Enter `ChatGPT-Trading-Bot` in `Title`, and enter the URL from the previous step.\n    4. Below, send every `5 minutes`\n    5. Click `CREATE`\n4. Trading View Alert Configuration\n    1. In TradingView's `Strategy Tester`, select your strategy, and click on the bell icon\n    2. In `Settings`, enter the message below:\n        ```json\n        {\n        \"passphrase\": \"PASSPHRASE used during setup\",\n        \"symbol\": \"Cryptocurrency to trade\",\n        \"leverage\": Leverage amount,\n        \"quantity\": Quantity to trade,\n        \"time\": \"{{time}}\",\n        \"close\": {{close}},\n        \"message\": {{strategy.order.alert_message}}\n        }\n        ```\n        For example:\n        ```json\n        {\n        \"passphrase\": \"Zw'4Tx^5/]f/pN\u003e}fx*9m6\u003cX,fxLx;x(\",\n        \"symbol\": \"BTCUSDT\",\n        \"leverage\": 10,\n        \"quantity\": 0.002,\n        \"time\": \"{{time}}\",\n        \"close\": {{close}},\n        \"message\": {{strategy.order.alert_message}}\n        }\n        ```\n        \u003e Explanation: Contract trading set `BTCUSDT` trading pair leverage to `10` times, quantity `0.002` BTC.\n    3. Notifications Configuration\n        1. Webhook URL setting: The URL in Heroku (`Settings` -\u003e `Domains`) + `/webhook`\n        - Example\n            ```\n            https://chatgpt-trading-bot.herokuapp.com/webhook\n            ```\n\n## Support Us\nLike this free project? Please consider [supporting us](https://www.buymeacoffee.com/explainthis) to keep it running.\n\n[\u003ca href=\"https://www.buymeacoffee.com/explainthis\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png\" height=\"45px\" width=\"162px\" alt=\"Buy Me A Coffee\"\u003e\u003c/a\u003e](https://www.buymeacoffee.com/explainthis)\n\n## License\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheexplainthis%2Fchatgpt-trading-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheexplainthis%2Fchatgpt-trading-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheexplainthis%2Fchatgpt-trading-bot/lists"}