basana.external.bitstamp.exchange¶
- class basana.external.bitstamp.exchange.Exchange(dispatcher, api_key=None, api_secret=None, session=None, tb=None, config_overrides={})¶
A client for Bitstamp crypto currency exchange.
- Parameters:
dispatcher (EventDispatcher) – The event dispatcher.
api_key (str | None) – An optional api key. If not set only public endpoints can be used.
api_secret (str | None) – An optional api secret. If not set only public endpoints can be used.
session (aiohttp.ClientSession) – An optional client session, in case you want to reuse connections.
tb (TokenBucketLimiter | None) – An optional token bucket limiter, in case you want to throttle requests.
config_overrides (dict) – An optional dictionary for overriding config settings.
- async cancel_order(order_id)¶
Cancels an order.
If the order can’t be canceled a
basana.external.bitstamp.exchange.Errorwill be raised.- Parameters:
order_id (str | int) – The order id.
- Return type:
- async create_instant_order(operation, pair, amount, amount_in_counter=False, client_order_id=None, **kwargs)¶
Creates an instant order.
If the order can’t be created a
basana.external.bitstamp.exchange.Errorwill be raised.- Parameters:
operation (OrderOperation) – The order operation.
pair (Pair) – The pair to trade.
amount (Decimal) – The amount to buy/sell.
amount_in_counter (bool) – False if the amount is set in base currency (default), True if the amount is set in quote currency.
client_order_id (str | None) – A client order id.
kwargs (Dict[str, Any]) – Additional keyword arguments that will be forwarded.
- Return type:
- async create_limit_order(operation, pair, amount, limit_price, client_order_id=None, **kwargs)¶
Creates a limit order.
If the order can’t be created a
basana.external.bitstamp.exchange.Errorwill be raised.- Parameters:
operation (OrderOperation) – The order operation.
pair (Pair) – The pair to trade.
amount (Decimal) – The amount to buy/sell in base units.
limit_price (Decimal) – The limit price.
client_order_id (str | None) – A client order id.
kwargs (Dict[str, Any]) – Additional keyword arguments that will be forwarded.
- Return type:
- async create_market_order(operation, pair, amount, client_order_id=None, **kwargs)¶
Creates a market order.
If the order can’t be created a
basana.external.bitstamp.exchange.Errorwill be raised.- Parameters:
operation (OrderOperation) – The order operation.
pair (Pair) – The pair to trade.
amount (Decimal) – The amount to buy/sell in base units.
client_order_id (str | None) – A client order id.
kwargs (Dict[str, Any]) – Additional keyword arguments that will be forwarded.
- Return type:
- async get_balance(symbol)¶
Returns the balance for a specific currency/symbol/etc..
- Parameters:
symbol (str) – The currency/symbol/etc..
- Return type:
- async get_bid_ask(pair)¶
Returns the current bid and ask price.
- Parameters:
pair (Pair) – The trading pair.
- Return type:
Tuple[Decimal, Decimal]
- async get_open_orders(pair=None)¶
Returns open orders.
- async get_order_info(pair, order_id=None, client_order_id=None)¶
Returns information about an order.
- Parameters:
pair (Pair) – The trading pair.
order_id (str | int | None) – The order id.
client_order_id (str | None) – The client order id.
- Return type:
OrderInfo | None
Note
Either order_id or client_order_id should be set, but not both.
For closed orders, this call only returns information for the last 30 days.
- async get_pair_info(pair)¶
Returns information about a trading pair.
- subscribe_to_bar_events(pair, bar_duration, event_handler, skip_first_bar=True, flush_delay=1)¶
Registers an async callable that will be called when a new bar is available.
- Parameters:
pair (Pair) – The trading pair.
bar_duration (int) – The bar duration in seconds.
event_handler (Callable[[BarEvent], Awaitable[Any]]) – An async callable that receives BarEvent.
skip_first_bar (bool) – True if the first bar should be skipped. This is to avoid receiving incomplete bars if subscription takes place in the middle of the period.
flush_delay (float) – The number of seconds to wait before generating the new bar, in case trades are delayed.
Note
Under the hood, this will subscribe to trade events and will aggregate those into bars.
- subscribe_to_order_book_events(pair, event_handler)¶
Registers an async callable that will be called when the order book is updated.
- Parameters:
pair (Pair) – The trading pair.
event_handler (Callable[[OrderBookEvent], Awaitable[Any]]) – An async callable that receives an OrderBookEvent.
Note
Only the top 100 bids and asks are returned in the event.
- subscribe_to_private_order_events(pair, event_handler)¶
Registers an async callable that will be called when your own orders are updated.
- Parameters:
pair (Pair) – The trading pair.
event_handler (Callable[[OrderEvent], Awaitable[Any]]) – An async callable that receives an OrderEvent.
- subscribe_to_private_trade_events(pair, event_handler)¶
Registers an async callable that will be called for your own new trades.
- Parameters:
pair (Pair) – The trading pair.
event_handler (Callable[[TradeEvent], Awaitable[Any]]) – An async callable that receives a TradeEvent.
- subscribe_to_public_order_events(pair, event_handler)¶
Registers an async callable that will be called when any order is updated.
- Parameters:
pair (Pair) – The trading pair.
event_handler (Callable[[OrderEvent], Awaitable[Any]]) – An async callable that receives an OrderEvent.
- subscribe_to_public_trade_events(pair, event_handler)¶
Registers an async callable that will be called for any new trade.
- Parameters:
pair (Pair) – The trading pair.
event_handler (Callable[[TradeEvent], Awaitable[Any]]) – An async callable that receives a TradeEvent.
- class basana.external.bitstamp.exchange.Error(msg, resp, json_response)¶
- Parameters:
msg (str)
resp (ClientResponse)
- class basana.external.bitstamp.exchange.TransactionType(value)¶
Enumeration for transaction types.
- DEPOSIT = 0¶
- MARKET_TRADE = 2¶
- WITHDRAWAL = 1¶
- class basana.external.bitstamp.exchange.Balance(json)¶
- Parameters:
json (dict)
- property available: Decimal¶
The available balance.
- property reserved: Decimal¶
The reserved balance.
- property total: Decimal¶
The total balance (available + reserved).
- class basana.external.bitstamp.exchange.CreatedOrder(json)¶
- Parameters:
json (dict)
- property amount: Decimal¶
The amount.
- property client_order_id: str | None¶
The client order id.
- property datetime: datetime¶
The creation datetime.
- property id: str¶
The order id.
- property operation: OrderOperation¶
The operation.
- property price: Decimal¶
The price.
- class basana.external.bitstamp.exchange.OrderInfo(pair, order_status)¶
- Parameters:
pair (Pair)
order_status (OrderStatus)
- property amount_filled: Decimal¶
The amount filled.
- property amount_remaining: Decimal¶
The amount remaining to be filled.
- property fees: Dict[str, Decimal]¶
The fees.
- property fill_price: Decimal | None¶
The fill price.
- property id: str¶
The order id.
- property is_open: bool¶
True if the order is open, False otherwise.
- property quote_amount_filled: Decimal¶
The amount filled in quote units.
- class basana.external.bitstamp.exchange.OpenOrder(json)¶
- Parameters:
json (dict)
- property amount: Decimal¶
The amount.
- property amount_filled: Decimal¶
The amount filled.
- property client_order_id: str | None¶
The client order id.
- property datetime: datetime¶
The creation datetime.
- property id: str¶
The order id.
- property limit_price: Decimal¶
The limit price.
- property operation: OrderOperation¶
The operation.