ttp-baql-reference

The official reference for the Bot Assistant Query Language (BAQL)

View the Project on GitHub

BAQL Version 1.2.5

Abstract

BAQL (Bot Assistant Query Language) is a domain specific language used for expressing declarative requirements for Bot Assistant engines used in automated trading systems.

Its goal is to provide a flexible and ergonomic semantic to users and a machine parseable set of instructions that can be used to query for the requested data.

It’s designed to be platform agnostic, albeit some expressions might not be available in all dialects.

Syntax

The syntax of the language is currently maintained by The Trading Parrot community and it’s subject to evolution over time. It follows the rules of semantic versioning.

Queries are implicit assumed as part of the language, therefore it’s not required to have explicit imperative clauses.

Language Elements

Operators

Each action contains an operator and a predicate. Each operator comes with its own rules (criteria) but all of them should complain about the restrictions of BAQL grammar and syntax. The operators should be extensible and independent one each other.

Pairs Settings

Operator to command changes to the pairs settings of a bot.

PS Operator name

Signal

Operator to specify the bot wants to receive a specified custom signal.

SIG Operator name

Orchestrator

Operator to complement the lifecycle of the bot and its deals.

ORC Operator name

Comments

Comments are not allowed in BAQL.

Grammar

Here is the EBNF-like grammar of the BAQL. The spaces in the grammar definition are for human readability. The grammar described here isn’t meant to be 100% accurate. Here are some missing details:

Main

sentence: prefix actions ((action_separator)* suffix)?

actions: action ((action_separator)+ action)*

prefix: 'BAQL:'

suffix: '!@'

action_separator: ' '

action: operator
      | operator operator_separator predicate

operator: 'PS'
        | 'SIG'
        | 'ORC'

operator_separator: ':'

list_start: '['

list_end: ']'

list_separator: ' '

interval_start: '('

interval_end: ')'

interval_separator: '&'

decimal_number: [-+0-9\.]+(number_multiplier)

number_multiplier: ''
                 | 'K'
                 | 'M'
                 | 'B'
                 | 'T'
                 | 'Q'

Number multipliers:

Multiplier Description Example
K Thousand 1K = 1000
M Million 1M = 1000K
B Billion 1B = 1000M
T Trillion 1T = 1000B
Q Quadrillion 1Q = 1000T

Best Practices using decimal numbers

Examples

ALL_50_BUS

INVALID: Missing starting BAQL tag

BAQL:ALL_50BUS

INVALID: No available actions

BAQL:XXX:ALL_50BUS

INVALID: No available actions

PairsSettings Operator

predicate: categories criteria_separator sort criteria_separator filters

categories: 'ALL'
          | category_list

category_list: category (category_separator category)*

category: 'DEFI'
        | 'ERC'
        | 'NFT'
        | 'DOT'
        | 'BSC'
        | 'ZIL'
        | 'MEME'
        | 'SC'
        | 'SOL'
        | 'POLY'
        | 'AI'
        | 'COS'
        | 'DAO'
        | 'ALGO'
        | 'TZ'
        | 'CHZ'
        | 'AVA'
        | 'WLTS'


category_separator: '&'

criteria_separator: '_'

sort: sort_number criteria_separator sort_keyword reverse_keyword

sort_number: [0-9]+

sort_keyword: 'LCGS'
            | 'LCAR'
            | 'DUSD'
            | 'DBTC'
            | 'HUSD'
            | 'SV'
            | 'BES'
            | 'BUS'
            | 'MC'
            | 'MV'
            | 'MCR'
            | 'CGR'
            | 'WUSD'
            | 'MVMC'
            | 'DVO'
            | 'WVO'
            | 'MVO'
            | 'RV'
            | 'VWAP'
            | 'VWMA'
            | 'DV'
            | 'MCTVL'
            | 'OBTC'
            | 'UBTC'
            | 'ABTC'

reverse_keyword: '.r'
               | ''

filters: filter (interval_separator filter)*

filter: interval_start (greater_equal_filter) filter_keyword (lower_equal_filter) interval_end

greater_equal_filter: range_number lower_equal

lower_equal_filter: lower_equal range_number

lower_equal: '≤'
           | '<='

range_number: decimal_number

filter_keyword: sort_keyword

Sort & Filter keywords:

