Skip to content

Testing TradingView connection

Rose Heart edited this page Feb 4, 2024 · 13 revisions

Testing TradingView connection

This content is a technical guide on how to test the connection between TradingView and Jackrabbit Relay. If you are interested in using TradingView and Jackrabbit Relay for trading, this guide can help you ensure that your connection is functioning properly.

The guide outlines the steps and configurations required to perform the test and provides a TradingView script and a program to facilitate the testing process. It also includes setup instructions, such as the TradingView alert message that can be used for testing purposes, and the exchange required for the tester place order program.

This guide is an essential resource for anyone who is new to using TradingView and Jackrabbit Relay and wants to ensure that their connection is working correctly. After testing your connection, the guide also provides a link to a step-by-step guide for setting up live trading.

Please be sure to utilize the JSON Validator to fully verify your order payloads. Note that there is a copy button that will copy the order payload, in compact form, to your clipboard. This is suitable for TradingView alert messages.

Testing method

Tester virtual exchange

Jackrabbit Relay provides both a TradingView script and place order program to facilitate testing.

In the Extras folder is the script that can be copied/pasted into TradingView's pine editor, or you can use this link,

Pine Script Signal Generator

Setup

As a virtual exchange, the tester has a configuration file in the Config folder,

# Tester - Virtual Exchange Framework                                                                                                 # Virtual exchanges do NOT follow regular exchange requirements. They can be any                                                      # modifier the developer has in mind. The MUST have all the basic requirements                                                        # of an exchange though, including Identity, including and expecially a webhook.                                                      # The virtual exchange is responsible for sending the modified payload to the                                                         # Relay server thru the webhook.                                                                                                      # A webhook may not be needed if the virtual exchange does not actually send                                                          # orders on. A ligitimate case study would be a full paper trading exchange that                                                      # only analyzes the market or a machine learning process that strictly collects                                                       # data for its own analysis.                                                                                                          
# Virtual exchange setting must be validated by developer.

# Remember that security is FULLY enforced, no exceptions, not evern for virtual
# exchanges.

# They may or may not need a login or API. Set be developer. This config is for
# the tester for TradingView.

# Account is one of the validating elements from the payload. It IS required.

{ "Framework":"virtual","Account":"TestBox" }

This file sets the requirements for the tester virtual exchange.

Use the following or something similar for your TradingView alert message, order payload (any asset can be used and no actual trades will be placed),

{ 
  "Exchange":"tester",
  "Market":"Spot",
  "Account":"Sandbox",
  "Action":"Buy",
  "Asset":"AAVE/USD",
  "Identity":"Your Identity" 
}

The tester exchange allow the tester place order program to be used. It simple logs the message in the Logs folder. Be sure to read the /home/Jackrabbit2/Config/tester.cfg file for more details. Once you have verified that your connection is stable, this proceed to the next test.

Common issues are with the identity or JSON payload structure. Using a JSON validator from anywhere on the web can highlight any issues quickly. Identity issues will show up in the logs.

DSR testing

Please refer to the DSR setup information for a detailed explaination of these elements.

Here is a base example of the dsr.cfg file,

# DSR - Virtual Exchange Framework

# Virtual exchanges do NOT follow regular exchange requirements. They can be any
# modifier the developer has in mind. The MUST have all the basic requirements
# of an exchange though, including Identity, including and expecially a webhook.
# The virtual exchange is responsible for sending the modified payload to the
# Relay server thru the webhook.

# A webhook may not be needed if the virtual exchange does not actually send
# orders on. A ligitimate case study would be a full paper trading exchange that
# only analyzes the market or a machine learning process that strictly collects
# data for its own analysis.

# Virtual exchange setting must be validated by developer.

# Remember that security is FULLY enforced, no exceptions, not evern for virtual
# exchanges.

# They may or may not need a login or API. Set be developer. This config is or
# the DSR (duplicate signal remover) for TradingView.

# Account is one of the validating elements from the payload. It IS required.

{ "Framework":"virtual","Account":"OANDA","Webhook":"http://127.0.0.1:7732" }
{ "Framework":"virtual","Account":"Sandbox","Webhook":"http://127.0.0.1:7732" }

Now for the order payload,

