Skip to content

tomav/docker-tradingview-trader

Repository files navigation

docker-tradingview-trader

This nodejs project allows you to execute trades from Tradingview alerts on most crypto exchanges.

Version 2.0

What's New

  • Dependencies updated: ccxt v4.4, express v4.21, jest v29.7, Node.js 20
  • New feature: cancel_orders order type to cancel all or specific types of orders
  • Security improvements: Removed eval() usage, proper async/await handling
  • CI/CD: Automated tests and Docker image publishing to GitHub Container Registry

Installation

docker pull ghcr.io/tomav/docker-tradingview-trader:latest

Usage

  • copy config.json.sample to config.json and fill in the required information
    • name is the alias for the exchange (you can have multiple aliases/accounts on 1 exchange)
    • exchange is the exchange id used in ccxt library
    • key & secret refer to the API keys you have to generate on each exchange
  • mount this config file in your docker container, ideally using docker-compose.yml

Tradingview alert message

Tradingview Webhook URL must be set to https://{your-hostname.tld}/trade Read the following sections to understand how to fill the Message field.

Tradingview alert panel

Real-life example

{
	"account": "deribit_main",
	"instrument": "BTC-PERPETUAL",
	"orders": [
		{ "t": "market_buy", "a": 10 },
		{ "t": "limit_buy", "a": 10, "p": 35000 },
		{ "t": "stop_market_sell", "a": 20, "p": 30000 }
	]
}

This example will open a market position, place a limit buy order, and set a stop order.

Note: JSON must be valid in order to be executed. You can check format using JSONLint.

Params description and requirement for each order type

  • t order type
  • a amount to buy or sell
  • p price at which to place order
  • u upper price for a scaled order
  • l lower price for a scaled order
  • n number of orders for a scaled order
  • ot order type filter for cancel_orders (optional: limit, stop, market)
t a p u l n ot
limit_buy x x
limit_sell x x
scaled_buy x x x x
scaled_sell x x x x
market_buy x
market_sell x
stop_market_buy x x
stop_market_sell x x
close_position
cancel_orders x

Cancel orders with optional type filter

The cancel_orders order type allows you to cancel all open orders, optionally filtered by order type.

Use case: Useful for updating stop losses or take profit levels by canceling existing orders before placing new ones.

Cancel all orders
{
	"account": "deribit_main",
	"instrument": "BTC-PERPETUAL",
	"orders": [
		{ "t": "cancel_orders" }
	]
}
Cancel only stop orders
{
	"account": "deribit_main",
	"instrument": "BTC-PERPETUAL",
	"orders": [
		{ "t": "cancel_orders", "ot": "stop" }
	]
}
Update stop loss example

Cancel existing stop orders and place a new one at an updated price:

{
	"account": "deribit_main",
	"instrument": "BTC-PERPETUAL",
	"orders": [
		{ "t": "cancel_orders", "ot": "stop" },
		{ "t": "stop_market_sell", "a": 20, "p": 32000 }
	]
}

Supported values for ot parameter:

  • limit - cancels only limit orders
  • stop - cancels only stop orders
  • market - cancels only market orders
  • omit ot to cancel all open orders for the instrument

Debug

curl -X POST -H "Content-Type: application/json" -d '{ "account": "first_account", "instrument": "BTC-PERPETUAL", "orders": [{ "t": "debug", "a": 10, "p": 10 }] }' http://localhost:3000/trade

Endpoints

  • POST /trade to place trades from tradingview
  • GET /exchanges to list supported exhanges, useful to find a ccxt id
  • GET /exchanges/:exchange to list available instruments (symbols) for a specific exchange

FAQ

Amount unit is in Fiat or Asset?

It depends on the exchange. Example:

  • deribit: it's fiat on BTC-PERPETUAL
  • bitfinex: it's asset on BTC/USD

Refere to exchange or ccxt documentation.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors 2

  •  
  •