{"id":13611088,"url":"https://github.com/51bitquant/binance-tradingview-webhook-bot","last_synced_at":"2025-04-13T01:34:34.020Z","repository":{"id":44146287,"uuid":"482133290","full_name":"51bitquant/binance-tradingview-webhook-bot","owner":"51bitquant","description":"A tradingview webhook trading bot for Binance Exchange.","archived":false,"fork":false,"pushed_at":"2023-04-28T02:46:03.000Z","size":64,"stargazers_count":89,"open_issues_count":1,"forks_count":54,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-08-01T19:56:29.983Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/51bitquant.png","metadata":{"files":{"readme":"README-Chinese.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-04-16T02:16:58.000Z","updated_at":"2024-07-18T16:47:29.000Z","dependencies_parsed_at":"2024-01-16T23:30:37.575Z","dependency_job_id":"ab53b173-adf0-4a1e-971c-968b6e37c6d4","html_url":"https://github.com/51bitquant/binance-tradingview-webhook-bot","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/51bitquant%2Fbinance-tradingview-webhook-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/51bitquant%2Fbinance-tradingview-webhook-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/51bitquant%2Fbinance-tradingview-webhook-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/51bitquant%2Fbinance-tradingview-webhook-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/51bitquant","download_url":"https://codeload.github.com/51bitquant/binance-tradingview-webhook-bot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223558537,"owners_count":17165143,"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":[],"created_at":"2024-08-01T19:01:51.669Z","updated_at":"2024-11-07T17:31:20.104Z","avatar_url":"https://github.com/51bitquant.png","language":"Python","readme":"# binance-tradingview-webhook-bot\n\n[English Docs](README.md) \n\n币安Tradingview Webhook交易机器人,\n通过简单的配置可以实现tradingview发送的信号进行交易。目前支持在币安现货和合约的交易信号。但是现货的需要你处理交易的下单逻辑。可以参考合约的下单方式。\n\n如果你想在tradingview\nwebhoook里面使用算法交易来降低成本或者滑点，可以考虑使用[howtrader](https://github.com/51bitquant/howtrader),\n里面内置了一些算法交易，同时更容易扩展你的交易信号。\n\n# 如何使用\n\n## 1. 购买服务器、域名和安装nginx软件\n如果你还没有服务器，可以购买一个服务器和域名，并把你的域名解析到当前服务器ip地址.\n\n**服务器推荐**：[https://www.ucloud.cn/site/active/kuaijie.html?invitation_code=C1x2EA81CD79B8C#dongjing](https://www.ucloud.cn/site/active/kuaijie.html?invitation_code=C1x2EA81CD79B8C#dongjing)\n\n完成上一步之后，你还需要安装nginx软件。window用户可以从这个网站下载[https://nginx.org/en/download.html](https://nginx.org/en/download.html)，对于macOS系统,\n你可以在终端输入一下命令安装:\n\n\u003e brew install nginx\n\n其他有用的命令如下:\n\n\u003e brew services start nginx \n\n\u003e brew services restart nginx\n\n\u003e brew services reload nginx\n\n如果提示你没有brew, 那么你需要安装下homebrew, 具体百度或者谷歌一下。\n\n对于window系统，你可以从以下链接下载nginx:\nhttps://nginx.org/en/download.html, 然后解压到指定目录. 然后启动它:\n\n\u003e start nginx.exe\n\n其他有用的命令如下:\n\n\u003e nginx.exe -s stop\n\n\u003e nginx.exe -s quit\n\n\u003e nginx.exe -s stop\n\n\u003e nginx.exe -s reload (reload)\n\n\n另外你还需要编辑下nginx.cong文件,该文件只要是配置你的nginx进行端口转发。由于tradingview只能用80端口，所以你需要为你的web服务器进行端口转发。\n在http里面添加如下配置信息：\n\n```\nserver {\n        listen 80;\n        server_name your.dormain.com;\n        charset utf-8;\n\n        location / {\n          proxy_pass http://localhost:8888;\n        }\n\n    }\n\n```\n\nserver_name 可以填写字符串或者你的ip地址都可以的， 比如： server_name\nxxx.xxx.xxx.xxx;\n\n修改nginx.conf后需要重启nginx 或者重新加载，你的配置才会生效， 最后运行main.py。\n\n## 创建webhook信号提醒\n\n 创建webhook提醒的时候，勾选Webhook Url 选项,\n 然后把你webhook的链接粘贴进去，例如: http://www.your.domain/webhook,\n 消息体格式如下\n\n```\n{\"action\": \"{{strategy.order.comment}}\",\n  \"symbol\": \"ETHUSDT\",\n\"exchange\": \"binance_future\",\n\"price\":\"{{strategy.order.price}}\",\n\"close\": \"{{close}}\",\n\"passphrase\": \"your customized password for safety.\",\n\"strategy_name\": \"ETHUSDT_5min\",\n\"some other key\": \"some other value you need\"\n}\n\n```\n需要注意的是，你的strategy_name的值，要跟你在config.py文件中的strategies里面的key要对应起来。\n不然它找不到你对应的策略的配置参数。另外在你的策略中，你订单的comment要填写成如下格式:\n\n```\n\nstrategy.entry('L', strategy.long, comment=\"long\")\nstrategy.entry('S', strategy.short, comment=\"short\")\nstrategy.exit('tp', comment=\"exit\")\n\n\n```\n\n## 如何运行代码\n\n1. 下载代码并解压它\n\n2. 创建一个 python 解析器， 推荐使用 anaconda, 这里演示用 anaconda\n   创建一个名为 mytrader, python版本为3.9 python解析器: \n   \u003e create -n mytrader python==3.9\n   \n   接下来激活它：\n   \n   \u003e conda activate mytrader\n \n  \n3. 进入你的代码，并安装依赖：\n    \n   \u003e  pip install -r requirements.txt\n\n4. 修改配置文件\n\n   编辑config.py文件, 设置的apikey, passphrase 还有策略信息\n   \n\n5. 运行代码： 如果是在本地电脑可以直接在终端输入：python main.py,\n  或者在pycharm中直接运行，但是记得为代码配置为刚才创建的python解析器。具体的配置可以参考[网易云课堂的视频](https://study.163.com/course/courseMain.htm?courseId=1209509824\u0026share=2\u0026shareId=480000001919830)\n   \n8. 服务器运行\n   \n   在服务器端运行，如果是在linux服务器，可以用守护进程的方式运行：\n    \n   \u003e nohup python -u main.py \u003e nohup_log.out 2\u003e\u00261 \u0026\n   \n   当然你可以通过shell命令来执行代码中的start.sh 文件。\n   \n   如果需要购买服务器，这里推荐ucloud, 新用户优惠比较大，链接如下:\n   [https://passport.ucloud.cn/?invitation_code=C1x2EA81CD79B8C](https://passport.ucloud.cn/?invitation_code=C1x2EA81CD79B8C)\n\n\n程序中，采用市价单的方式下单，主要是为了保证及时成交。如果你是跑BTCUSDT,\nETHUSDT等流动性好的品种，那么其滑点是比较小的。如果你想用挂单的方式，支持限价单和市价单。你如果想下做市单，可以把订单类型order_type=OrderType.Maker即可。\n如果想下限价单，把下单的参数order_type设置为OrderType.LIMIT。 \n\nmaker单: maker order\n``` python \nstatus, order = binance_future_client.place_order(\n                symbol=symbol,\n                order_side=OrderSide.BUY,\n                order_type=OrderType.MAKER,\n                quantity=Decimal(vol1),\n                price=Decimal(price),\n                client_order_id=order_id\n            )\n\n```\n\n限价单： limit order\n``` python \nstatus, order = binance_future_client.place_order(\n                symbol=symbol,\n                order_side=OrderSide.BUY,\n                order_type=OrderType.LIMIT,\n                quantity=Decimal(vol1),\n                price=Decimal(price),\n                client_order_id=order_id\n            )\n\n```\n\n你可以在同一个交易对下面，交易不同的策略，这就通过strategy_name来实现的。strategy_name是策略的名称，他们的持仓是根据策略的名称来识别的。\n策略A的持仓和策略B不会关联，他们管理好他们的持仓即可。\n\n最后祝老板发财。\n\n# 联系方式\n\n微信: bitquant51 \n\ndiscord: 51bitquant#8078\n\n如果使用中遇到任何问题，可以咨询我。","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F51bitquant%2Fbinance-tradingview-webhook-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F51bitquant%2Fbinance-tradingview-webhook-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F51bitquant%2Fbinance-tradingview-webhook-bot/lists"}