Sort Name Description Default Sort Order
LCGS LunarCrush Galaxy Scoretm 1
Decimal number from 0.0 to ∞. The larger the better
descending
LCAR LunarCrush AltRanktm 1
Integer number from 1 to ∞. The smaller the better
ascending
DUSD Percentage change in price for the last 24 hours (USD) 2
Decimal number from -∞ to ∞
descending
DBTC Percentage change in price for the last 24 hours (BTC) 2
Decimal number from -∞ to ∞
descending
HUSD Percentage change in price for the last hour (USD) 2
Decimal number from -∞ to ∞
descending
SV Social Volume 1
Decimal number from 0.0 to ∞. The larger the stronger
descending
BUS Bullish Sentiment 1
Decimal number from 1.0 to 5.0. The larger, the stronger the sentiment
descending
BES Bearish Sentiment 1
Decimal number from 1.0 to 5.0. The larger, the stronger the sentiment
descending
MC Market cap 2
Decimal number from 0.0 to ∞
descending
MV Market volume 2
Decimal number from 0.0 to ∞
descending
MCR Market cap rank 2
Integer number from 1 to ∞. The smaller the better
ascending
CGR CoinGecko rank 2
Integer number from 1 to ∞. The smaller the better
ascending
WUSD Percentage change in price for the last 7 days (USD) 2
Decimal number from -∞ to ∞
descending
MVMC Ratio between Market Volume and Market cap 3
Decimal number from 0.0 to ∞
descending
DVO Daily Volatility 4
Decimal number from 0.0 to ∞. The larger, the stronger the movement
descending
WVO Weekly Volatility 4
Decimal number from 0.0 to ∞. The larger, the stronger the movement
descending
MVO Monthly Volatility 4
Decimal number from 0.0 to ∞. The larger, the stronger the movement
descending
RV Relative Volume 4
Decimal number from 0.0 to ∞
descending
VWAP Volume Weighted Average Price 4
Decimal number from -∞ to ∞. Difference within current price and VWAP
descending
VWMA Volume Weighted Moving Average 4
Decimal number from -∞ to ∞. Difference within current price and VWMA
descending
DV Percentage change in volume for the last 24 hours 4
Decimal number from -∞ to ∞
descending
MCTVL Market Cap / Total Value Locked 5
Decimal number larger than 0
descending
OBTC Last 90 days BTC’s outperformers 6
Integer number from 1 to ∞. The smaller the better
ascending
UBTC Last 90 days BTC’s underperformers 6
Integer number from 1 to ∞. The smaller the better
ascending
ABTC Last 90 days top performers 6
Integer number from 1 to ∞. The smaller the better
ascending

Supported categories:

Category 1 Description
DEFI DeFi
ERC ERC-20
NFT NFT
DOT DOT ecosystem
BSC BSC ecosystem
ZIL ZIL ecosystem
SC Stable coins
MEME Meme coins
SOL Solana ecosystem
POLY Polygon ecosystem
AI AI
COS Cosmos ecosystem
DAO DAO
ALGO Algorand ecosystem
TZ Tezos ecosystem
CHZ Chiliz ecosystem
AVA Avalanche ecosystem
WLTS Wallets

PairsSettings examples

Check the available Sort and Filters criteria.

BAQL:PS:ALL_50_BUS

BAQL:PS:MEME_25_DUSD

BAQL:PS:ALL_200_MC.r

BAQL:PS:DEFI&NFT_25_DBTC

BAQL:PS:ALL_10_LCAR

BAQL:PS:ALL_7_MCR

BAQL:PS:ALL_10_CGR

Check how to use number multipliers.

BAQL:PS:ALL_50_LCGS_(250M≤MV≤1.2B)

BAQL:PS:ALL_50_LCGS_(250M≤MV≤1.2B)&(0.1≤DBTC≤10)

BAQL:PS:ALL_50_LCGS_(250000000≤MV≤1200000000)&(0.1≤DBTC≤10)

BAQL:PS:ALL_10_LCAR_(750M≤MC)

BAQL:PS:ALL_10_LCAR_(750M<=MC)

BAQL:PS:ALL_10_LCAR_(750000000<=MC)

BAQL:PS:ALL_50_BUS_(101≤LCAR)

BAQL:PS:ALL_7_BUS_(LCAR≤327)

BAQL:PS:ALL_10_BUS_(50≤MCR≤100)

BAQL:PS:ALL_10_MCTVL_(3M≤MC)

BAQL:PS:ALL_10_ZZ

INVALID: PS: Invalid sorting order keyword

BAQL:PS:ALL_LCAR

INVALID: PS: Action malformed

BAQL:PS:ALL_10000000_LCAR

INVALID: PS: Invalid n. of tokens

