Skip to main content

Zubr exchange SDK

Project description

Zubr exchange SDK

Simple example

import logging
from pprint import pprint

from zubr import ZubrSDK, OrderType, TimeInForce

zubr_sdk = ZubrSDK(
    api_key='YOUR-API-KEY-HERE',
    api_secret='YOUR-API-SECRET-HERE',
)

logging.basicConfig(level=logging.INFO)

context = {
    'order_placed': False,
    'sell_price': '0',
}


def sell_and_cancel(message):
    print(f'order placed: {message}')
    order_id = message['result']['value']

    # Cancel order
    zubr_sdk.cancel_order(
        order_id=order_id,
        callback=lambda x: (
            print(f'Order cancelled: {x}')
        ),
    )


def sell_and_replace(message):
    print(f'order placed: {message}')
    order_id = message['result']['value']

    # Replace order
    zubr_sdk.replace_order(
        order_id=order_id,
        price=context['sell_price'],
        size=2,
        callback=lambda x: (
            print(f'Order replaced: {x}')
        ),
    )


# Fetch orderbook
@zubr_sdk.subscribe_orderbook
def on_orderbook(message):
    print('orderbook:')
    pprint(message)

    if context['order_placed']:
        return

    instrument_id, orders = list(message['value'].items())[0]
    sell_price = max(x['price'] for x in orders['asks'])
    context['sell_price'] = sell_price

    # Place and replace
    zubr_sdk.sell(
        instrument_id=instrument_id,
        price=sell_price,
        size=1,
        order_type=OrderType.LIMIT,
        time_in_force=TimeInForce.GTC,
        callback=sell_and_replace,
    )

    # Place and cancel
    zubr_sdk.sell(
        instrument_id=instrument_id,
        price=sell_price,
        size=1,
        order_type=OrderType.LIMIT,
        time_in_force=TimeInForce.GTC,
        callback=sell_and_cancel,
    )

    context['order_placed'] = True


# Fetch last trades
@zubr_sdk.subscribe_last_trades
def on_last_trades(message):
    print('last trades:')
    pprint(message)


zubr_sdk.run_forever()

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

zubr_temp-0.2.4.tar.gz (5.1 kB view details)

Uploaded Source

File details

Details for the file zubr_temp-0.2.4.tar.gz.

File metadata

  • Download URL: zubr_temp-0.2.4.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.48.2 CPython/3.8.2

File hashes

Hashes for zubr_temp-0.2.4.tar.gz
Algorithm Hash digest
SHA256 97f87d29fb7f8c92fa50a0f970d95308ae20778b0fb0233f61b5bc4ae321cabf
MD5 c721787b383a4d5ecae98a692bf68bb7
BLAKE2b-256 836753300041524eaeb8b87a72138d0f6769223ec343c0042909920410628b21

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