|
8 | 8 |
|
9 | 9 |
|
10 | 10 |
|
11 |
| -# Tradingview-webhooks-bot |
| 11 | +# The What |
12 | 12 |
|
13 |
| -tradingview-webhooks-bot is a trading bot, written in python that allows users to place trades with tradingview's webhook alerts. |
| 13 | +Tradingview-webhooks-bot (TVWB) is a small, Python-based framework that allows you to extend or implement your own logic |
| 14 | +using data from [Tradingview's webhooks](https://www.tradingview.com/support/solutions/43000529348-about-webhooks/). |
14 | 15 |
|
15 |
| ---- |
| 16 | +# The How |
16 | 17 |
|
17 |
| -## Quickstart Using Pipenv |
| 18 | +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. |
| 19 | +TVWB uses [Flask](https://flask.palletsprojects.com/en/2.2.x/) to handle the webhooks and provides you with a simple API to interact with the data. |
18 | 20 |
|
19 |
| -Pipenv is a tool that helps users set virtual environments and install dependencies with ease. There are many benefits to creating a virtual environment, especially for those that haev other projects running on the same server. |
| 21 | +# Quickstart |
20 | 22 |
|
21 |
| -### Install pipenv and initiate virtual environment |
| 23 | +* Installation |
| 24 | +* Serving the App |
22 | 25 |
|
23 |
| -1. Install pipenv `sudo apt install pipenv` |
24 |
| -2. Once pipenv is installed, I recommend that you [get familiar with it](https://github.com/pypa/pipenv). |
25 |
| -3. Navigate to the folder where you cloned the repo. You should see `Pipfile` and `Pipfile.lock` files. |
26 |
| -4. Run command `pipenv install` |
27 |
| -5. The dependencies required to get started should now be installed. Check by running command `pipenv graph` - You should see flask and ccxt. |
28 |
| -6. If you want to install any other dependencies, or if you get an error that you're missing a depedency, simply use command `pipenv install <dependency>` |
29 |
| -7. Starting the virtual environment: `pipenv shell` |
30 |
| -8. Starting the flask app: `python webhook-bot.py` |
| 26 | +**Ensure you're in the `src` directory.** |
31 | 27 |
|
32 |
| -There you go! Nice and simple Python version and virtualenv management. |
| 28 | +### Creating an action |
33 | 29 |
|
34 |
| -### Using ngrok for webook data retrieval |
| 30 | +```bash |
| 31 | +python3 tvwb.py action:create NewAction --register |
| 32 | +``` |
35 | 33 |
|
36 |
| -Many people are having difficulties with their server properly receiving webhook data from TradingView. The easiest way to get started quickly without ripping your hair out from trying to figure out what's wrong, [ngrok](https://ngrok.com/) can be used to receive the signals. Create a free account, unless you want your server to go down every 8 hours. Navigate to the downloads page, and select your download to match your machine. For example, I am on Ubuntu: `wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip` |
| 34 | +This creates an action and automatically registers it with the app. [Learn more on registering here](https://github.com/robswc/tradingview-webhooks-bot/wiki/Registering). |
37 | 35 |
|
38 |
| -### Quick Start Guide |
| 36 | +_Note, action and event names should **_always_** be in PascalCase._ |
39 | 37 |
|
40 |
| -[Here is a quick start guide!](https://github.com/Robswc/tradingview-webhooks-bot/wiki/Quick-Start-Guide) Once everything is set up, you can use this guide to get started! |
| 38 | +### Linking an action to an event |
| 39 | + |
| 40 | +```bash |
| 41 | +python3 tvwb.py action:link NewAction WebhookReceived |
| 42 | +``` |
| 43 | + |
| 44 | +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. |
| 45 | + |
| 46 | +### Editing an action |
| 47 | + |
| 48 | +Navigate to `src/components/actions/NewAction.py` and edit the `run` method. You will see something similar to the following code. |
| 49 | +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 |
| 50 | +the webhook data. |
| 51 | + |
| 52 | +```python |
| 53 | +class NewAction(Action): |
| 54 | + def __init__(self): |
| 55 | + super().__init__() |
| 56 | + |
| 57 | + def run(self, *args, **kwargs): |
| 58 | + super().run(*args, **kwargs) # this is required |
| 59 | + """ |
| 60 | + Custom run method. Add your custom logic here. |
| 61 | + """ |
| 62 | + data = self.validate_data() # always get data from webhook by calling this method! |
| 63 | + print('Data from webhook:', data) |
| 64 | +``` |
| 65 | + |
| 66 | +### Running the app |
| 67 | + |
| 68 | +```bash |
| 69 | +python3 tvwb.py start |
| 70 | +``` |
0 commit comments