API Reference

Detailed API Reference for BSX Exchange SDK.

bsx_py.instance

class bsx_py.instance.Environment(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

TESTNET = 'https://api.testnet.bsx.exchange'
MAINNET = 'https://api.bsx.exchange'
class bsx_py.instance.BSXInstance(env, wallet, signer)[source]

Bases: object

The client interface to interact with BSX Exchange

BSXInstance will handle signing, authenticating, API key renewal internally.

Each BSXInstance works with only one wallet. If you want to use multiple wallets, just create multiple instances.

static from_api_key(api_key, api_secret, signer, env)[source]

Initialize a new BSXInstance object using an active API key.

The BSXInstance returned by this method will not be able to submit withdrawal requests

Return type:

BSXInstance

Attributes:

api_key (str): BSX API key

api_secret (str): BSX secret

signer (LocalAccount): signer wallet used to sign requests

env (Environment|str): environment to use (Testnet or mainnet) or the domain in plain text

Raises:

BSXRequestException: If the response status is not “success”.

static from_smart_contract(env, contract_address, signature, nonce, signer)[source]

Initialize a new BSXInstance object using main wallet’s private key

Return type:

BSXInstance

Attributes:

env (Environment|str): environment to use (Testnet or mainnet) or the domain in plain text

contract_address (str): multi sig wallet address

signature (str): signature to use. Please read https://api-docs.bsx.exchange/reference/sign-messages for how to generate the signature

signer (LocalAccount): signer wallet used to sign requests

Raises:

BSXRequestException: If the response status is not “success”.

__init__(env, wallet, signer)[source]

Initialize a new BSXInstance object using main wallet’s private key

Attributes:

env (Environment|str): environment to use (Testnet or mainnet) or the domain in plain text

wallet (LocalAccount): main wallet

signer (LocalAccount): signer wallet used to sign requests

Raises:

BSXRequestException: If the response status is not “success”.

create_order(params)[source]

Create a new order

Return type:

Order

Attributes:

params (CreateOrderParams): object that contains data required to create an order

Return:

Order: created order

Raises:

BSXRequestException: If the response status is not “success”.

create_order_async(params)[source]

Create a new order

Return type:

Order

Attributes:

params (CreateOrderParams): object that contains data required to create an order

Return:

Order: created order

Raises:

BSXRequestException: If the response status is not “success”.

cancel_order(order_id)[source]

Cancel an order by id

Return type:

CancelOrderResult

Attributes:

order_id (str): order_id that need to be cancelled

Return:

CancelOrderResult: cancel result

Raises:

BSXRequestException: If the response status is not “success”.

cancel_order_async(order_id)[source]

Cancel an order by id

Return type:

CancelOrderResult

Attributes:

order_id (str): order_id that need to be cancelled

Return:

CancelOrderResult: cancel result

Raises:

BSXRequestException: If the response status is not “success”.

cancel_bulk_orders(order_ids)[source]

Cancel multiple orders by ids

Return type:

CancelMultipleOrdersResult

Attributes:

order_ids (list[str]): order_ids that need to be cancelled

Return:

CancelMultipleOrdersResult: cancel result

Raises:

BSXRequestException: If the response status is not “success”.

cancel_bulk_orders_async(order_ids)[source]

Cancel multiple orders by ids

Return type:

CancelMultipleOrdersResult

Attributes:

order_ids (list[str]): order_ids that need to be cancelled

Return:

CancelMultipleOrdersResult: cancel result

Raises:

BSXRequestException: If the response status is not “success”.

cancel_all_orders(product_id)[source]

Cancel all open orders of a given product

Return type:

CancelMultipleOrdersResult

Attributes:

product_id (str): the product that it’s orders need to be cancelled

Return:

CancelMultipleOrdersResult: cancel result

Raises:

BSXRequestException: If the response status is not “success”.

cancel_all_orders_async(product_id)[source]

Cancel all open orders of a given product

Return type:

CancelMultipleOrdersResult

Attributes:

product_id (str): the product that it’s orders need to be cancelled

Return:

CancelMultipleOrdersResult: cancel result

Raises:

BSXRequestException: If the response status is not “success”.

get_all_open_orders(product_id)[source]

Get all open orders of a given product

Return type:

OrderListingResult

Attributes:

product_id (str): the product id

Return:

CancelMultipleOrdersResult: contains a list of open orders

Raises:

BSXRequestException: If the response status is not “success”.

get_all_open_orders_async(product_id)[source]

Get all open orders of a given product

Return type:

OrderListingResult

Attributes:

product_id (str): the product id

Return:

CancelMultipleOrdersResult: contains a list of open orders

Raises:

BSXRequestException: If the response status is not “success”.

get_order_history(params)[source]

Get order history

Return type:

OrderListingResult

Attributes:

params (GetOrderHistoryParams): parameters to get order history

Return:

OrderListingResult: contains a list of orders

Raises:

BSXRequestException: If the response status is not “success”.

get_order_history_async(params)[source]

Get order history

Return type:

OrderListingResult

Attributes:

params (GetOrderHistoryParams): parameters to get order history

Return:

OrderListingResult: contains a list of orders

Raises:

BSXRequestException: If the response status is not “success”.

submit_withdrawal_request(params)[source]

Submit withdrawal request

Return type:

bool

Attributes:

params (WithdrawParams): parameters to create withdrawal request

Return:

bool: whether the withdrawal request was created successfully or not

Raises:

BSXRequestException: If the response status is not “success”.

submit_withdrawal_request_async(params)[source]

Submit withdrawal request

Return type:

bool

Attributes:

params (WithdrawParams): parameters to create withdrawal request

Return:

bool: whether the withdrawal request was created successfully or not

Raises:

BSXRequestException: If the response status is not “success”.

get_portfolio_detail()[source]

Get portfolio detail

Return type:

Portfolio

Return:

Portfolio: portfolio detail of the current user

Raises:

BSXRequestException: If the response status is not “success”.

get_portfolio_detail_async()[source]

Get portfolio detail

Return type:

Portfolio

Return:

Portfolio: portfolio detail of the current user

Raises:

BSXRequestException: If the response status is not “success”.

batch_update_orders(params)[source]

Update orders in batch

Return type:

BatchOrderUpdateResponse

Attributes:

params (BatchOrderUpdateParams): update orders parameters

Return:

BatchOrderUpdateResponse: update result. The order of items in the result is the same as the order of items in the input params

Raises:

BSXRequestException: If the response status is not “success”.

batch_update_orders_async(params)[source]

Update orders in batch

Return type:

BatchOrderUpdateResponse

Attributes:

params (BatchOrderUpdateParams): update orders parameters

Return:

BatchOrderUpdateResponse: update result. The order of items in the result is the same as the order of items in the input params

Raises:

BSXRequestException: If the response status is not “success”.

get_user_trade_history(params)[source]

Get user’s trade history

Return type:

GetTradeHistoryResponse

Attributes:

params (GetTradeHistoryParams): filter parameters

Return:

GetTradeHistoryResponse: trade history

Raises:

BSXRequestException: If the response status is not “success”.

get_user_trade_history_async(params)[source]

Get user’s trade history

Return type:

GetTradeHistoryResponse

Attributes:

params (GetTradeHistoryParams): filter parameters

Return:

GetTradeHistoryResponse: trade history

Raises:

BSXRequestException: If the response status is not “success”.

get_products()[source]

Get all markets

Return type:

list[Product]

Return:

list[Product]: list of all markets

Raises:

BSXRequestException: If the response status is not “success”.

get_products_async()[source]

Get all markets

Return type:

list[Product]

Return:

list[Product]: list of all markets

Raises:

BSXRequestException: If the response status is not “success”.

get_funding_history(params)[source]

Get funding rate history

Return type:

GetFundingHistoryResponse

Attributes:

params (GetFundingHistoryParams): filter parameters

Return:

GetFundingHistoryResponse: funding rate history

Raises:

BSXRequestException: If the response status is not “success”.

get_funding_history_async(params)[source]

Get funding rate history

Return type:

GetFundingHistoryResponse

Attributes:

params (GetFundingHistoryParams): filter parameters

Return:

GetFundingHistoryResponse: funding rate history

Raises:

BSXRequestException: If the response status is not “success”.

get_api_key_list()[source]

Get all active API keys

Return type:

GetAPIKeysResponse

Return:

GetAPIKeysResponse: API keys list

Raises:

BSXRequestException: If the response status is not “success”.

get_api_key_list_async()[source]

Get all active API keys

Return type:

GetAPIKeysResponse

Return:

GetAPIKeysResponse: API keys list

Raises:

BSXRequestException: If the response status is not “success”.

delete_user_api_key(api_key)[source]

Delete an API key

Return type:

str

Attributes:

api_key (str): API key to be deleted

Return:

str: API key that was deleted

Raises:

BSXRequestException: If the response status is not “success”.

delete_user_api_key_async(api_key)[source]

Delete an API key

Return type:

str

Attributes:

api_key (str): API key to be deleted

Return:

str: API key that was deleted

Raises:

BSXRequestException: If the response status is not “success”.

create_user_api_key(name='')[source]

Create a new API key

Return type:

APIKey

Attributes:

name (str): name of the new API key

Return:

APIKey: new API key info

Raises:

BSXRequestException: If the response status is not “success”.

create_user_api_key_async(name='')[source]

Create a new API key

Return type:

APIKey

Attributes:

name (str): name of the new API key

Return:

APIKey: new API key info

Raises:

BSXRequestException: If the response status is not “success”.

bsx_py.common.types.account

class bsx_py.common.types.account.WithdrawParams(amount, nonce)[source]

Bases: object

Contains parameters for creating a withdrawal request

Args:

amount (Decimal): Token amount to withdraw. For USDC, the minimum amount is 2 USDC. We currently only allow withdraw up to min(settled_usdc_balance, free_collateral).

nonce (int): timestamp in nanosecond that is larger than (request received time - 10 minutes)

amount: Decimal
nonce: int
__init__(amount, nonce)
class bsx_py.common.types.account.PortfolioSummary(margin_use, account_leverage, in_liquidation, free_collateral, total_account_value, total_notional, usdc_balance, unsettled_usdc, realized_pnl, total_initial_margin, total_maintenance_margin, has_pending_withdrawal)[source]

Bases: object

margin_use: Decimal
account_leverage: Decimal
in_liquidation: bool
free_collateral: Decimal
total_account_value: Decimal
total_notional: Decimal
usdc_balance: Decimal
unsettled_usdc: Decimal
realized_pnl: Decimal
total_initial_margin: Decimal
total_maintenance_margin: Decimal
has_pending_withdrawal: bool
static from_dict(data)[source]
Return type:

PortfolioSummary

__init__(margin_use, account_leverage, in_liquidation, free_collateral, total_account_value, total_notional, usdc_balance, unsettled_usdc, realized_pnl, total_initial_margin, total_maintenance_margin, has_pending_withdrawal)
class bsx_py.common.types.account.Position(product_index, product_id, net_size, avg_entry_price, initial_margin_requirement, maintenance_margin_requirement, liquidation_price, unrealized_pnl, mark_price, leverage, unsettled_funding, funding_index, quote_balance)[source]

Bases: object

product_index: int
product_id: str
net_size: Decimal
avg_entry_price: Decimal
initial_margin_requirement: Decimal
maintenance_margin_requirement: Decimal
liquidation_price: Decimal
unrealized_pnl: Decimal
mark_price: Decimal
leverage: Decimal
unsettled_funding: Decimal
funding_index: Decimal
quote_balance: Decimal
static from_dict(data)[source]
Return type:

Position

__init__(product_index, product_id, net_size, avg_entry_price, initial_margin_requirement, maintenance_margin_requirement, liquidation_price, unrealized_pnl, mark_price, leverage, unsettled_funding, funding_index, quote_balance)
class bsx_py.common.types.account.OrderStats(total_orders, total_done_orders, total_open_orders, total_pending_orders)[source]

Bases: object

total_orders: Decimal
total_done_orders: Decimal
total_open_orders: Decimal
total_pending_orders: Decimal
static from_dict(data)[source]
Return type:

OrderStats

__init__(total_orders, total_done_orders, total_open_orders, total_pending_orders)
class bsx_py.common.types.account.ProductStats(total_orders, total_done_orders, total_open_orders, total_pending_orders)[source]

Bases: object

total_orders: Decimal
total_done_orders: Decimal
total_open_orders: Decimal
total_pending_orders: Decimal
static from_dict(data)[source]
Return type:

ProductStats

__init__(total_orders, total_done_orders, total_open_orders, total_pending_orders)
class bsx_py.common.types.account.PortfolioProduct(product_id, stat)[source]

Bases: object

product_id: str
stat: ProductStats
static from_dict(data)[source]
Return type:

PortfolioProduct

__init__(product_id, stat)
class bsx_py.common.types.account.TradingStats(total_trading_volume)[source]

Bases: object

total_trading_volume: Decimal
static from_dict(data)[source]
Return type:

TradingStats

__init__(total_trading_volume)
class bsx_py.common.types.account.PortfolioStats(order_stats, products, trading_stats, total_deposit, total_withdraw)[source]

Bases: object

order_stats: OrderStats
products: list[PortfolioProduct]
trading_stats: TradingStats
total_deposit: Decimal
total_withdraw: Decimal
static from_dict(data)[source]
Return type:

PortfolioStats

__init__(order_stats, products, trading_stats, total_deposit, total_withdraw)
class bsx_py.common.types.account.Portfolio(account, summary, positions, stats)[source]

Bases: object

account: str
summary: PortfolioSummary
positions: list[Position]
stats: PortfolioStats
static from_dict(data)[source]
__init__(account, summary, positions, stats)
class bsx_py.common.types.account.APIKey(api_key, api_secret, created_at, updated_at, name, sender, signer)[source]

Bases: object

api_key: str
api_secret: str
created_at: datetime
updated_at: datetime
name: str
sender: str
signer: str
static from_dict(data)[source]
Return type:

APIKey

__init__(api_key, api_secret, created_at, updated_at, name, sender, signer)
class bsx_py.common.types.account.GetAPIKeysResponse(api_keys)[source]

Bases: object

api_keys: list[APIKey]
static from_dict(data)[source]
Return type:

GetAPIKeysResponse

__init__(api_keys)

bsx_py.common.types.market

class bsx_py.common.types.market.Side(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

BUY = 'BUY'
SELL = 'SELL'
static from_str(value)[source]
Return type:

Side

class bsx_py.common.types.market.OrderType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

LIMIT = 0
MARKET = 1
STOP = 2
static from_str(value)[source]
Return type:

OrderType

class bsx_py.common.types.market.OrderStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

PENDING = 'PENDING'
OPEN = 'OPEN'
DONE = 'DONE'
static from_str(value)[source]
Return type:

OrderStatus

class bsx_py.common.types.market.TransferType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

WITHDRAW = 'WITHDRAW'
DEPOSIT = 'DEPOSIT'
static from_str(value)[source]
Return type:

TransferType

class bsx_py.common.types.market.CreateOrderParams(side, type, product_index, price, size, time_in_force, nonce, post_only=False, reduce_only=False, client_order_id=None)[source]

Bases: object

Contains parameters required for creating a new order

Args:

side (Side): The side of the order

type (OrderType): The type of order

product_index (int): Product to place order on. (BTC-PERP=1, ETH-PERP=2, SOL-PERP=3)

price (Decimal): The max or min price limit to buy or sell at

size (Decimal): The amount to buy or sell

time_in_force (str): GTC | IOC | FOK. default is GTC

nonce (int): timestamp in nanosecond that is larger than (request received time - 10 minutes)

post_only (bool): optional; default is false

reduce_only (bool): optional; default is false

client_order_id (str): optional; default is None. Max 32 alphabet characters. Case-insensitive. Must be unique among all open orders of the current user

side: Side
type: OrderType
product_index: int
price: Decimal
size: Decimal
time_in_force: str
nonce: int
post_only: bool = False
reduce_only: bool = False
client_order_id: Optional[str] = None
__init__(side, type, product_index, price, size, time_in_force, nonce, post_only=False, reduce_only=False, client_order_id=None)
class bsx_py.common.types.market.Trade(id, price, size, liquidity_indicator, time, funding_payment, trading_fee, sequencer_fee)[source]

Bases: object

id: str
price: Decimal
size: Decimal
liquidity_indicator: str
time: datetime
funding_payment: Decimal
trading_fee: Decimal
sequencer_fee: Decimal
static from_dict(data)[source]
Return type:

Trade

__init__(id, price, size, liquidity_indicator, time, funding_payment, trading_fee, sequencer_fee)
class bsx_py.common.types.market.Order(id, price, size, product_id, side, type, time_in_force, nonce, post_only, reduce_only, created_at, cancel_reason, reject_reason, cancel_reject_reason, filled_fees, filled_size, status, sender, avg_price, cancel_requested, is_liquidation, initial_margin, last_trades, client_order_id)[source]

Bases: object

Contains information about an order

Args:

id (str): The order ID, should be an uuid

price (Decimal): The original price (in quote unit) of the order. Example 45000.1 (USDC)

size (Decimal): The original size (in base unit) of the order. Example 0.3 (BTC)

product_id (str): The product of the order

side (str): Order’s side. Possible values: BUY, SELL

type (str): Order’s type. Possible values: LIMIT, MARKET, STOP

time_in_force (str): GTC | IOC | FOK

nonce (int): The nonce of the order

post_only (bool): Post-only means the order will only be placed as a maker order. If any part of the order results in taking liquidity, the order will be rejected and no part of it will execute.

reduce_only (bool): Indicates if the order is reduce-only

created_at (datetime): Created at timestamp in nanosecond

cancel_reason (str): The cancel reason (if exists). Possible values: user/admin/insufficient funds/etc

reject_reason (str): The reason reason (if exists)

cancel_reject_reason (str): The cancel reason reason (if exists)

filled_fees (Decimal): The total filled fees (in quote unit - USDC) of the order

filled_size (Decimal): The total filled size (in base unit - BTC) of the order

status (str): PENDING | OPEN | DONE

sender (str): The owner address of the order

avg_price (Decimal): The average price (in quote unit - USDC) of the order

cancel_requested (bool): Indicates if the order is cancel requested

is_liquidation (bool): Indicates if the order is a liquidation order

initial_margin (str): Initial Margin Requirement for the order

client_order_id (str): The client order ID specified by user when creating new orders

id: str
price: Decimal
size: Decimal
product_id: str
side: str
type: str
time_in_force: str
nonce: int
post_only: bool
reduce_only: bool
created_at: datetime
cancel_reason: str
reject_reason: str
cancel_reject_reason: str
filled_fees: Decimal
filled_size: Decimal
status: str
sender: str
avg_price: Decimal
cancel_requested: bool
is_liquidation: bool
initial_margin: str
last_trades: list[Trade]
client_order_id: str
static from_dict(data)[source]
Return type:

Order

__init__(id, price, size, product_id, side, type, time_in_force, nonce, post_only, reduce_only, created_at, cancel_reason, reject_reason, cancel_reject_reason, filled_fees, filled_size, status, sender, avg_price, cancel_requested, is_liquidation, initial_margin, last_trades, client_order_id)
class bsx_py.common.types.market.CancelMultipleOrdersParams(product_ids=None, order_ids=None, nonces=None)[source]

Bases: object

product_ids: Optional[list[str]] = None
order_ids: Optional[list[str]] = None
nonces: Optional[list[int]] = None
__init__(product_ids=None, order_ids=None, nonces=None)
class bsx_py.common.types.market.CancelOrderResult(order_id, nonce, client_order_id)[source]

Bases: object

Returned if an order is cancelled successfully

Args:

order_id (str): Order id of the cancelled order

nonce (int): Nonce of the cancelled order

client_order_id (str): Client order ID of the cancelled order

order_id: str
nonce: int
client_order_id: str
static from_dict(data)[source]
Return type:

CancelOrderResult

__init__(order_id, nonce, client_order_id)
class bsx_py.common.types.market.CancelOrdersResultItem(order_id, nonce, client_order_id)[source]

Bases: object

Returned if an order is cancelled successfully

Args:

order_id (str): Order id of the cancelled order

nonce (int): Nonce of the cancelled order

client_order_id (str): Client order ID of the cancelled order

order_id: str
nonce: int
client_order_id: str
static from_dict(data)[source]
Return type:

CancelOrdersResultItem

__init__(order_id, nonce, client_order_id)
class bsx_py.common.types.market.CancelMultipleOrdersResult(cancelled_orders)[source]

Bases: object

cancelled_orders: list[CancelOrdersResultItem]
static from_dict(data)[source]
Return type:

CancelMultipleOrdersResult

__init__(cancelled_orders)
class bsx_py.common.types.market.OrderListingResult(orders)[source]

Bases: object

orders: list[Order]
static from_dict(data)[source]
Return type:

OrderListingResult

__init__(orders)
class bsx_py.common.types.market.GetOrderHistoryParams(product_id=None, start_time=None, end_time=None, limit=100, statuses=None, client_order_ids=None)[source]

Bases: object

product_id: str = None
start_time: Optional[datetime] = None
end_time: Optional[datetime] = None
limit: int = 100
statuses: list[OrderStatus] = None
client_order_ids: list[str] = None
__init__(product_id=None, start_time=None, end_time=None, limit=100, statuses=None, client_order_ids=None)
class bsx_py.common.types.market.CancelOrderParams(order_id=None, nonce=None, client_order_id=None)[source]

Bases: object

order_id: Optional[str] = None
nonce: Optional[str] = None
client_order_id: Optional[str] = None
__init__(order_id=None, nonce=None, client_order_id=None)
class bsx_py.common.types.market.CancelOrdersParams(order_ids=None, nonces=None, client_order_ids=None)[source]

Bases: object

order_ids: list[str] = None
nonces: list[str] = None
client_order_ids: list[str] = None
__init__(order_ids=None, nonces=None, client_order_ids=None)
class bsx_py.common.types.market.CancelAllParams(product_id)[source]

Bases: object

product_id: str
__init__(product_id)
class bsx_py.common.types.market.BatchOrderUpdateParams(operations)[source]

Bases: object

operations: list[CreateOrderParams | CancelOrderParams | CancelOrdersParams | CancelAllParams]
__init__(operations)
class bsx_py.common.types.market.BatchOrderUpdateResult(code, message, detail)[source]

Bases: object

code: int
message: str
detail: Order | CancelOrderResult | CancelMultipleOrdersResult
static from_dict(data)[source]
Return type:

BatchOrderUpdateResult

__init__(code, message, detail)
class bsx_py.common.types.market.BatchOrderUpdateResponse(data)[source]

Bases: object

data: list[BatchOrderUpdateResult]
static from_dict(data)[source]
Return type:

BatchOrderUpdateResponse

__init__(data)
class bsx_py.common.types.market.GetTradeHistoryParams(product_id, start_time=None, end_time=None, page=1, limit=100)[source]

Bases: object

product_id: str
start_time: Optional[datetime] = None
end_time: Optional[datetime] = None
page: int = 1
limit: int = 100
__init__(product_id, start_time=None, end_time=None, page=1, limit=100)
class bsx_py.common.types.market.GetTradeHistoryResponse(product_id, wallet_address, trades, page, total)[source]

Bases: object

product_id: str
wallet_address: str
trades: list[Trade]
page: int
total: int
static from_dict(data)[source]
Return type:

GetTradeHistoryResponse

__init__(product_id, wallet_address, trades, page, total)
class bsx_py.common.types.market.PerpetualProductConfig(initial_margin, maintenance_margin, max_leverage)[source]

Bases: object

initial_margin: Decimal
maintenance_margin: Decimal
max_leverage: Decimal
static from_dict(data)[source]
Return type:

PerpetualProductConfig

__init__(initial_margin, maintenance_margin, max_leverage)
class bsx_py.common.types.market.Product(index, product_id, base_asset_symbol, quote_asset_symbol, underlying, display_name, display_base_asset_symbol, enabled, post_only, base_increment, quote_increment, quote_volume_24h, change_24h, high_24h, low_24h, last_price, mark_price, index_price, max_position_size, open_interest, funding_interval, next_funding_rate, next_funding_time, last_cumulative_funding, min_order_size, predicted_funding_rate, perpetual_product_config)[source]

Bases: object

index: int
product_id: str
base_asset_symbol: str
quote_asset_symbol: str
underlying: str
display_name: str
display_base_asset_symbol: str
enabled: bool
post_only: bool
base_increment: Decimal
quote_increment: Decimal
quote_volume_24h: Decimal
change_24h: Decimal
high_24h: Decimal
low_24h: Decimal
last_price: Decimal
mark_price: Decimal
index_price: Decimal
max_position_size: Decimal
open_interest: Decimal
funding_interval: Decimal
next_funding_rate: Decimal
next_funding_time: Decimal
last_cumulative_funding: Decimal
min_order_size: Decimal
predicted_funding_rate: Decimal
perpetual_product_config: PerpetualProductConfig
static from_dict(data)[source]
Return type:

Product

__init__(index, product_id, base_asset_symbol, quote_asset_symbol, underlying, display_name, display_base_asset_symbol, enabled, post_only, base_increment, quote_increment, quote_volume_24h, change_24h, high_24h, low_24h, last_price, mark_price, index_price, max_position_size, open_interest, funding_interval, next_funding_rate, next_funding_time, last_cumulative_funding, min_order_size, predicted_funding_rate, perpetual_product_config)
class bsx_py.common.types.market.GetProductsResponse(products)[source]

Bases: object

products: list[Product]
static from_dict(data)[source]
Return type:

GetProductsResponse

__init__(products)
class bsx_py.common.types.market.GetFundingHistoryParams(product_id, start_time, end_time, limit=20, page=1)[source]

Bases: object

product_id: str
start_time: Optional[datetime]
end_time: Optional[datetime]
limit: int = 20
page: int = 1
__init__(product_id, start_time, end_time, limit=20, page=1)
class bsx_py.common.types.market.FundingRate(time, rate)[source]

Bases: object

time: datetime
rate: Decimal
static from_dict(data)[source]
Return type:

FundingRate

__init__(time, rate)
class bsx_py.common.types.market.GetFundingHistoryResponse(product_id, items, paging)[source]

Bases: object

product_id: str
items: list[FundingRate]
paging: Paging
static from_dict(data)[source]
Return type:

GetFundingHistoryResponse

__init__(product_id, items, paging)
class bsx_py.common.types.market.GetTransferHistoryParams(type, start_time, end_time, page=1)[source]

Bases: object

type: TransferType
start_time: datetime
end_time: datetime
page: int = 1
__init__(type, start_time, end_time, page=1)

bsx_py.common.exception

exception bsx_py.common.exception.BSXRequestException(code, message, detail)[source]

Bases: Exception

Exception class for BSX Request

__init__(code, message, detail)[source]
get_code()[source]
Return type:

int

get_message()[source]
Return type:

str

get_detail()[source]
Return type:

str

exception bsx_py.common.exception.UnknownException(response_body)[source]

Bases: BSXRequestException

__init__(response_body)[source]
exception bsx_py.common.exception.UnauthenticatedException[source]

Bases: BSXRequestException

__init__()[source]
exception bsx_py.common.exception.NotSupportOperationException[source]

Bases: Exception

exception bsx_py.common.exception.WalletPrivateNotProvidedException[source]

Bases: Exception

bsx_py.typed_message

bsx_py.typed_message.gen_register_typed_message_for_smart_contract(env, signer, nonce)[source]

Helper function to generate the typed message that used to generate the signature for register a smart contract.

Note that this function should only be used to get the data of the typed message. The way to construct the message depends on the language that is used to generate the signature.

Return type:

dict

Attributes:

env (Environment|str): environment to use (Testnet or mainnet) or the domain in plain text

signer (LocalAccount): signer wallet used to sign requests

nonce (int): nonce that will be used to call the register API. We recommend using current timestamp in nanoseconds. Nonce should be unique across all requests of a user

Return:

dict: typed message in dict format.