TradingView
AlphaCentauri66367
2023年2月20日晚上9點25分

PineTradingbotWebhook 

Apple Inc.NASDAQ

描述

Library "PineTradingbotWebhook"

makeWebhookJson(webhookKey, direction, qty, entryLimit, entryStop, exitLimit, exitStop, orderRef, contract)
  Creates a Webhook message for Tbot on Tradingboat
  Parameters:
    webhookKey: the unique key to the Flask (TVWB) server
    direction: the same as the strategy's direction
    qty
    entryLimit
    entryStop
    exitLimit
    exitStop
    orderRef
    contract
  Returns: JSON as a string

發布通知

v2:
update the "qty" argument from a "simple float" to a "series float"

發布通知

v3

Updated:
- Update PineScript library to send a single client ID for multiple Redis pub actions

發布通知

v4

Updated:
"Revised makeWebhookJson function to use -1e10 as a special value for the qty parameter to indicate all contracts/units should be exited. Added comment to code to explain the special value."

發布通知

v5

This update includes the addition of a detailed description for function parameters.

Allow me to clarify the purpose of this library.
The library generates webhook messages in JSON format.
The following is an example of the JSON message format:

----------------------------------------------------------------------------------
{
"timestamp": 1645630199,
"ticker": "AAPL",
"currency": "USD",
"timeframe": "1D",
"key": "WebhookReceived:123456",
"contract": "stock",
"orderRef": "long#1",
"direction": "strategy.long",
"clientId": 1,
"metrics": [
{
"name": "entry.stop",
"value": 130.0
},
{
"name": "entry.limit",
"value": 0.0
},
{
"name": "exit.limit",
"value": 150.0
},
{
"name": "exit.stop",
"value": 100.0
}
]
}
----------------------------------------------------------------------------------
The webhook message can be received by a web server. An example of such a server is provided below.
The web server is based on Flask and TVWB.
It can push Redis messages to individual Redis Streams per Interactive Broker clientID,
as well as fetch order information and display it in web browsers.

Here is the link to the GitHub repository for the tradingview-webhooks-bot:

github.com/PlusGenie/tradingview-webhooks-bot

發布通知

v6
This patch replaces string concatenation with the str.format() function for better readability and performance

發布通知

v7

Updated: Rearrange the function signature parameter order

makeWebhookJson(webhookKey, orderRef, direction, qty, entryLimit, entryStop, exitLimit, exitStop, contract, clientId)
  Creates a Webhook message for Tbot on Tradingboat
  Parameters:
    webhookKey (simple string): the unique key to the Flask (TVWB) server - // Use format like WebhookReceived:123456
    orderRef (simple string): this will be used to create the order reference ID, together with timeframe and clientID
    direction (simple string): the same as the strategy's direction - strategy.entrylong, strategy.entryshort, strategy.exitlong, strategy.exitshort, strategy.close, strategy.close_all
    qty (float): default value is -1e10 indicating all contracts/units
    entryLimit (float): this is same to strategy.entry()'s limit parameter
    entryStop (float): this is same to strategy.entry()'s stop parameter
    exitLimit (float): this is the same to strategy.exit()'s limit parameter
    exitStop (float): this is the same to strategy.exit()'s stop parameter
    contract (simple string): this will be translated to secType in ib insync. stock, forex, crypto
    clientId (int): this is for IB Gateway/TWS's clientID which should start with 1
  Returns: JSON as a series string

發布通知

v8

Updated: The library has been updated to include support for Futures.

makeWebhookJson(webhookKey, orderRef, direction, qty, entryLimit, entryStop, exitLimit, exitStop, contract, exchange, lastTradeDateOrContractMonth, clientId)
  Creates a Webhook message for Tbot on Tradingboat
  Parameters:
    webhookKey (simple string): the unique key to the Flask (TVWB) server - // Use format like WebhookReceived:123456
    orderRef (simple string): this will be used to create the order reference ID, together with timeframe and clientID
    direction (simple string): the same as the strategy's direction - strategy.entrylong, strategy.entryshort, strategy.exitlong, strategy.exitshort, strategy.close, strategy.close_all
    qty (float): default value is -1e10 indicating all contracts/units
    entryLimit (float): this is same to strategy.entry()'s limit parameter
    entryStop (float): this is same to strategy.entry()'s stop parameter
    exitLimit (float): this is the same to strategy.exit()'s limit parameter
    exitStop (float): this is the same to strategy.exit()'s stop parameter
    contract (simple string): this will be translated to secType in ib_insync. stock, forex, crypto and future(s)
    exchange (simple string): Destination exchange for ib_insync, primarily for futures.
    lastTradeDateOrContractMonth (simple string): The contract's last trading day or contract month for ib_insync, mainly for futures. Should be in the format YYYYMM or YYYYMMDD.
    clientId (int): this is for IB Gateway/TWS's clientID which should start with 1
  Returns: JSON as a series string

