Giter VIP home page Giter VIP logo

robswc / tradingview-webhooks-bot Goto Github PK

View Code? Open in Web Editor NEW
562.0 41.0 175.0 13.18 MB

a framework 🏗 for trading with tradingview webhooks!

Home Page: http://tvwb.robswc.me

License: GNU General Public License v3.0

Python 64.51% CSS 1.18% JavaScript 5.42% HTML 28.68% Dockerfile 0.23%
tradingview webhooks trading bot trading-bot alerts cryptocurrency framework python flask webhook json discord tradingview-webhooks-bot

tradingview-webhooks-bot's Introduction

demopic

tvwb_demo.webm

📀 Live Demo 🖥

There's now a live demo available at http://tvwb.robswc.me.
Feel free to check it out or send it some webhooks!

DigitalOcean Referral Badge

The What 🔬

Tradingview-webhooks-bot (TVWB) is a small, Python-based framework that allows you to extend or implement your own logic using data from Tradingview's webhooks. TVWB is not a trading library, it's a framework for building your own trading logic.

The How 🏗

TVWB is fundamentally a set of components with a webapp serving as the GUI. TVWB was built with event-driven architecture in mind that provides you with the building blocks to extend or implement your own custom logic. TVWB uses Flask to handle the webhooks and provides you with a simple API to interact with the data.

Quickstart 📘

Docker compose command

docker-compose run app start

Installation

Hosting


Ensure you're in the src directory. When running the following commands, if you installed manually.
If you used docker, start the tvwb.py shell with docker-compose run app shell (in the project root directory) and omit the python3 tvwb.py portion of the commands.


Creating an action

python3 tvwb.py action:create NewAction --register

This creates an action and automatically registers it with the app. Learn more on registering here.

Note, action and event names should always be in PascalCase.

You can also check out some "pre-made" community actions!

Linking an action to an event

python3 tvwb.py action:link NewAction WebhookReceived

This links an action to the WebhookReceived event. The WebhookReceived event is fired when a webhook is received by the app and is currently the only default event.

Editing an action

Navigate to src/components/actions/NewAction.py and edit the run method. You will see something similar to the following code. Feel free to delete the "Custom run method" comment and replace it with your own logic. Below is an example of how you can access the webhook data.

class NewAction(Action):
    def __init__(self):
        super().__init__()

    def run(self, *args, **kwargs):
        super().run(*args, **kwargs)  # this is required
        """
        Custom run method. Add your custom logic here.
        """
        data = self.validate_data()  # always get data from webhook by calling this method!
        print('Data from webhook:', data)

Running the app

python3 tvwb.py start

Sending a webhook

Navigate to http://localhost:5000. Ensure you see the WebhookReceived Event. Click "details" to expand the event box. Find the "Key" field and note the value. This is the key you will use to send a webhook to the app. Copy the JSON data below, replacing "YOUR_KEY_HERE" with the key you copied.

{
    "key": "YOUR_KEY_HERE",
    "message": "I'm a webhook!"
}

The key field is required, as it both authenticates the webhook and tells the app which event to fire. Besides that, you can send any data you want. The data will be available to your action via the validate_data() method. (see above, editing action)

On tradingview, create a new webhook with the above JSON data and send it to http://ipaddr:5000/webhook. You should see the data from the webhook printed to the console.

FAQs

So how do I actually trade?

To actually submit trades, you will have to use a library like ccxt for crypto currency. For other brokers, usually there are SDKs or APIs available. The general workflow would look something like: webhook signal -> tvwb (use ccxt here) -> broker. Your trade submission would take place within the run method of a custom action.

The tvwb.py shell

You can use the tvwb.py shell command to open a python shell with the app context. This allows you to interact with the app without having to enter python3 tvwb.py every time.

Running Docker on Windows/Mac?

Thanks to @khamarr3524 for pointing out there are some docker differences when running on Windows or Mac. I've added OS-specific docker-compose.yml files to accomodate these differences. One should be able to run their respective OS's docker-compose.yml file without issue now!

How do I get more help?

At the moment, the wiki is under construction. However, you may still find some good info on there. For additional assistance you can DM me on Twitter or join the Discord. I will try my best to get back to you!

tradingview-webhooks-bot's People

Contributors