{
  "Comment1":"Relay required elements",
  "Time":"{{time}}",
  "Recipe":"#ATR #RSI #DCA",
  "Action":"Buy",
  "Exchange":"dsr,tester",
  "Account":"Sandbox,TestBox",
  "Market":"Spot",
  "USD":"1%",
  "Asset":"{{ticker}}",
  "Comment4":"Price used in limit orders as well as DSR",
  "Price":"{{close}}",
  "Comment2":"DSR required elements in addition to above",
  "AvgProfit":"{{plot_0}}",
  "LProfit":"{{plot_1}}",
  "TCycles":"{{plot_2}}",
  "CBuys":"{{plot_3}}",
  "MBCycle":"{{plot_4}}",
  "TBuys":"{{plot_5}}",
  "Link":"https://www.tradingview.com/chart/lMQAJ6YU",
  "Identity":"YourIdentity"
}

Now lets put it all together. This is an example of using the DSR, an exchange, and conditional orders, all in a single payload. Comment(1/2/3), Recipe, and Link aren't needed, but recommended to help keep your order organized. This payload also uses TradingView macros. The take profit and stoploss are descretionary based upon your resk management.

{ 
  "Comment1","Basic order",
  "Exchange":"dsr,kraken", 
  "Account":"Kraken,MAIN", 
  "Market":"Spot", 
  "Action":"Buy", 
  "Asset":"{{ticker}}", 
  "Base":"1",
  "RemapSymbol":"Yes",
  "Comment2","DSR section",
  "Recipe":"17/47 #Crossover 197 #Momentum", 
  "Link":"https://www.tradingview.com/chart/M4dbBVTB/", 
  "Time":"{{time}}", 
  "Price":"{{close}}", 
  "AvgProfit":"{{plot_0}}", 
  "LProfit":"{{plot_1}}", 
  "TCycles":"{{plot_2}}",
  "CBuys":"{{plot_3}}", 
  "MBCycle":"{{plot_4}}", 
  "TBuys":"{{plot_5}}",
  "Comment3":"Conditional order section", 
  "Conditional":"Yes", 
  "Direction":"Long", 
  "SellAction":"Sell",
  "TakeProfit":"2%",
  "StopLoss":"9%",
  "Identity":"Redacted"
}

Force feeding payloads

Things go wrog once in a while, and subsequently, forced testing is required. This section details how to complete such testing. The first step in forced testing us saving a payload in pure text to a file. It can be anywhere, but I recomend a directory inder the /home directory,

mkdir /home/Testing
cd /home/Testing

Now using mcedit, nano, or some other PLAIN TEXT EDITOR, save your payload to a file, ie, testmsg or dsrmsg. Please be sure to take the time to neme these filese appropriately as they will be used frequently to diagnose issues.

Lets start with the tester. I'm going to use the DSR msg for this example.

/home/JackrabbitRelay2/Base/PlaceOrder.tester < /home/JackrabbitRelay2/Testing/msgDSR

The above command is how you force feed a payload into a place order processor. It is the most effecient way to test any payload (alert messaege).

The output will be similar to the below.

2023-03-29 19:05:31.171939 3408013 PlaceOrder Tester 0.0.0.1.45
2023-03-29 19:05:31.173601 3408013 Order parsed
2023-03-29 19:05:31.173691 3408013 |- Comment1: Relayrequiredelements
2023-03-29 19:05:31.173750 3408013 |- Exchange: dsr
2023-03-29 19:05:31.173796 3408013 |- Market: Spot
2023-03-29 19:05:31.173852 3408013 |- Account: Sandbox
2023-03-29 19:05:31.173897 3408013 |- Action: buy
2023-03-29 19:05:31.173942 3408013 |- Asset: ETHUSDT
2023-03-29 19:05:31.174000 3408013 |- USD: 1%
2023-03-29 19:05:31.174087 3408013 |- RemapSymbol: Yes
2023-03-29 19:05:31.174168 3408013 |- Comment4: PriceusedinlimitordersaswellasDSR
2023-03-29 19:05:31.174233 3408013 |- Price: 0.00001059
2023-03-29 19:05:31.174328 3408013 |- Comment2: DSRrequiredelementsinadditiontoabove
2023-03-29 19:05:31.174416 3408013 |- Time: 2022-10-14T06:22:00Z
2023-03-29 19:05:31.174495 3408013 |- Recipe: #Momentum#MACD#BBands#DCA
2023-03-29 19:05:31.174545 3408013 |- AvgProfit: 1.1534158404637536
2023-03-29 19:05:31.174600 3408013 |- LProfit: 1.500237191650844
2023-03-29 19:05:31.174642 3408013 |- TCycles: 4
2023-03-29 19:05:31.174683 3408013 |- CBuys: 2
2023-03-29 19:05:31.174774 3408013 |- MBCycle: 16
2023-03-29 19:05:31.174828 3408013 |- TBuys: 31
2023-03-29 19:05:31.174870 3408013 |- Link: https://www.tradingview.com/chart/mPaXGZSU/
2023-03-29 19:05:31.174922 3408013 |- OrderType: market
2023-03-29 19:05:31.174973 3408013 Processing Completed: 0:00:00.003393 seconds

