beatzxbt / bybit-smm

bybit simple market maker
MIT License
398 stars 125 forks source link

Bybit Simple Market Maker

This is a simple market making bot for Bybit.

DISCLAIMER: Nothing in this repository constitutes financial advice (and therefore, please use at your own risk). It is tailored primarily for learning purposes, and is highly unlikely you will make profits trading this strategy. If you are not ready to risk your own capital, but want to try it out, you can sign up for Bybit's Testnet. BeatzXBT will not accept liability for any loss or damage including, without limitation to, any loss of profit which may arise directly or indirectly from use of or reliance on this software.

Getting Started

Clone the repository

In the terminal run the following commands:

# Change directories to your workspace
$ cd /path/to/your/workspace

# Clone the repository
$ git clone git@github.com:beatzxbt/bybit-smm.git

# Change directories into the project
$ cd bybit-smm

Note: Each terminal command going forward will be run within the main project directory.

Set Up the environment

Copy .env.exmaple to .env. This is where we are going to store our API keys:

$ cp .env.example .env

Next, you will need to create a Bybit account. If you are not ready to trade real money, you can create a testnet account with no KYC required by signing up at testnet.bybit.com.

Once you have created your Bybit account, generate API key and secret following this guide. Once you have your API keys, edit the .env file that you generated earlier, filling in your credentials:

API_KEY=YOUR_API_KEY_HERE
API_SECRET=YOUR_API_SECRET_HERE

The account must be a Unified Trading Account (UTA).

Optional: If you are using the testnet to trade, set the TESTNET flag to True within the .env file:

TESTNET=True

Install the requirements

Optional: If you are familiar with virtual environments, create one now and activate it. If not, this step is not necessary:

$ virtualenv venv
$ source venv/bin/activate

Install the package requirements:

$ pip install -r requirements.txt

Configure the trading parameters

Next, we are going to configure the parameters that actually determine which market we are making, and how the trader should behave.

Sensible defaults are set in parameters.yaml.example. Copy it over to your parameter.yaml file to get started:

$ cp parameters.yaml.example parameters.yaml

The parameters.yaml file is gitignored, and can be configured for each environment that you are trading in separately.

Each of the configurable parameters are explained below in more detail

Master offsets

Market Maker Settings

Settings regarding the functionality of the core market making script

Volatility settings

The volatility indicator used to define the trading range is Bollinger Band Width.

Running the bot

To run the the bot, once your .env and parameters.yaml file are configured, simply run:

(venv) $ python3 -m main

NOTE: If you are using MacOS, you may run into the following error:

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)

The fix is simple.

Strategy Design/Overview

  1. Prices from Bybit (and optionally Binance) are streamed using websockets into a common shared class.
  2. Features are calculated from the updated market data, and a market maker class generates optimal quotes
    • Multiple features work on comparing different mid-prices to each other (trying to predict where price is likely to go).
    • Both bid/ask skew is then calculated, based on the feature values but corrected for the current inventory (filled position).
    • Prices & sizes are generated based on the skew, with edge cases for extreme inventory cases.
    • Spread is adjusted for volatility (as a multiple of the base spread), widening when short term movements increase.
    • Quotes are generated using all the above, formatted for the local client and returned.
  3. Orders are sent via a Order Management System (currently disabled), which transitions between current and new states, and tries to do so in the most ratelimit-efficient way possible.

Contributions

Please create issues to flag bugs or suggest new features and feel free to create a pull request with any improvements.

If you have any questions or suggestions regarding the repo, or just want to have a chat, my handles are below 👇🏼

Twitter: @beatzXBT | Discord: gamingbeatz

Donations

If you want to buy me a coffee (much appreciated :D), my addresses are below:

-USDC: 0x84a16e23c38f84709395720b08348d86883acf81 (Arbitrum)

-USDC: 9mJw3Wyifr19vqHJp6SLK86sDXrE6Ayk96U7F4Wano2H (Solana)

-ETH: 0x84a16e23c38f84709395720b08348d86883acf81 (ERC20)

If you are feeling generous but cant send over any of the above chains for whatever reason, feel free to DM on Twitter/Discord and we can sort something out :)