Lets go over how to automate your trades on the ByBit exchange. We begin by creating a webhook on TradingView.To/ByBit which provides us with a connection and some pretty easy commands to control our trading account. This is how it works.
The Syntax: [command] [symbol] [param]=[value]
- command specifies what we will do like buy, close, sell or cancel
- symbol specifies which coin to perform the command on like BTCUSDT. It can be ommitted in some commands like checking the balance.
- param grants us control of specific features like price and quantity. Most parameters are shortened using the first letter such as price can be sent as p=1.234 or price=1.234
- value specifies the param value. Example: quantity=20%. Below are the list of all supported parameters.
-
Price (P)
Sent in percentage or specific value. A market order is placed if the value is not sent -
Quantity (Q - opening OQ and closing CQ)
Can be sent in percentage or specific value. The default is 100% if it is not set -
Category (C - spot, linear or options)
Specifies the symbol category spot, linear or options. The default is linear. -
Leverage (L)
Customizes your trading leverage. -
Hedge
Hedge mode allows you to open both buy and sell trades. This notation is added to a command that specifies the account is in hedge mode while trading derivatives. -
Account (A - unified, contract or spot)
All commands are built to execute on unified accounts as its the default account type. Use this param to specify you are on different account type. -
Type (T - buy, long, 1, sell, short, -1)
You can filter what type of trade to close by adding the type parameter. -
Stop_Loss (SL) and Take_Profit (TP)
Similar to price, you can send percentage or a specific value. Spot market does not allow these parameters as it does not support positions.
For your own testing, you can add :ignore to any command to exclude everything else after the notation. This is useful if you want to add helpful text to see later.
Example:sell BTCUSDT :ignore MC Strategy 1 Minute
Supported Commands
- Opening a trade
- Cancelling an order
- Closing a position in derivatives
- Modifying TP/SL
- Checking the balance
Opening a Trade
Annotations: buy, long, 1, sell, short, -1
Parameters Allowed are P, Q, OQ, C, L, A, SL, TP and Hedge
SPOT
Spot account allows you to exchange a crypto currency for another. You can buy a coin at a lower price and dispose it at a higher price there by making a profit. When you initiate a buy trade of BTCUSDT for instance, you are converting USDT to BTC. When you initiate a sell trade, you are converting BTC to USDT.
-
buy SOLUSDT q=50% category=spot
converts half of the USDT to SOL -
long ADASOL c=SPOT
converts all the SOL to ADA -
-1 ADAUSDT c=spot Q=5
converts 5 ADA to USDT -
{{strategy.order.action}} ADAUSDT c=spot Q=5
buys 5 ADA using USDT when the tradingview strategy goes long and sells 5 ADA when it goes short. See how to generate tradingview alerts.
The price
parameter can be sent to open limit orders. Using Q as percentage fetches the balance of your quote currency. Example: BTCUSDT uses USDT, ETHBTC uses your BTC balance.
Derivatives
With leveraged capability, bybit offers more trading functions to users to trade more amount than they have. This category allows open positions and hedging in the market. You can also trade any number of coins without having to own that particular coin unlike spot.
-
long XRPUSDT quantity=10% L=5
creates a buy position of 10% of your leveraged USDT balance -
sell SOLUSDT OQ=10% p={{plot_1}}
creates a limit order at the specified price. The price is fetched from the second plot of your strategy or indicator on tradingview. If the price is less than the market, the order will be filled immediately.
Cancelling an Order
Annotations: cancel, exit
Parameters Allowed are A and C.
Orders that have not been filled exist in both spot and derivatives market in bybit.
-
cancel XRPUSDT category=SPOT
will cancel all active orders in spot for the XRPUSDT symbol.
Closing a position
Annotations: close, flat and 0 (zero)
Parameters Allowed are Q, CQ, C, A and T
Positions can only exist in the derivatives market, Therefore using a close command where the category is spot will not work.
-
close BTCUSDT q=50% t=long
will partially close half of your BTCUSDT position that is on the long side. -
close ADAUSDT CQ=100%
will fully close your ADAUSDT active position.
Modifying a position
Annotations: update and modify
Parameters Allowed are TP, SL, C, A and T
You can add or change your TP and SL simply by sending this command. Percentages and price values are well accepted.
-
update GMTUSDT sl=3% tp=10% hedge t=sell
will modify the sell trades with the set targets. Note that when in hedge mode, you must specify the type of trade to modify.
View Balance
Annotations: bal, balance, funds
Only parameter allowed is the A
In some cases, a quick check of your balance is important. Instead of specifying the symbol, we specify the coin or leave it empty to see all the balances available.
-
funds
will return all the coins that have a balance greater than zero -
balance USDT
will return your USDT balance
Advanced Use Case
You can also combine commands using TradingView placeholders.
{{strategy.market_position}} SOLUSDT OQ=10% CQ=100% L=5
opens a market position when the strategy says long or short of 10% with 5X leverage the USDT balance and closes the whole position when the strategy says flatSee more about how to generate tradingview alerts using placeholders