BAQL:PS:ALL_50_LCGS_(250M≤ZZZZ≤1.2B)

INVALID: PS: Invalid filter keyword

BAQL:PS:ALL_50_LCGS_(250M≤MV≤1.2B)_(0.1≤DBTC≤10)

INVALID: PS: Action malformed

BAQL:PS:ALL_50_LCGS_(DBTC≥10)

INVALID: Invalid interval sign

BAQL:PS:ALL_50_LCGS_(0.1<DBTC)

INVALID: Invalid interval sign

BAQL:PS:ALL_50_LCGS_(10≤DBTC≤0.1)

INVALID: Interval inequality malformed

Signal Operator

predicate: signal_name
         | signal_list

signal_name: [a-zA-Z0-9]+

signal_list: list_start signal_name ((list_separator)+ signal_name)* list_end

Signal examples

Check the available TTP signals.

BAQL:SIG:PETRO

BAQL:SIG:[MCC]

BAQL:SIG:[PETRO LAMBO]

BAQL:SIG:[MCC_MCB]

BAQL:SIG:[MCC LAMBO MCC]

BAQL:SIG:[MCC

BAQL:SIG:[[MCC] [LAMBO]]

BAQL:SIG:__[MCC LAMBO]

Orchestrator Operator

predicate: orchestrator
         | orchestrator_list

orchestrator_list: list_start orchestrator ((list_separator)+ orchestrator)* list_end

orchestrator: orchestrator_provider operator_separator orchestration_command_list

orchestrator_provider: [a-zA-Z0-9]+

orchestration_command_list: orchestration_command (command_separator orchestration_command)?

orchestration_command: orchestration_action orchestration_separator orchestration_reaction

orchestration_separator: '_'

command_separator: '&'

orchestration_action: [a-zA-Z0-9]+

orchestration_reaction: [a-zA-Z0-9]+

Orchestrator examples

Check the available TTP orchestrator providers. See the possible commands using the list of actions and the list of reactions.

BAQL:ORC:[ORIG:SELL_STPCL]

BAQL:ORC:ORIG:SELL_STPCL

BAQL:ORC:BTCS:IN_STT

BAQL:ORC:[ORIG:SELL_STP&BUY_STT]

BAQL:ORC:ORIG:SELL_STP&BUY_STT

BAQL:ORC:[ORIG:SELL_STP&BUY_STT ST:SELL_STPCL&BUY_STT]

BAQL:ORC:[BTCS:OUT_STP&IN_STT ST:SELL_STPCL&BUY_STT]

BAQL:ORC:]ORIG:BUY_STT]

BAQL:ORC:[ORIG:SELL_STP&&SELL_STPCL]

BAQL:ORC:[ORIG:SELL_STP&SELL_STP]

BAQL:ORC:[ORIG:SELL_STP ORIG:SELL_STPCL]

BAQL:ORC:ORIG:SELL_STP&BUY_STT ST:SELL_STPCL&BUY_STT

Combined examples (more than one action together)

BAQL:PS:ALL_3_LCAR SIG:SERPIL

BAQL:PS:ALL_3_LCAR SIG:SERPIL!@

BAQL:PS:ALL_3_LCAR SIG:SERPIL !@

BAQL:PS:ALL_3_LCAR SIG:SERPIL !@ - further text

BAQL:PS:ALL_10_LCGS SIG:LAMBO ORC:[ORIG:SELL_STP&BUY_STT ST:SELL_STPCL&BUY_STT]

BAQL:PS:MEME&DEFI_50_LCGS_(2.17≤BUS) ORC:ORIG:BUY_STT

BAQL:PS:ALL_3_LCAR_SIG:SERPIL

Appendixes

Error codes

Code Meaning
1001 String too long: Max 500 chars
1002 Missing starting BAQL tag
1003 Additional start tags
2001 No available actions
2002 Unsupported action
2003 Multiple occurences of the same action
2004 Nested predicate lists are not supported
2005 Predicate list malformed
2006 Composite predicate malformed
2007 Interval list malformed
2008 Invalid interval sign
2009 Interval inequality malformed
2010 Interval number malformed
2011 Multiple occurrences of the same interval criteria
3001 PS: Action malformed
3002 PS: Unsupported categories
3003 PS: Invalid n. of tokens [1,99999]
3004 PS: Invalid sorting criteria
3005 PS: Invalid sorting order keyword
3006 PS: Unsupported filter
4001 SIG: Invalid signal name format
4002 SIG: Multiple occurrences of the same signal
5001 ORC: Action malformed
5002 ORC: Multiple occurrences of the same orchestrator provider
5003 ORC: Multiple occurrences of the same command action