dependabot[bot] avatar khamarr3524 avatar lpx55 avatar robswc avatar zahidhussaina2l avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tradingview-webhooks-bot's Issues

what ı did wrong

                                                                                                                                                       ^

SyntaxError: unexpected EOF while parsing
127.0.0.1 - - [10/May/2020 19:24:59] "�[35m�[1mPOST /webhook HTTP/1.1�[0m" 500 -
[2020-05-10 19:25:05,541] ERROR in app: Exception on /webhook [POST]
Traceback (most recent call last):
File "C:\Users\ali\AppData\Roaming\Python\Python38\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\ali\AppData\Roaming\Python\Python38\site-packages\flask\app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\ali\AppData\Roaming\Python\Python38\site-packages\flask\app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\ali\AppData\Roaming\Python\Python38\site-packages\flask_compat.py", line 39, in reraise
raise value
File "C:\Users\ali\AppData\Roaming\Python\Python38\site-packages\flask\app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\ali\AppData\Roaming\Python\Python38\site-packages\flask\app.py", line 1936, in dispatch_request
return self.view_functionsrule.endpoint
File "C:\tradingview-webhooks-bot-master\tradingview-webhooks-bot\webhook-bot.py", line 30, in webhook
data = parse_webhook(request.get_data(as_text=True))
File "C:\tradingview-webhooks-bot-master\tradingview-webhooks-bot\actions.py", line 13, in parse_webhook
data = ast.literal_eval(webhook_data)
File "C:\Users\ali\AppData\Local\Programs\Python\Python38-32\lib\ast.py", line 59, in literal_eval
node_or_string = parse(node_or_string, mode='eval')
File "C:\Users\ali\AppData\Local\Programs\Python\Python38-32\lib\ast.py", line 47, in parse
return compile(source, filename, mode, flags,
File "", line 1
{"type": "market", "side": "buy", "amount": "15", "symbol": "XBTUSD", "price": "None", "key": "a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2"
^
SyntaxError: unexpected EOF while parsing
127.0.0.1 - - [10/May/2020 19:25:05] "�[35m�[1mPOST /webhook HTTP/1.1�[0m" 500

please who can help me ı dont know python ı am trying to learn ,,,, if someone want to help to me he can connect via teamview to my pc

Wiki Content and Guides

Hey all!

I know I've been a bit inactive over the years with this project. However, I'm looking to release the next iteration, which means new material for the Wiki and getting started guides.

If anyone would like to contribute, let me know and I can explain what needs work.

Thanks!

Add log to a file

When running it via apache, there is no way to see how exchange replies or if something happens. So, some kind log file is needed.

How to add Oanda API

Thanks for your good work.
I would like to know how can I add Oanda API by using your Python module.
It will be good if we can add other brokers.

Thanks

Worker timeout

Happens when /webhook request can't be processed in time. Can be from various causes. Investigating...

how can I test it with curl?

I followed the instructions from #8
Made the changes to the script and started it. Runs OK, seems to listen port 5000
How can I test it from a outside to make sure it actually works OK. (I am not a developer so... ;)

500 Internal Server Error

This is the error i am getting could you assist?

SyntaxError: invalid syntax
127.0.0.1 - - [03/Feb/2020 14:21:52] "POST /webhook HTTP/1.1" 500 -
Traceback (most recent call last):
  File "C:\Users\user\.virtualenvs\tvwebhooks-2LK2msMJ\lib\site-packages\flask\app.py", line 2463, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Users\user\.virtualenvs\tvwebhooks-2LK2msMJ\lib\site-packages\flask\app.py", line 2449, in wsgi_app
    response = self.handle_exception(e)
  File "C:\Users\user\.virtualenvs\tvwebhooks-2LK2msMJ\lib\site-packages\flask\app.py", line 1866, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\user\.virtualenvs\tvwebhooks-2LK2msMJ\lib\site-packages\flask\_compat.py", line 39, in reraise
    raise value
  File "C:\Users\user\.virtualenvs\tvwebhooks-2LK2msMJ\lib\site-packages\flask\app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\user\.virtualenvs\tvwebhooks-2LK2msMJ\lib\site-packages\flask\app.py", line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\user\.virtualenvs\tvwebhooks-2LK2msMJ\lib\site-packages\flask\app.py", line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\user\.virtualenvs\tvwebhooks-2LK2msMJ\lib\site-packages\flask\_compat.py", line 39, in reraise
    raise value
  File "C:\Users\user\.virtualenvs\tvwebhooks-2LK2msMJ\lib\site-packages\flask\app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\user\.virtualenvs\tvwebhooks-2LK2msMJ\lib\site-packages\flask\app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\Users\user\Google Drive\Python\tvwebhooks\main.py", line 20, in webhook
    data = parse_webhook(request.get_data(as_text=True))
  File "C:\Users\user\Google Drive\Python\tvwebhooks\actions.py", line 13, in parse_webhook
    data = ast.literal_eval(webhook_data)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Lib\ast.py", line 46, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Lib\ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
File "<unknown>", line 1
    BTCUSD, 1 Moving Up 0.01 in 1 bars
                   ^
SyntaxError: invalid syntax

tradingview-webhooks-bot for Interactive Broker

Hi, there.
I am very interested in your project.
I am going to use your webhook method on my projects.
By the way, I can't use it with my Interactive Broker Python API.
I am calling ib_insync function on the send_order in action.py(instead of ccxt.kraken)
By the way, I can't write the ib_insync function.
image

Can you help me?
Can I trade by using your webhook method in the Interactive Broker?
Thanks.

Warning: Python 3.7 was not found on your system…

Fresh install of Ubuntu 20.04 that has python 3.8 gives this error:

pipenv install
Warning: Python 3.7 was not found on your system…
You can specify specific versions of Python with:
  $ pipenv --python path/to/python

Possible that you can test and fix?

I changed Pipfile to this and it was at least installing:

[requires]
python_version = "3.8"

TradingView bot

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Request: Please add install instructions with Apache

  1. Directory structure
  2. if any files need to be edited (#8)
  3. if any files need to be moved
  4. sample Apache virtual host config

Something like:

<VirtualHost *:80>
		ServerName mywebsite.com
		ServerAdmin [email protected]
		WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi 
		<Directory /var/www/FlaskApp/FlaskApp/>
			Order allow,deny
			Allow from all
		</Directory>
		Alias /static /var/www/FlaskApp/FlaskApp/static
		<Directory /var/www/FlaskApp/FlaskApp/static/>
			Order allow,deny
			Allow from all
		</Directory>
		ErrorLog ${APACHE_LOG_DIR}/error.log
		LogLevel warn
		CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

TypeError: can't multiply sequence by non-int of type 'str'

First of all ı want to thank you for your project.
Than ı have a problem while ı am sending a "market" order. When I change order type to "limit", it doesn't cause any problem, sending order correctly.
How can ı fix this problem?
Thanks for your help.

[Alert Received]
POST Received: {'type': 'market', 'side': 'buy', 'amount': '1000', 'symbol': 'MATIC/USDT', 'price': 'None', 'key': '2b5d9b96dfb7c18841bbd50f822d7f0ef7172732943856016074fd7f'}
Sending: MATIC/USDT market buy 1000 None
[2020-04-06 09:55:20,811] ERROR in app: Exception on /webhook [POST]
Traceback (most recent call last):
File "C:\Anaconda3\lib\site-packages\flask\app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "C:\Anaconda3\lib\site-packages\flask\app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Anaconda3\lib\site-packages\flask\app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Anaconda3\lib\site-packages\flask_compat.py", line 39, in reraise
raise value
File "C:\Anaconda3\lib\site-packages\flask\app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Anaconda3\lib\site-packages\flask\app.py", line 1935, in dispatch_request
return self.view_functionsrule.endpoint
File "C:\Users\Kahraman\Desktop\tradingview-webhooks-bot-master\tradingview-webhooks-bot\webhook-bot.py", line 38, in webhook
send_order(data)
File "C:\Users\Kahraman\Desktop\tradingview-webhooks-bot-master\tradingview-webhooks-bot\actions.py", line 53, in send_order
data['symbol'], data['type'], data['side'], data['amount'], calc_price(data['price']))
File "C:\Anaconda3\lib\site-packages\ccxt\binance.py", line 1096, in create_order
request['quoteOrderQty'] = self.decimal_to_precision(amount * price, TRUNCATE, precision, self.precisionMode)
TypeError: can't multiply sequence by non-int of type 'str'
127.0.0.1 - - [06/Apr/2020 09:55:20] "POST /webhook HTTP/1.1" 500 -

Very excited!

Just wanted to stop by and show support for what you are doing. TradingView finally came to its senses and opening up webhooks is huge!

pipenv trouble starting

Hi,
I have trouble starting the shell. Only getting this message:
Launching subshell in virtual environment…
bash: 8: Bad file descriptor
. /home/zta/.local/share/virtualenvs/tradingview-webhooks-bot-mMk8oI4N/bin/activate

But I guess it maybe depends on my local environment?

cheers

How to get reduce_only to work on bybit

Hello, first of all thanks for all the time and effort you put in to creating this. I have the following issue: i am not familiar with python. And after trying all sorts of things for a week with changing tradingview alerts and the actions.py to get my problem solved. i just cant get it to work.

So i use bybit in hedge mode (both shorts and longs can be open at same time). To close a position the extra parameter reduce_only is needed, with values true or false. I also wanted to add a stop loss which i thought should also be added through params. I added them in actions.py as follows

print('Sending:', data['symbol'], data['type'], data['side'], data['amount'], data['reduce_only'], data['stop_loss'])
order = exchange.create_order(data['symbol'], data['type'], data['side'], data['amount'], params={'reduce_only': data['reduce_only'], 'stop_loss': data['stop_loss']})

i keep getting the error:
NameError: name 'reduce_only' is not defined
NameError: name 'stop_loss' is not defined

Any help would be greatly appreciated..
Thank you

FTX failing

I had to change the dependencies to include 1.93 for CCXT to get the more recent exchanges - such as FTX.

I get this when sending orders to Ngrok with a /webhook to POST to:

[Alert Received] POST Received: {'type': 'market', 'side': 'buy', 'amount': '0.01', 'symbol': 'BTC-PERP', 'price': 'None', 'key': 'd16fc5157c8bb83570dc90e63bf927ba0926fafb15e66503711dba6b'} Sending: BTC-PERP market buy 0.01 None [2019-11-21 16:37:19,833] ERROR in app: Exception on /webhook [POST] Traceback (most recent call last): File "/home/ubuntu/.local/share/virtualenvs/tradingview-webhooks-bot-KPgcNiaq/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app response = self.full_dispatch_request() File "/home/ubuntu/.local/share/virtualenvs/tradingview-webhooks-bot-KPgcNiaq/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/ubuntu/.local/share/virtualenvs/tradingview-webhooks-bot-KPgcNiaq/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception reraise(exc_type, exc_value, tb) File "/home/ubuntu/.local/share/virtualenvs/tradingview-webhooks-bot-KPgcNiaq/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise raise value File "/home/ubuntu/.local/share/virtualenvs/tradingview-webhooks-bot-KPgcNiaq/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request rv = self.dispatch_request() File "/home/ubuntu/.local/share/virtualenvs/tradingview-webhooks-bot-KPgcNiaq/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "webhook-bot.py", line 35, in webhook send_order(data) File "/home/ubuntu/projects/tradingview-webhooks-bot/tradingview-webhooks-bot/actions.py", line 49, in send_order order = exchange.create_order(data['symbol'], data['type'], data['side'], data['amount'], calc_price(data['price'])) File "/home/ubuntu/.local/share/virtualenvs/tradingview-webhooks-bot-KPgcNiaq/lib/python3.7/site-packages/ccxt/ftx.py", line 830, in create_order priceToPrecision = float(self.price_to_precision(symbol, price)) File "/home/ubuntu/.local/share/virtualenvs/tradingview-webhooks-bot-KPgcNiaq/lib/python3.7/site-packages/ccxt/base/exchange.py", line 1188, in price_to_precision return self.decimal_to_precision(price, ROUND, self.markets[symbol]['precision']['price'], self.precisionMode) File "/home/ubuntu/.local/share/virtualenvs/tradingview-webhooks-bot-KPgcNiaq/lib/python3.7/site-packages/ccxt/base/decimal_to_precision.py", line 55, in decimal_to_precision dec = decimal.Decimal(str(n)) decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>] 127.0.0.1 - - [21/Nov/2019 16:37:19] "POST /webhook HTTP/1.1" 500 -

Default configuration doesn't run on Docker for Windows

The current docker-compose.yml file does not work when running the container in Docker for Windows. The container is inaccessible even from localhost.

The solution is to change network_mode to bridge and use the docker --publish or -p parameter to bind the port.
This issue is resolved by Pull Request #55 , adding an FAQ entry for easy adjustment by the user.

What am I doing wrong here, I have followed all steps correctly

ualenvs/trading-hnTPjx37/bin/activate
(trading) ubuntu@ip-172-31-34-546:~/tradingview/trading$ python webhook-bot.py

  • Serving Flask app "webhook-bot" (lazy loading)
  • Environment: production
    WARNING: This is a development server. Do not use it in a production deployment.
    Use a production WSGI server instead.
  • Debug mode: off
  • Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
    127.0.0.1 - - [08/Mar/2020 17:22:51] "GET / HTTP/1.1" 200 -
    127.0.0.1 - - [08/Mar/2020 17:22:51] "GET /favicon.ico HTTP/1.1" 404 -
    [Alert Received]
    POST Received: {'type': 'market', 'side': 'sell', 'amount': '10', 'symbol': 'BTC/USD', 'price': 'None', 'key': '292f4a2921fa2153eb13862c051448f5b4e8fffeedee33ww'}
    Sending: BTC/USD market sell 10 None
    [2020-03-08 17:30:04,045] ERROR in app: Exception on /webhook [POST]
    Traceback (most recent call last):
    File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/base/exchange.py", line 539, in fetch
    response.raise_for_status()
    File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
    requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://www.bitmex.com/api/v1/order

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functionsrule.endpoint
File "webhook-bot.py", line 35, in webhook
send_order(data)
File "/home/ubuntu/tradingview/trading/actions.py", line 49, in send_order
order = exchange.create_order(data['symbol'], data['type'], data['side'], data['amount'], calc_price(data['price']))
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/bitmex.py", line 1079, in create_order
response = self.privatePostOrder(self.extend(request, params))
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/base/exchange.py", line 435, in inner
return entry(_self, **inner_kwargs)
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/base/exchange.py", line 458, in request
return self.fetch2(path, api, method, params, headers, body)
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/base/exchange.py", line 454, in fetch2
return self.fetch(request['url'], request['method'], request['headers'], request['body'])
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/base/exchange.py", line 551, in fetch
self.handle_errors(http_status_code, http_status_text, url, method, headers, http_response, json_response, request_headers, request_body)
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/bitmex.py", line 1154, in handle_errors
raise BadRequest(feedback)
ccxt.base.errors.BadRequest: bitmex {"error":{"message":"'price' must be a number.","name":"HTTPError"}}
127.0.0.1 - - [08/Mar/2020 17:30:04] "POST /webhook HTTP/1.1" 500 -
[Alert Received]
POST Received: {'type': 'market', 'side': 'sell', 'amount': '10', 'symbol': 'BTC/USD', 'price': 'None', 'key': '292f4a2921fa2153eb13862c051448f5b4e87caf04ba0287999f68bc'}
Sending: BTC/USD market sell 10 None
[2020-03-08 17:30:11,478] ERROR in app: Exception on /webhook [POST]
Traceback (most recent call last):
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/base/exchange.py", line 539, in fetch
response.raise_for_status()
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://www.bitmex.com/api/v1/order

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functionsrule.endpoint
File "webhook-bot.py", line 35, in webhook
send_order(data)
File "/home/ubuntu/tradingview/trading/actions.py", line 49, in send_order
order = exchange.create_order(data['symbol'], data['type'], data['side'], data['amount'], calc_price(data['price']))
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/bitmex.py", line 1079, in create_order
response = self.privatePostOrder(self.extend(request, params))
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/base/exchange.py", line 435, in inner
return entry(_self, **inner_kwargs)
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/base/exchange.py", line 458, in request
return self.fetch2(path, api, method, params, headers, body)
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/base/exchange.py", line 454, in fetch2
return self.fetch(request['url'], request['method'], request['headers'], request['body'])
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/base/exchange.py", line 551, in fetch
self.handle_errors(http_status_code, http_status_text, url, method, headers, http_response, json_response, request_headers, request_body)
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/bitmex.py", line 1154, in handle_errors
raise BadRequest(feedback)
ccxt.base.errors.BadRequest: bitmex {"error":{"message":"'price' must be a number.","name":"HTTPError"}}
127.0.0.1 - - [08/Mar/2020 17:30:11] "POST /webhook HTTP/1.1" 500 -
[Alert Received]
POST Received: {'type': 'market', 'side': 'sell', 'amount': '10', 'symbol': 'BTC/USD', 'price': 'None', 'key': '292f4a2921fa2153eb13862c051448f5b4e87caf04ba0287999f68bc'}
Sending: BTC/USD market sell 10 None
[2020-03-08 17:30:18,889] ERROR in app: Exception on /webhook [POST]
Traceback (most recent call last):
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/base/exchange.py", line 539, in fetch
response.raise_for_status()
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://www.bitmex.com/api/v1/order

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functionsrule.endpoint
File "webhook-bot.py", line 35, in webhook
send_order(data)
File "/home/ubuntu/tradingview/trading/actions.py", line 49, in send_order
order = exchange.create_order(data['symbol'], data['type'], data['side'], data['amount'], calc_price(data['price']))
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/bitmex.py", line 1079, in create_order
response = self.privatePostOrder(self.extend(request, params))
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/base/exchange.py", line 435, in inner
return entry(_self, **inner_kwargs)
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/base/exchange.py", line 458, in request
return self.fetch2(path, api, method, params, headers, body)
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/base/exchange.py", line 454, in fetch2
return self.fetch(request['url'], request['method'], request['headers'], request['body'])
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/base/exchange.py", line 551, in fetch
self.handle_errors(http_status_code, http_status_text, url, method, headers, http_response, json_response, request_headers, request_body)
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/bitmex.py", line 1154, in handle_errors
raise BadRequest(feedback)
ccxt.base.errors.BadRequest: bitmex {"error":{"message":"'price' must be a number.","name":"HTTPError"}}
127.0.0.1 - - [08/Mar/2020 17:30:18] "POST /webhook HTTP/1.1" 500 -
[Alert Received]
POST Received: {'type': 'market', 'side': 'sell', 'amount': '10', 'symbol': 'BTC/USD', 'price': 'None', 'key': '292f4a2921fa2153eb13862c051448f5b4e87caf04ba0287999f68bc'}
Sending: BTC/USD market sell 10 None
[2020-03-08 17:30:26,319] ERROR in app: Exception on /webhook [POST]
Traceback (most recent call last):
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/base/exchange.py", line 539, in fetch
response.raise_for_status()
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://www.bitmex.com/api/v1/order

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functionsrule.endpoint
File "webhook-bot.py", line 35, in webhook
send_order(data)
File "/home/ubuntu/tradingview/trading/actions.py", line 49, in send_order
order = exchange.create_order(data['symbol'], data['type'], data['side'], data['amount'], calc_price(data['price']))
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/bitmex.py", line 1079, in create_order
response = self.privatePostOrder(self.extend(request, params))
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/base/exchange.py", line 435, in inner
return entry(_self, **inner_kwargs)
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/base/exchange.py", line 458, in request
return self.fetch2(path, api, method, params, headers, body)
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/base/exchange.py", line 454, in fetch2
return self.fetch(request['url'], request['method'], request['headers'], request['body'])
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/base/exchange.py", line 551, in fetch
self.handle_errors(http_status_code, http_status_text, url, method, headers, http_response, json_response, request_headers, request_body)
File "/home/ubuntu/.local/share/virtualenvs/trading-hnTPjx37/lib/python3.7/site-packages/ccxt/bitmex.py", line 1154, in handle_errors
raise BadRequest(feedback)
ccxt.base.errors.BadRequest: bitmex {"error":{"message":"'price' must be a number.","name":"HTTPError"}}
127.0.0.1 - - [08/Mar/2020 17:30:26] "POST /webhook HTTP/1.1" 500 -

 ngrok command shell below

ngrok by @inconshreveable (Ctrl+C to quit)

Session Status online
Account Enock (Plan: Free)
Version 2.3.35
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://60fb567d.ngrok.io -> http://localhost:5000
Forwarding https://60fb567d.ngrok.io -> http://localhost:5000

Connections ttl opn rt1 rt5 p50 p90
10 0 0.01 0.01 2.03 2.08

HTTP Requests

POST /webhook 500 INTERNAL SERVER ERROR
POST /webhook 500 INTERNAL SERVER ERROR
POST /webhook 500 INTERNAL SERVER ERROR
POST /webhook 500 INTERNAL SERVER ERROR
POST /webhook 500 INTERNAL SERVER ERROR
POST /webhook 500 INTERNAL SERVER ERROR
POST /webhook 500 INTERNAL SERVER ERROR
POST /webhook 500 INTERNAL SERVER ERROR

How to contact you?

Hello Robert:

Thanks for great work.

How can I contact you to ask you for an extension of your github on a private line?

Please let me know.

Thanks.

K.R.

Conflict Jinga vs flask in requirements

Just tried installing from repo but there is a conflict with dependencies:

The conflict is caused by:
    The user requested Jinja2==3.1.1
    flask 2.3.2 depends on Jinja2>=3.1.2

updating one dependency led to another conflict. Finally, this set worked, but I'm hoping nothing broke...

click==8.1.3
colorama==0.4.5
Flask==2.3.2
gunicorn==20.1.0
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.1
shellingham==1.4.0
typer==0.4.0
typer-cli==0.0.13
Werkzeug==2.3.3

Update: yes, when I try to run, I notice the following error:

cannot import name 'get_terminal_size' from 'click.termui'

Feature request: Different types of orders

  1. Order size based on % of available funds.
    Example: free funds € 1000, order LTC/EUR, size 10%: order €100
    I personally like to buy round numbers and avoid buying "dust" so maybe we should have some type of rounding to closest 0.5 or something too.
  2. Cancel orders placed by the bot
  3. Margin trade (define margin level) with the order
  4. Stop loss
  5. Take profit

flask issue

Hi - I have successfully followed the steps to install pipenv and can see the pipfile and lock file as well. Upon running the pipenv graph, I see the following:

Flask==1.1.2

  • click [required: >=5.1, installed: 7.1.2]
  • itsdangerous [required: >=0.24, installed: 1.1.0]
  • Jinja2 [required: >=2.10.1, installed: 2.11.2]
    • MarkupSafe [required: >=0.23, installed: 1.1.1]
  • Werkzeug [required: >=0.15, installed: 1.0.1]

So far - does that sound right to you? Upon starting the virtual environment and running the webhook-bot, I see the following which is where I'm stuck.

Traceback (most recent call last):
File "webhook-bot.py", line 15, in
import requests
ModuleNotFoundError: No module named 'requests'

I feel like I haven't gotten very far with this (am not all that experienced, to be honest). To be clear I do have all the necessary installations.
Thanks

500 INTERNAL SERVER ERROR

Hi Robert,

Thanks for the great work. I follow the steps and when I try to send the test alert from tradingview to ngrok. I encounter an error: 500 INTERNAL SERVER ERROR. The details description is:

<title>500 Internal Server Error</title>

Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

Pls let me know if you have any idea on how to fix it. Thanks!

403 FORBIDDEN

Im getting the 403 message, Im not sure what to do.

Bitmex testnet

Hello,
When I try to use webhook with Bitmex testnet API key, it says:

ccxt.base.errors.BadSymbol: bitmex does not have market symbol XBTUSD

I searched some and found same issues and suggestions on ccxt. But, still could not solve yet:

https://github.com/ccxt/ccxt/issues/3920

I'd be glad if you guide me about that.

thank you

File "<unknown>", line 1

I keep getting following message, what may be the main cause of this error?:

SyntaxError: invalid syntax
127.0.0.1 - - [18/Jan/2021 21:08:34] "POST /webhook HTTP/1.1" 500 -
[2021-01-18 21:08:39,735] ERROR in app: Exception on /webhook [POST]
Traceback (most recent call last):
  File "/Users/alper/venv/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/alper/venv/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/alper/venv/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/alper/venv/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/alper/venv/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/alper/venv/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "webhook-bot.py", line 30, in webhook
    data = parse_webhook(request.get_data(as_text=True))
  File "/Users/alper/tools/tradingview-webhooks-bot/tradingview-webhooks-bot/actions.py", line 13, in parse_webhook
    data = ast.literal_eval(webhook_data)
  File "/usr/local/Cellar/[email protected]/3.7.9_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ast.py", line 46, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "/usr/local/Cellar/[email protected]/3.7.9_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "<unknown>", line 1
    ALERT!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.