Superalgos Goes Perps on Bybit!

A first iteration to start trading Perpetual and Inverse markets on Bybit!

Hey there, it’ Bybit Perpetual Inverse BIT/USD what you are watching!

Ever since I started using Superalgos I have always felt as a limitation the use of spot markets only. Of course exchanges like Binance — with over 500 crypto trading pairs on its platform — are wonderful, and have contributed significantly to the growth of the crypto sector letting people trade thousands of pairs, some of them even a bit exotic.

But now the wait is over and I want to present a first iteration in the Superalgos codebase that will allow users to create trading bots in Bybit and take advantage of the Perpetual and Inverse markets!

This article is divided into 4sections:

  • Section 1 is a brief description of the SA install process.
  • Section 2 covers Perpetual Linear markets.
  • Section 3 covers Perpetual Inverse markets.
  • Section 4 gives an overview about the new parameters in SA.

This article will not only cover the basic configurations but will also try to give you some insights about how to overcome possible issues.

I’m not explaining what a contract is, what an inverse market is or how to make or lose money in exchanges. It’s up to you to make the necessary research.

DICLAIMER: Futures/Leveraged Markets are extremely risky. It means users can amplify the size of bids and for most users this means losing their capital much faster. Superalgos is a tool and bears no responsibility for any losses incurred.

If you don’t have an account on Bybit and would like to sign up, please use my referral link:

Do not worry! Everything is kept anonymous, and it’s a way to help me keep contributing to Superalgos, and both of us will receive a Welcome Bonus!

SECTION 1. -> Superlagos Installation

I’m not going too in depth here. If you’re not familiar with installing SA, make sure you follow the instructions on the README file on the official Github repository explaining the installation process more in detail.

For my needs I will make a classic SA install in Windows 10.
I have already installed the pre-requisites like Git and NodeJS on my PC and I have a GitHub account with my Personal Access Token set up.

Let’s start then from my fork:
Obviously for you it will be the address of your fork.

This is my SA fork in Github

Once you have your SA fork in Github, then the process is quite easy and straightforward. We just need to clone the repository (sometimes called repo) and run a couple of scripts to set up SA.

I’m installing SA on my Desktop to keep things easy. To do that, I simply open my Terminal (I use Git Bash that should be installed along with Git) and from the Desktop folder I give the following command in sequence (waiting for each command to complete):

git clone   
cd superalgos
git checkout develop
node setup
node setup GitUser PesonalToken

Below there is a screenshot of the commands used to complete the install.

First give the node setup command

Note: a bug in the node setupPlugins may prevent the Upstream to be set up properly. Check it with git remote -v command. You can add it later if needed!
You can follow
the issue here.

Now that everything is in place all we have to do is to launch SA with the commandnode platformand a new window of your default browser should pop up confirming SA is up and running.

SECTION 2. -> Setting up Bybit Exchange Perpetual Linear

Superalgos Welcome Tutorial

A recent upgrade in the code of SA has made the process of setting up the Perpetual Linear markets on Bybit a breeze! Simply use the appropriate codeName in the exchange node and add your favorite pairs.

In this article I’m using the Tested Exchangess Workspace to have a clean environment and I’m going to set up the pair BIT/USDT. I’m also using the Bybit testnet/sandBox but you can just delete that line of code if not needed.

Exchange config:

"codeName": "bybit",
"sandBox": "true"
Fetching candles for BIT/USDT in Bybit Perpetual Linear market

We can now just proceed as usual, setting the correct date from which start to pull candles and wait a bit for the magic to happen. After all candles are fetched we can open the chart and check everything is working, candles are plotted!

Candles are fetched!

Now let’s have a look at the Bybit Exchange. It’s is a very advanced exchange with the ability to set up many different options. One of the many useful options lets you decide if to have an Hedge Mode or a One Way Mode when trading. For this article I will use a classic One Way Mode.
The difference between the two modes is that in the Edge Mode users can open Long and Short position at the same time. I would say this is amazing to keep your position in full control!

One Way Mode set up

Let’s now try to run a Live Strategy. Bring up your favorite one or simply create a new one from scratch to quickly test the capabilities of SA and run it.

