Skip to main content

Python3 Bybit HTTP/WebSocket API Connector

Project description

pybit

All Contributors

Build Status Build Status Build Status contributions welcome

Python3 API connector for Bybit's HTTP and Websockets APIs.

About

Put simply, pybit (Python + Bybit) is a lightweight one-stop-shop module for the Bybit HTTP and WebSocket APIs. I was personally never a fan of auto-generated connectors that used a mosh-pit of various modules you didn't want (sorry, bravado) and wanted to build my own Python3-dedicated connector with very little external resources. The goal of the connector is to provide traders and developers with an easy-to-use high-performing module that has an active issue and discussion board leading to consistent improvements.

Development

As a user of the module myself, pybit is being actively developed, especially since Bybit is making changes and improvements to their API on a daily basis (we're still missing some key functions such as bulk order submission or withdrawals). pybit uses requests and websocket-client for its methods, alongside other built-in modules. Anyone is welcome to branch/fork the repository and add their own upgrades. If you think you've made substantial improvements to the module, submit a pull request and I'll gladly take a look.

Installation

pybit requires Python 3.6.1 or higher. The module can be installed manually or via PyPI with pip:

pip install pybit

How to Use

You can retrieve the HTTP and WebSocket classes like so:

from pybit import HTTP, WebSocket

Create an HTTP session and connect via WebSocket:

session = HTTP(
    endpoint='https://api.bybit.com', 
    api_key='...',
    api_secret='...'
)
ws = WebSocket(
    endpoint='wss://stream.bybit.com/realtime', 
    subscriptions=['order', 'position'], 
    api_key='...',
    api_secret='...'
)

Information can be sent to, or retrieved from, the Bybit APIs:

# Get orderbook.
session.orderbook(symbol='BTCUSD')

# Create five long orders.
orders = [{
    'symbol': 'BTCUSD', 
    'order_type': 'Limit', 
    'side': 'Buy', 
    'qty': 100, 
    'price': i,
    'time_in_force': 'GoodTillCancel'
} for i in [5000, 5500, 6000, 6500, 7000]]

# Submit the orders in bulk.
session.place_active_order_bulk(orders)

# Check on your order and position through WebSocket.
ws.fetch('order')
ws.fetch('position')

Check out the example python files for more information on available endpoints and methods, and more documentation on the HTTP methods can be found here: https://github.com/verata-veritatis/pybit/blob/master/docs/HTTP.md.

Contact

You can reach out to me via Telegram: @verataveritatis. I'm pretty active on the BybitAPI Telegram group chat.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


verata-veritatis

💻 📖

Todd Conley

🤔

This project follows the all-contributors specification. Contributions of any kind welcome!

Project details


Download files

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

Files for pybit, version 1.1.4
Filename, size File type Python version Upload date Hashes
Filename, size pybit-1.1.4.tar.gz (18.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page