Skip to main content

A modification of pybit library to facilitate trading automation and analysis.

Project description

pybit_ms

This library is a modification of the official pybit library, designed to facilitate trading automation and analysis.


Installation Instructions

Install the library using pip with the following command:

pip install pybit_ms

Usage example

Import the BybitAPI class required for interacting with the Bybit's API:

from pybit_ms import BybitAPI    

1. Public endpoint:

First we show how to query a public endpoint, i.e. one that does not require profile authentication. In this example we implement the get_tickers() function which queries the latest price snapshot, best bid/ask price, and trading volume in the last 24 hours.

Initialize the BybitAPI class wit:

api = BybitAPI()

and query with parameters of your choice, for example spot trade, and coin pair BTC-USDT:

api.market.get_tickers(category="spot", symbol="BTCUSDT")

This will display an html table like the one below:

In case we are only interested in the price we can set the only_ticker parameter to True, or set the raw parameter to True for the complete raw request response.

2. Private endpoint:

To query a private endpoint we need to pass our API keys as parameters in the intial BybitAPI client class. Store the API keys in two string variables: public_key and private_key.

Initialize the BybitAPI client class with:

api = BybitAPI(testnet=True, api_key=public_key, api_secret=private_key)

Note:

  • it is always good practice to store the actual keys in a separate file and read them from there when necessary (refer to read_api_keys.py file in the examples folder for an example of how to store and read them).
  • when experimenting for the first times or for simulations you can set the testnet parameter to true and use your Bybit's testnt apikeys to login into the Bybit's Testnet account.

Now we can query private endpoints like looking at our wallet balance with the command get_wallet_balance():

api.account.get_wallet_balance(accountType="UNIFIED", plot=True, raw=False)

Like in this example, if desired this will allow us, through the corresponding parameters, to look at a pie chart of our wallet balance and have formatted response:

Total equity: $105,277.80
BTC: Wallet Balance = 1.001055, USD Value = $95510.41
ETH: Wallet Balance = 1.288068, USD Value = $4329.78
USDT: Wallet Balance = 5439.141664, USD Value = $5437.61


Another fundamental function consists in placing an order. Suppose we want to place a limit order on the BTC-USDT pair in the spot account. Based on the result we got above with the get_tickers() function we could decide to buy a quantity of 0.001 BTC when the its price reaches 96000 USDT. To place this order we simply execute:

api.trade.place_order(category="linear", symbol="BTCUSDT", side="Buy", order_type="limit", qty=0.001, price="96000")

This should return the order id, for example:

'orderId: d38fcc86-c6ce-4fae-9212-f4a5d43269fhs'

All the functions that have been added or modified, and thus differ from the official bybit library can be found in the changes.txt file, which gives details of the modifications. Documentation for these functions is encapsulated in docstrings written within the function declarations.

More advanced use examples can be found in example/trading.ipynb

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybit_ms-0.1.4.tar.gz (28.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pybit_ms-0.1.4-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

Details for the file pybit_ms-0.1.4.tar.gz.

File metadata

  • Download URL: pybit_ms-0.1.4.tar.gz
  • Upload date:
  • Size: 28.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for pybit_ms-0.1.4.tar.gz
Algorithm Hash digest
SHA256 0322b67ca0fed52dc897ea550570d9fb2ff5910a8f02c6663cddc9caf135f867
MD5 7e6fe09ed8cbed25eb41472ca0ee6ad1
BLAKE2b-256 3a8bb692c73e6c8b25fe17510c1d3de97bc5935f7f54e15aeac6e5d5e9047d77

See more details on using hashes here.

File details

Details for the file pybit_ms-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: pybit_ms-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 30.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for pybit_ms-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 894071b06473b0d005cac926ee84c2b43de085d999a09a92a49a4764659d6e22
MD5 2b83fe4d7398a5ae1260e35aa733c362
BLAKE2b-256 85f917f9247d17d8c0896815c49c9f43b1f980f498a885f0b9b8ed57999f78f5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page