Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Notbank Python SDK

main page

sign up in Notbank.

Installation

To install Notbank use pip

pip install notbank

Documentation

This sdk makes use of the api of Notbank.

Quick start

Client creation

There are two communication protocols supported by the Notbank client. Communication via websocket, and via rest. Communication via websocket requires connection and permits subscriptions, other than that they are equivalent.

from notbank_python_sdk.requests_models import *
from notbank_python_sdk.client_connection_factory import new_rest_client_connection
from notbank_python_sdk.error import NotbankException
from notbank_python_sdk.notbank_client import NotbankClient

try:
    # a rest client via http
    rest_connection = new_rest_client_connection()
    client = NotbankClient(rest_connection)
except NotbankException as e:
    print(e)

Error handling

All internal notbank client and notbank server errors inherit from NotbankException, and all client methods may throw it (e.g. invalid request, request timeout, ...)

# client : NotbankClient : ....
try:
    orderbook = client.get_order_book(OrderBookRequest("BTCUSDT", 1, 1))
except NotbankException as e:
    print(e)

Put order at the top of book example

import random
from decimal import Decimal

from notbank_python_sdk.notbank_client import NotbankClient
from notbank_python_sdk.client_connection_factory import new_rest_client_connection

account_id: int = 13  # must be user account id

# instantiate client
connection = new_rest_client_connection()
client = NotbankClient(connection)

# authentication (same for rest client or websocket client)
authenticate = client.authenticate(
    AuthenticateRequest(
        api_public_key="api-public-key",
        api_secret_key="api-secret-key",
        user_id="user-id",
    )
)
if not authenticate.authenticated:
    raise Exception("client not authenticated")

# get USDT user balance (also known as position)
positions = client.get_account_positions(
    GetAccountPositionsRequest(account_id))
usdt_balance = None
product = "USDT"
market_pair = "BTCUSDT"
for position in positions:
    if position.product_symbol == product:
        usdt_balance = position
if usdt_balance is None:
    raise Exception("user has no balance")

# define order_amount (between all usdt_balance and half usdt_balance)
total_balance = usdt_balance.amount
quantity_to_spend = total_balance - \
    Decimal(random.random()) * (total_balance/2)

# define order_price (around market top)
orderbook = client.get_order_book(
    OrderBookRequest(market_pair, level=2, depth=5))
top_orderbook = orderbook.bids[0]
delta = Decimal(random.randrange(10, 100))/1000
order_price = top_orderbook.price + delta
order_quantity = quantity_to_spend / order_price

# send order
instrument = client.get_instrument_by_symbol(market_pair)
request = SendOrderRequest(
    instrument=instrument,
    account_id=account_id,
    time_in_force=TimeInForce.GTC,
    side=Side.Buy,
    quantity=order_quantity,
    limit_price=order_price,
    order_type=OrderType.Limit,
)
response = client.send_order(request)

# handle order result
if response.status == SendOrderStatus.REJECTED:
    # order was rejected
    raise Exception("rejected order")
else:
    # order was accepted
    order_id = response.order_id
    print(order_id)

# close client
client.close()

websocket

There are two websocket clients, and can be instanced with the functions new_websocket_client_connection and new_restarting_websocket_client_connection.

The restarting websocket will reconnect forever when the connection goes down unexpectedly, re-authenticating if it was authenticated, and re-subscribing to already stablished subscriptions. While reconnecting, calls to the websocket will throw. For subscriptions, reconnection will call again the snapshot hooks.

from notbank_python_sdk.requests_models import *
from notbank_python_sdk.client_connection_factory import new_websocket_client_connection, new_restarting_websocket_client_connection
from notbank_python_sdk.error import NotbankException
from notbank_python_sdk.notbank_client import NotbankClient

try:
    # a websocket client
    websocket_connection = new_websocket_client_connection()
    client = NotbankClient(websocket_connection)
except NotbankException as e:
    print(e)



try:
    # a restarting websocket client
    restarting_websocket_connection = new_restarting_websocket_client_connection()
    client = NotbankClient(restarting_websocket_connection)
except NotbankException as e:
    print(e)

Release files for notbank 3.0.0a1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for notbank 3.0.0a1
File Size Uploaded
notbank-3.0.0a1.tar.gz 78.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for notbank 3.0.0a1
File Interpreter ABI Platform
notbank-3.0.0a1-py3-none-any.whl Python 3 none any Details

Total release size: 207.0 kB

Release files / notbank-3.0.0a1.tar.gz

Download URL notbank-3.0.0a1.tar.gz
Size 78.2 kB
Tags Source
SHA-256 checksum
How to use checksums
bd6c65bf3cac91a6829d3a656720cb378c75280221f1d18840f347591e183865
BLAKE2b-256 checksum
How to use checksums
c7212147f6eedff008207f3c63b7c24d6c155031d0a283e742e38ec3c8d06626
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.16

Release files / notbank-3.0.0a1-py3-none-any.whl

Download URL notbank-3.0.0a1-py3-none-any.whl
Size 128.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c51875617cd8526e791c74a1324e70c2570f2d56c34a6fc37effe5f9315337b2
BLAKE2b-256 checksum
How to use checksums
4c2dc2875d080a6e369e062071367514966891492c768d18f69cf30d68e16e35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.16
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page