發布通知

v9

Updated:

Added 'ticker' parameter in PineTradingbotWebhook library

- Enhanced the makeWebhookJson function with a new 'ticker' parameter
- Ensured compatibility with different symbol formats in TradingView and ib_insync
- Provided default behavior to use current chart's ticker if 'ticker' parameter is not specified
- Updated function documentation to include the new parameter description

發布通知

v10

Updated:
makeWebhookJson(webhookKey, orderRef, direction, qty, entryLimit, entryStop, exitLimit, exitStop, contract, ticker, lastTradeDateOrContractMonth, exchange, multiplier, clientId)
  Creates a Webhook message for Tbot on Tradingboat
  Parameters:
    webhookKey (simple string): the unique key to the Flask (TVWB) server - // Use format like WebhookReceived:123456
    orderRef (simple string): this will be used to create the order reference ID, together with timeframe and clientID
    direction (simple string): the same as the strategy's direction - strategy.entrylong, strategy.entryshort, strategy.exitlong, strategy.exitshort, strategy.close, strategy.close_all
    qty (float): default value is -1e10 indicating all contracts/units
    entryLimit (float): this is same to strategy.entry()'s limit parameter
    entryStop (float): this is same to strategy.entry()'s stop parameter
    exitLimit (float): this is the same to strategy.exit()'s limit parameter
    exitStop (float): this is the same to strategy.exit()'s stop parameter
    contract (simple string): this will be translated to secType in ib_insync. stock, forex, crypto and future(s)
    ticker (simple string): The TradingView ticker symbol for the asset; defaults to the current chart's ticker if not specified.
    lastTradeDateOrContractMonth (simple string): The contract's last trading day or contract month for ib_insync, mainly for futures. Should be in the format YYYYMM or YYYYMMDD.
    exchange (simple string): Destination exchange for ib_insync, primarily for futures.
    multiplier (simple string): The futures contract multiplier is the amount multiplying the price per point to determine total value.
    clientId (int): this is for IB Gateway/TWS's clientID which should start with 1
  Returns: JSON as a series string
評論
AlphaCentauri66367
This is the example of the full JSON message generated by PineTradingbotWebhook library: pastebin.com/2dQ557eR
switzera7
With changes made to 'contract' type from v8, ETFs get categorized as 'fund' which prevents IB from executing the transaction. ETFs transactions worked with v7 as it would categorize them as 'stock'. Not sure if this can be fixed or if I have missed something?
AlphaCentauri66367
@switzera7,
Please use the official library v7 for your project.
That's why all contracts, such as stocks, crypto, and forex in the GitHub, still use v7.

v8 and v9 are only for future development versions.
v10 is the official library for a customized project that wants to include Futures.
serkany88
This is not really an efficient way to create jsons in pine, string concentations are really slow, instead you should use str.format and create your resulting json in as fewer calls as possible it will make the code execution way faster especially it will help you with faster api calls if your strategy is already too big. Otherwise you may face execution timed out errors.
AlphaCentauri66367
@serkany88,
Thank you very much for your suggestions. I've taken your advice into account and made revisions to the library accordingly.
papamextrade
Pls can someboy provide an example for GC future? AAPL works, but futures are not received by TBOT. Thx!
AlphaCentauri66367
@papamextrade, Futures are not supported by the open-source TBOT on Tradingboat.
AlphaCentauri66367
This is an example of a complete JSON message generated by the PineTradingbotWebhook library.
---------------------------------------------------------------------------------------------------
{
"timestamp": 1680795320618,
"ticker": "AAPL",
"currency": "USD",
"timeframe": "5S",
"key": "WebhookReceived:123456",
"contract": "stock",
"orderRef": "Short#1",
"direction": "strategy.entryshort",
"clientId": 1,
"metrics": [
{
"name": "entry.stop",
"value": 0.0
},
{
"name": "entry.limit",
"value": 0.0
},
{
"name": "exit.limit",
"value": 0.0
},
{
"name": "exit.stop",
"value": 0.0
},
{
"name": "qty",
"value": 100
},
{
"name": "price",
"value": 164.59
}
]
}
更多