Now, if you have followed my set up, you will face an error …. :-(

The error reported in CLI is the following:

*********** ['2022-04-27T15:13:03.836Z',194,'Exchange API','[ERROR] createOrder -> Error = bybit {"ret_code":130001,"ret_msg":"position idx not match position mode","ext_code":"","ext_info":"","result":null,"time_now":"1651072383.541214","rate_limit_status":99,"rate_limit_reset_ms":1651072383537,"rate_limit":100}'] @ Masters-Low-Frequency-Trading

It clearly says what the issue is:

"ret_msg":"position idx not match position mode"

What we have to do here is to search for this error in the Bybit API Manual:

As you can see in Bybit API docs, we should tell SA to connect to the exchange specifying that parameter or make sure the default value used by CCXT matches the one set by us in the exchange. Basically that parameter specifies how your position is treated when placing concurring orders.

I can see you asking “But how….?!?”

Well, thanks to the recent improvement to the SA code this is extremely easy. In fact, we can now just add and pass that parameter to our connection.

Take the Crypto Exchange node, expand it and open the Market config:

SA can now accept a new object in that config. The object is called positionParams and lets you pass what we need now to fine tune the connection to the exchange. So let’s give it a try and copy the following code:

"codeName": "BIT/USDT",
"positionParams": {
"position_idx": 0

Now let’s try again to run our strategy and check if the issue has gone away….

After few minutes we can check there are no more errors in the CLI and checking in the exchange we can see our order was nicely placed! It’s simply amazing, yeah!

A market order sent from SA platform!

And we can check in SA chart too!

Market Orders popping up in SA chart

Connection with the exchange is working and we are able to place Live orders in the exchange. Nothing left here to do, let’s then move to the Inverse Market.

SECTION 3. -> Setting up Bybit Exchange Perpetual Inverse

Now that we have just set up a Linear Market in Bybit we can move forward and check if we can connect to Perpetual Inverse Markets.
The pair will be the same BIT/USD but with a subtle difference because now the pair is quoted in real USD on not in USDT and also:

  • Linear Contracts are settled in Quoted Asset -> BIT/USDT:USDT
  • Inverse Contracts are settled in Base Asset -> BIT/USD:BIT
It says it’s Inverse Perpetual

Let’s now add a new exchange, we do not want to mess with the one just installed in case things are not going right.

So, as before, let’s quickly add a new exchange, name it as you prefer, add the trading pair BIT/USD and install the market.

Will SA fetch candles? I’m not sure ….

Oh no … it looks like we have connection errors …

The error says that “Param validation for 'limit' failed”. As before we just need to search for this message in the Bybit API Manual and set an appropriate value.

When searching don’t get confused. In the exchange “limit” is used in many different ways but looking at the error it should be clear that it is about the connection and not about orders.

BadRequest: bybit {"ret_code":10001,"ret_msg":"Param validation for 'limit' failed

So let’s update our config setting up that parameter but first let’s also take a look at the CCXT library that SA uses to connect to the exchange, we are now dealing with inverse markets… maybe we can find something useful in the CCXT code used to connect to the exchange.

Are you the defaultType I was waiting for so long?

A little search in the CCXT code and we can find exactly what we were looking for! It’s clearly written that in Bybit we can have different defaultType of connection, so we just need to tell to SA we would like to use the Inverse Market. Now that we have everything we need, let’s update the config of the Crypto Exchange:

"codeName": "bybit",
"limit": 50,
"options": {
"adjustForTimeDifference": "true",
"defaultType": "inverse"
Advanced Crypto Exchange config

As you can see there are new parameters and an object called options that we can use to specify the defaultType of the market that in our case in Inverse.

Let’s now try again to fetch the candles and fingers crossed…

No more errors and candles are fetched!
Tasks are running fine
Candles are plotted in the chart

Now let’s run our strategy to test the connection:

Position taken!

Orders are successfully sent to the exchange!

It’s simply beautiful!

There is nothing more to do here, just explore, test and enjoy this new SA ability!

SECTION 4. -> Parameters Overview and Few Considerations

With the recent updates in the code we now have the ability to fine tune the connection to the exchange and also the way an order is placed. Here you can find a compact overview.


codeName:   // Set the exchange codenamesandBox:    // Set the sandBox modemaxRate:    // Set numbers of max candles before savinglimit:      // Exchange specific parameterrateLimit:  // Set the rate limit for the connectionhostname:   // Set a custom hostnameoptions:    // An object that accept parameters the exchange need


positionParams: // Object that accept parameters the exchange needs


Now SA can send parameters along with orders so when managing a position under a Perpetual Contract we can specify that the order is a reduceOnly for example. Every exchange has its own parameters.

orderParams: // Object that can accept a reduceOnly param


All the logic behind how Superalgos handles this new features, that is the ability to connect and trade in Perpetual Markets, is extensively tested.
What is still missing is the ability to perform meaningful backtest on these markets taking into account the leverage and the liquidation issue.
So all the calcs that are needed when trading in these kind of markets are left to the final user.

As usual I show you what can be done, then the road is yours. Take care!

If you enjoyed this article and want to support my contributions to the project then you can simply make a new account in Bybit using my referral link. Both me and you will receive a welcome bonus. As for every exchange everything is anonymous and nothing is collected:

Bybit sign up →

Superalgos official Telegram chat:



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store