Available TTP signals

Signal Name Description Exchanges / Markets
SERPIL Serpil signal Binance Spot (BTC & USDT pairs)
Binance USD-M futures (USDT pairs)
MCC Market Cipher Conservative signal Binance USD-M futures (USDT pairs)
Binance COIN-M futures
MCR Market Cipher Risky signal Binance USD-M futures (USDT pairs)
Binance COIN-M futures
MCB Market Cipher Bear (short) signal Binance USD-M futures (USDT pairs)
Binance COIN-M futures
LAMBO Lambo signal Binance Spot (BUSD & USDT pairs)
Binance US Spot (USD pairs)
FFALL FFALL signal Binance Spot (3x DOWN pairs)
METERL METER long signal Binance USD-M futures (USDT pairs)
ByBit USDT Perpetual
METERS METER short signal Binance USD-M futures (USDT pairs)
ByBit USDT Perpetual
SAVAGEL Risk Savage long signal Binance USD-M futures (USDT pairs)
ByBit USDT Perpetual
OKX USDT Perpetual Swaps
SAVAGES Risk Savage short signal Binance USD-M futures (USDT pairs)
ByBit USDT Perpetual
OKX USDT Perpetual Swaps

Available TTP’s Orchestrator Providers

Provider Description Supported Action
ORIG Original TTP Orchestrator BUY & SELL
ST SuperTrend 1H BTC BUY & SELL
STHA2H SuperTrend HA 2H BTC BUY & SELL
AI1H Artificial Intelligence 1H BTC BUY & SELL
AI2H Artificial Intelligence 2H BTC BUY & SELL
AI4H Artificial Intelligence 4H BTC BUY & SELL
T2AI1H Artificial Intelligence 1H TOTAL2 BUY & SELL
T2AI2H Artificial Intelligence 2H TOTAL2 BUY & SELL
T2AI4H Artificial Intelligence 4H TOTAL2 BUY & SELL
STDXY SuperTrend 4H DXY BUY & SELL
STT3 SuperTrend 1H TOTAL3 BUY & SELL
STT34H SuperTrend 4H TOTAL3 (optimised) BUY & SELL
OTH4H SuperTrend 4H OTHERS (optimised) BUY & SELL
PNRT3 PNRT Filter 1H TOTAL3 & OTHERS BUY & SELL
BULLOSC Bull OSC 2H BTC BUY & SELL
BEAROSC Bear OSC 2H BTC BUY & SELL
MC15M MarketCipher 15M div BTC BUY & SELL
MC1H MarketCipher 1H div BTC BUY & SELL
MC4H MarketCipher 4H div BTC BUY & SELL
MC1D MarketCipher 1D div BTC BUY & SELL
HIVE1H Hive 1H bull:60C7MinDiv, bear:7C2MinDiv BUY & SELL
HIVE4H Hive 4H bull:60C7MinDiv, bear:7C2MinDiv BUY & SELL
HIVE1D Hive 1D bull:60C7MinDiv, bear:7C2MinDiv BUY & SELL
RSIRALS RSI ratio LS 1H BUY & SELL
BTCS Bitcoin Season:Altcoin Index between 0 and 24 a IN & OUT
ALTS Altcoin Season: Altcoin Index between 75 and 100 a IN & OUT
EFEAR Fear & Greed Index: between 0 and 24 b IN & OUT
FEAR Fear & Greed Index: between 25 and 49 b IN & OUT
GREED Fear & Greed Index: between 50 and 74 b IN & OUT
EGREED Fear & Greed Index: between 75 and 100 b IN & OUT
WE SELL on Sat 0Hrs, BUY on Mon 0hrs UTC BUY & SELL
TEST Fast shooting ORC for testing purposes BUY & SELL

Available Orchestration Actions

The following are all the actions supported by the bot assistant. See the table above to see which actions are supported by a given orchestrator provider.

Action Description
SELL Signal when the market is rather overbought
BUY Signal when the market is rather oversold
IN Signal when the reference value enters a range
OUT Signal when the reference value exits a range

Available Orchestration Reactions

Reaction Description
STP Stop the bot
STPCL Stop the bot and close bot deals at market price
CL Close bot deals at market price
STPCA Stop the bot and cancel all bot deals
CA Cancel all bot deals
STT Start the bot
STTDL Start the bot and start new deal (single-pair bot)

Previous versions

Notes