You will also find this content is the tester.log file in the log directory.

Now to test the DSR,

/home/JackrabbitRelay2/Base/PlaceOrder.dsr < /home/JackrabbitRelay2/Testing/msgDSR
2023-03-29 19:10:54.764880 3408300 PlaceOrder DSR 0.0.0.1.45
2023-03-29 19:10:54.766000 3408300 Order parsed
2023-03-29 19:10:54.766085 3408300 |- Comment1: Relayrequiredelements
2023-03-29 19:10:54.766145 3408300 |- Exchange: dsr
2023-03-29 19:10:54.766196 3408300 |- Market: Spot
2023-03-29 19:10:54.766250 3408300 |- Account: Sandbox
2023-03-29 19:10:54.766451 3408300 |- Action: buy
2023-03-29 19:10:54.766643 3408300 |- Asset: ETHUSDT
2023-03-29 19:10:54.766812 3408300 |- USD: 1%
2023-03-29 19:10:54.766947 3408300 |- RemapSymbol: Yes
2023-03-29 19:10:54.767071 3408300 |- Comment4: PriceusedinlimitordersaswellasDSR
2023-03-29 19:10:54.767189 3408300 |- Price: 0.00001059
2023-03-29 19:10:54.767307 3408300 |- Comment2: DSRrequiredelementsinadditiontoabove
2023-03-29 19:10:54.767426 3408300 |- Time: 2022-10-14T06:22:00Z
2023-03-29 19:10:54.767554 3408300 |- Recipe: #Momentum#MACD#BBands#DCA
2023-03-29 19:10:54.767656 3408300 |- AvgProfit: 1.1534158404637536
2023-03-29 19:10:54.767749 3408300 |- LProfit: 1.500237191650844
2023-03-29 19:10:54.767839 3408300 |- TCycles: 4
2023-03-29 19:10:54.767930 3408300 |- CBuys: 2
2023-03-29 19:10:54.768023 3408300 |- MBCycle: 16
2023-03-29 19:10:54.768112 3408300 |- TBuys: 31
2023-03-29 19:10:54.768202 3408300 |- Link: https://www.tradingview.com/chart/mPaXGZSU/
2023-03-29 19:10:54.768296 3408300 |- OrderType: market
2023-03-29 19:10:54.875257 3408300 DSR failed with: Duplicate order
2023-03-29 19:10:54.875400 3408300 Processing Completed: 0:00:00.110808 seconds

Here there is an problem, but not an error or program crash. This example highlights the importance of checking ALL your logs. Below is a successful log entry for kucoin using the DSR,

/home/JackrabbitRelay2/Base/PlaceOrder.dsr < /home/JackrabbitRelay2/Testing/msgDSR
2023-03-29 19:14:56.697854 3408538 PlaceOrder DSR 0.0.0.1.45
2023-03-29 19:14:56.698002 3408538 Order parsed
2023-03-29 19:14:56.698059 3408538 |- Comment1: Relayrequiredelements
2023-03-29 19:14:56.698105 3408538 |- Exchange: dsr
2023-03-29 19:14:56.698147 3408538 |- Market: Spot
2023-03-29 19:14:56.698186 3408538 |- Account: Sandbox
2023-03-29 19:14:56.698224 3408538 |- Action: buy
2023-03-29 19:14:56.698264 3408538 |- Asset: ETHUSDT
2023-03-29 19:14:56.698312 3408538 |- USD: 1%
2023-03-29 19:14:56.698361 3408538 |- RemapSymbol: Yes
2023-03-29 19:14:56.698402 3408538 |- Comment4: PriceusedinlimitordersaswellasDSR
2023-03-29 19:14:56.698444 3408538 |- Price: 0.00001075
2023-03-29 19:14:56.698485 3408538 |- Comment2: DSRrequiredelementsinadditiontoabove
2023-03-29 19:14:56.698525 3408538 |- Time: 2022-10-14T06:22:00Z
2023-03-29 19:14:56.698571 3408538 |- Recipe: #Momentum#MACD#BBands#DCA
2023-03-29 19:14:56.698627 3408538 |- AvgProfit: 1.1534158404637536
2023-03-29 19:14:56.698669 3408538 |- LProfit: 1.500237191650844
2023-03-29 19:14:56.698709 3408538 |- TCycles: 4
2023-03-29 19:14:56.698822 3408538 |- CBuys: 3
2023-03-29 19:14:56.698866 3408538 |- MBCycle: 16
2023-03-29 19:14:56.698905 3408538 |- TBuys: 38
2023-03-29 19:14:56.698944 3408538 |- Link: https://www.tradingview.com/chart/mPaXGZSU/
2023-03-29 19:14:56.698984 3408538 |- OrderType: market
2023-03-29 19:14:56.801423 3408538 Dispatching to kucoin/Sandbox
2023-03-29 19:15:10.339188 3408538 Processing Completed: 0:00:13.641615 seconds

