Asyncronous Python3 API connector for Bitget's HTTP and Websockets APIs.
Put simply, pyget (Python + Bitget) is a lightweight, fast, asyncronous one-stop-shop
module for the Bitget REST HTTP and WebSocket APIs. It is built using built in asyncio
library and the aiohttp library.
I was never a fan of connectors that used a mosh-pit of various modules that you didn't
want, used up valuable resources and slowed down the connector, particularly with
syncronous code. So I decided to build my own Python3-dedicated connector with very
little external resources (pyget uses only aiohttp package). The goal of the
connector is to provide traders and developers with an easy-to-use, lightning fast
asyncronous API connector module.
pyget was a private module as part of proprietary trading strategies, it was being
actively developed, especially since Bitget was making changes and improvements to
their API on a regular basis. It is compatible up to V1 of the Bitget APIs. It has
now been open-sourced and is offered as a public, true community project.
pyget uses aiohttp for its methods, alongside other built-in modules, such as asyncio,
for high performance asyncronous operations.
Feel free to fork this repository, issue reports for any bugs and add pull requests for any improvements and updates to Bitget API changes.
pyget requires Python 3.9 or higher. The module can be installed manually. Pypi
installation support will be considered.
# Production installation
pip install .
# Developer/Editable installation
pip install -e .
You can retrieve the HTTP and WebSocket classes like so:
import asyncio
from pyget import ExchangeCreate an HTTP session and connect via WebSocket using context manager protocol:
async def main():
async with Exchange() as session:
rest = session.rest(
endpoint='https://api.bitget.com',
api_key='...',
api_secret='...',
passphrase=...,
contract_type='futures',
force_retry=True
)
ws = session.websocket(
endpoint='wss://ws.bitget.com/mix/v1/stream',
subscriptions=['mc.candle1m.ETHUSDT']
)
asyncio.run(main())Information can be sent to, or retrieved from, the Bitget APIs:
async def main():
async with Exchange() as session:
rest = session.rest(...)
# Get symbol ticker.
await rest.do('get_single_symbol_ticker', symbol='BTCUSDT_UMCBL')
# Create five long orders.
orders = [{
'size': '0.1',
'price': i,
'side': 'open_long',
'orderType': 'limit'
} for i in ['5000', '5500', '6000', '6500', '7000']]
# Submit the orders in bulk, asyncronously.
await self.rest.do('batch_order',
symbol = 'BTCUSDT_UMCBL',
marginCoin = 'USDT',
orderDataList = orders
)
asyncio.run(main())Check out the example python files, in the examples directory, for
more information, documentation and examples on available endpoints
and methods for the HTTP and WebSocket classes.
I'm pretty responsive here on Github.
Thanks goes to these wonderful people (emoji key):
APF20 💻 📖 |
This project follows the all-contributors specification. Contributions of any kind welcome!
I work on pyget in my spare time. If you like the project and want to donate,
you can do so to the following addresses:
SOL: HoUMsBKUESB9fsVTNtT4jYGnAzTAH9LNpZHjXvPiZ5Tb
BTC: bc1q4y230tg3rrhty9zxwpm63g5sgaqxw83xuwahjk
ETH: 0x06fd9aad799c5f094ce8c941fae9b81967cd8323