Skip to main content

A Python SDK for WhiteBit cryptocurrency exchange API

Project description

A Python SDK for whitebit

License: MIT

Please read whitebit API document before continuing.

API List

v4 is the preferred one to use

Disclaimer

“You acknowledge that the software is provided “as is”. Author makes no representations or warranties with respect to the software whether express or implied, including but not limited to, implied warranties of merchantability and fitness for a particular purpose. author makes no representation or warranty that: (i) the use and distribution of the software will be uninterrupted or error free, and (ii) any use and distribution of the software is free from infringement of any third party intellectual property rights. It shall be your sole responsibility to make such determination before the use of software. Author disclaims any liability in case any such use and distribution infringe any third party’s intellectual property rights. Author hereby disclaims any warranty and liability whatsoever for any development created by or for you with respect to your customers. You acknowledge that you have relied on no warranties and that no warranties are made by author or granted by law whenever it is permitted by law.”

REST API

Setup

Install the Python module:

python3 -m pip install python-whitebit-sdk

Init client for API services. Get APIKey/SecretKey from your whitebit account.

from whitebit import MainAccountClient

account = MainAccountClient(api_key="", api_secret=""))

Following are some simple examples.

See the examples folder for full references.

Create Spot Limit Order

# Create order/spot client
order = OrderClient(api_key="",
                    api_secret="")

# Call SDK function put_limit
print(order.put_limit("BTC_USDT", "sell", "0.1", "40000", True))

Websocket API

Setup

Init bot class and "on_message" method for work with ws responses. Get APIKey/SecretKey from your whitebit account.

class Bot(WhitebitWsClient):
    def __init__(self):
        super().__init__(key="", secret="")

    async def on_message(self, event) -> None:
        logging.info(event)
        

Following are some simple examples.

See the examples folder for full references.

Subscribe on deals topic

class Bot(WhitebitWsClient):
    '''Can be used to create a custom trading strategy/bot'''

    def __init__(self):
        super().__init__(key="", secret="")

    async def on_message(self, event) -> None:
        '''receives the websocket events'''
        if 'result' in event:
            result = event['result']
            match result:
                case 'pong': return
            logging.info(event['result'])
            return
        else:
            method = event['method']
            match method:
                case WhitebitWsClient.DEALS_UPDATE:
                    logging.info(event['params'])
            return


async def main() -> None:
    bot = Bot()
    await bot.get_deals("BTC_USDT", 0, 100)
    await bot.subscribe_deals(["BTC_USDT"])
    while not bot.exception_occur:
        await asyncio.sleep(100)
    return


if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        pass
    finally:
        loop.close()

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

whitebit_python_sdk-1.1.1.tar.gz (166.9 kB view details)

Uploaded Source

Built Distribution

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

whitebit_python_sdk-1.1.1-py3-none-any.whl (387.8 kB view details)

Uploaded Python 3

File details

Details for the file whitebit_python_sdk-1.1.1.tar.gz.

File metadata

  • Download URL: whitebit_python_sdk-1.1.1.tar.gz
  • Upload date:
  • Size: 166.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for whitebit_python_sdk-1.1.1.tar.gz
Algorithm Hash digest
SHA256 ba64a87f42d5bb7f01fe8fd36069884f7fd436ae04163bbacee2dd234a3b1201
MD5 78aa66c23620bd2106d5811689a0ece0
BLAKE2b-256 1354846869c9d4be90a3a9a61c64c7beb892c14deb4ef8095515018f84934cf7

See more details on using hashes here.

File details

Details for the file whitebit_python_sdk-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for whitebit_python_sdk-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 922407886ee3476e6a509d1c30d81ccbde0cd7fb7500e71de08b7203c645759a
MD5 3e11adb74997f6c3d9e2c45782cab33f
BLAKE2b-256 0b9741f5d64c2e7da6fbe1d64ead7ae5b8b9f7301e73697aa408e725c1a8fbe8

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