• Stars
    star
    606
  • Rank 73,470 (Top 2 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created about 5 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a framework 🏗 for trading with tradingview webhooks!

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

Get Support on Discord

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 📘

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!

More Repositories

1

tradingview-trainer

A lightweight app for practicing your trading on Tradingview
Python
213
star
2

stratis

a python-based framework for creating and testing trading strategies
Python
35
star
3

tradingview-indicators

a repository for tradingview indicators I go over on my youtube channel
20
star
4

ubuntu-22-nvidia-suspend-fix-script

Fix for suspend not working on some instances of Ubuntu 22 w/Nvidia drivers
Shell
16
star
5

quickbase-json-api-client

Unofficial Quickbase JSON API wrapper for python. Provides objects and methods for querying and inserting records.
Python
13
star
6

tdameritrade-simple-api

Simple API for TD Ameritrade w/Python
Python
9
star
7

market-agent-sim

Agent-based market simulation, using various trading strategies.
Python
7
star
8

upreq

a small helper cli for python's requirements.txt
Go
6
star
9

bitmex-ranker

a tool to keep track of the bitmex leaderboards
Python
5
star
10

docker-essential-aliases

docker essential aliases (dea) makes working with docker just a little bit easier!
Go
4
star
11

hi-wonder-tank-chassis

Python
3
star
12

strategy-sandbox

A small tool designed to test variable targets in trading strategies
Python
2
star
13

nadocast-ui

an unofficial user interface for the nadocast project
Python
2
star
14

ssh-quick-config

Quickly and easily generates your SSH config file and handles ssh keys.
Shell
1
star
15

stratis-ui-legacy

a frontend, dynamic interface for Stratis
TypeScript
1
star
16

blocker

back and forward testing python framework
Python
1
star
17

orderex-api

The API used in the orderex application, in standalone form. Used to send API requests using multiple accounts, proxies and special options!
1
star
18

orderex

A single-line API/Tool for placing orders on multiple crypto-currency exchanges.
Python
1
star