The actual payload will be listed in the kucoin.log file as well as the results from the PlaceOrder kucoin program. Those details are outlined in the log files.

Here is a test payload for the OANDA broker using the DSR. It is important to remember that the testing process can NOT translate TradingView macros.

{                                                                                                                                       
  "Identity": "YourID",
  "Time": "2022-11-09T15:40:45Z", 
  "Recipe": "#Tester#DCA",                                                                              
  "Action": "sell",                                                                                                                     
  "Exchange": "oanda",                                                                                                                  
  "Account": "MAIN",                                                                                                                    
  "Asset": "EURUSD",                                                                                                                    
  "Units": "1",                                                                                                                         
  "Price": "1.002405",                                                                                                                  
  "AvgProfit": "0.327011078530943", 
  "LProfit": "0.3511358400963949",                                                                    
  "TCycles": "14", 
  "CBuys": "3", 
  "MBCycle": "9", 
  "TBuys": "37",                                                                         
  "RemapSymbol": "Yes",                                                                                                                 
  "Link": "https://www.tradingview.com/chart/naYu8oKU/",                                                                                
  "OrderType": "market"                                                                                                               }

Next steps

After you have done all the tests and checks, the next steps will be setting up live tading.

RAPMD Crypto: Automated algorithmic trading done right

Jackrabbit support server

JSON Validator

Frequency Weighted OrderBook Analysis

Advanced Research

Introduction

Jackrabbit Relay
Introduction
Risks
Disclaimer
Notes
Video
Supported Exchanges/Brokers
Security and firewall
Installation
Updating
Configuration files
Live Trading


Installation-and-Setup

Creating a Virtual Environment
Installation/Setup
Requirements
Stopping Version 1
Installing and setting up Version 2
Configuration
Reboot startup
Manual startup


Identity

Identity


Configuration

Configuration
Configuration files
Location and file names
File contents
Order types
Examples for the CCXT framework
Examples for the OANDA framework


Orders

JackrabbitRelay Order Payloads
Payload Synopsis
Order Types
Actions
Examples


Conditional Orders

JackrabbitRelay Order Payloads
Oliver Twist: Jackrabbit Relay conditional and orphan order manager
Unveiling Oliver Twist's Conditional Methodology
Managing Orphan Orders: The Limit-Only Approach
The Literary Significance of "Oliver Twist"


Supported-Exchanges-and-Brokers

Supported Exchanges/Brokers
Forex Brokers
Confirmed working brokers
Cryptocurrency Exchanges
Confirmed working exchanges
Theoretically supported


Known-Issues

Known Issues
Closing a position fails
BitMex
Phemex
ByBit
Python 3.10
Kucoin Futures/TradingView


Virtual-Exchange-Broker-DSR

DSR (Duplicate Signal Remover)
Log Files


Jackrabbit-Mimic

Jackrabbit Mimic
Introduction
Usage
Data Source Integration
Simple Setup Process
Understanding Differences
Educational Focus
Setup and Configuration
Wallets and history
How cryptocurrency wallets work
Long positions
Short positions
Alert/Signal messages
Long positions
Short positions
Supporting Jackrabbit Mimic


Logs

Logs
Files
JackrabbitRelay
PlaceOrder


Testing-TradingView-connection

Testing TradingView connection
Testing method
Setup
DSR Testing
Force feeding payloads
Next Steps


Step-by-step guide to live trading with TradingView

Step-by-step guide to live trading with TradingView
Walk Through
Strategy Differences


Additional Programs

Additional Programs


Roadmap

Roadmap
Finished
In Progress
Future Plans


Supporting-Jackrabbit

Supporting Jackrabbit and it's future development
Current patrons and subscribers
The cost of open source
Supporting

Terms-and-Definitions

Terms and Definitions

Clone this wiki locally