def _order_status(self, id_): """Get the status of an order. Params ====== order_id : int The order ID given by /order/new. Fields ====== symbol [string] The symbol name the order belongs to exchange [string] "bitfinex" price [decimal] The price the order was issued at (can be null for market orders) avg_execution_price [decimal] The average price at which this order as been executed so far. 0 if the order has not been executed at all side [string] Either "buy" or "sell" type [string] Either "market" / "limit" / "stop" / "trailing-stop" timestamp [time] The timestamp the order was submitted is_live [bool] Could the order still be filled? is_cancelled [bool] Has the order been cancelled? is_hidden [bool] Is the order hidden? oco_order [int64] If the order is an OCO order, the ID of the linked order. Otherwise, null was_forced [bool] For margin only true if it was forced by the system executed_amount [decimal] How much of the order has been executed so far in its history? remaining_amount [decimal] How much is still remaining to be submitted? original_amount [decimal] What was the order originally submitted for? """ with BitfinexConnection() as c: return c.query_private('order/status', params={ 'order_id': id_, })
def _candles(self, time_frame, pair, section, limit=100, start='', end='', sort=0): """Return charter candle info. Path params =========== time_frame: string Available values: '1m', '5m', '15m', '30m', '1h', '3h', '6h', '12h', '1D', '7D', '14D', '1M'. symbol: string The symbol you want information about. section: string Available values: last, hist. Query params ============ limit: int Number of candles requested. start: string Filter start (ms). end: string Filter end (ms). sort: int Sorts results returned with old > new if 1 Fields ===== MTS [int] millisecond time stamp OPEN [float] First execution during the time frame CLOSE [float] Last execution during the time frame HIGH [float] Highest execution during the time frame LOW [float] Lowest execution during the timeframe VOLUME [float] Quantity of symbol traded within the timeframe """ params = { 'limit': limit, } with BitfinexConnection(version='v2') as c: return c.query_public('candles/trade:' + ':'.join([time_frame, pair]) + '/' + section, get_params=params) return 't' + pair.upper()
def _cancel_orders(self, order_ids): """Cancel an order. Params ====== order_ids : int[] """ with BitfinexConnection() as c: return c.query_private('order/cancel/multi', params={ 'order_ids': order_ids, })
def _order_history(self, limit=100): """View latest inactive orders. Limited to 3 days and 1 request per minute. Params ====== limit : int Limit number of results """ with BitfinexConnection() as c: return c.query_private('orders/hist', params={'limit_orders': limit})
def _symbols(self): """Return pair's details. Response details ================ pair [string] The pair code price_precision [integer] Maximum number of significant digits for price in this pair initial_margin [decimal] Initial margin required to open a position in this pair minimum_margin [decimal] Minimal margin to maintain (in %) maximum_order_size [decimal] Maximum order size of the pair minimum_order_size [decimal] Minimum order size of the pair expiration [string] Expiration date for limited contracts/pairs """ with BitfinexConnection() as c: return c.query_public('symbols_details')
def _ticker(self, pair): """Return ticker. Fields ===== mid [price] (bid + ask) / 2 bid [price] Innermost bid ask [price] Innermost ask last_price [price] The price at which the last order executed low [price] Lowest trade price of the last 24 hours high [price] Highest trade price of the last 24 hours volume [price] Trading volume of the last 24 hours timestamp [time] The timestamp at which this information was valid """ with BitfinexConnection() as c: return c.query_public('pubticker/' + pair)
def _wallet_balance(self): """Return wallet balances.""" with BitfinexConnection() as c: return c.query_private('balances')
def _order(self, pair, side, type_, volume=0, price=0, post_only=True, oco=False, oco_price=0): """Submit a new order. Params ====== symbol : str amount : float side : str Either 'buy' or 'sell'. type : str Can be: "market" / "limit" / "stop" / "trailing-stop" / "fill-or-kill" / "exchange market" / "exchange limit" / "exchange stop" / "exchange trailing-stop" / "exchange fill-or-kill". (type starting by "exchange" are exchange orders, others are margin trading orders) price : float is_hidden : boolean True if order should be hidden. is_postonly : boolean True if order should be post only. Only relevant for limit orders. use_all_available : int If 1 post an order that will use all your available balance. ocoorder : boolean Set an additional STOP OCO order that will be linked with the current order. buy_price_oco: float If ocoorder is true, this field represents the price of the OCO stop order to place. sell_price_oco: float If ocoorder is true, this field represents the price of the OCO stop order to place. Fields ====== order_id : int An order object containing the order ID as well as all the information privided by /order/status. """ params = { 'symbol': pair, 'amount': str(volume), 'side': side, 'type': type_, 'price': str(price), 'use_all_available': 0 if volume else 1, 'is_postonly': post_only, 'ocoorder': oco, 'buy_price_oco': str(oco_price) if oco and side == 'buy' else '0', 'sell_price_oco': str(oco_price) if oco and side == 'sell' else '0', } with BitfinexConnection() as c: return c.query_private('order/new', params=params)
def _fees(self): with BitfinexConnection() as c: return c.query_private('summary')
def _active_orders(self): """View active orders.""" with BitfinexConnection() as c: return c.query_private('orders')
def test_private_with_arguments(self): with BitfinexConnection() as c: result = c.query('POST', 'mytrades', sign=True, params={'symbol': 'ltcusd'}) self.assertIsNotNone(result)
def test_private(self): with BitfinexConnection() as c: result = c.query('POST', 'account_infos', sign=True) self.assertIsNotNone(result)
def test_public_with_arguments(self): with BitfinexConnection() as c: result = c.query('GET', 'stats/btcusd') self.assertIsNotNone(result)
def test_public(self): with BitfinexConnection() as c: result = c.query('GET', 'symbols') self.assertIsNotNone(result)
def test_exception(self): with self.assertRaises(ExchangeConnectionException): with BitfinexConnection() as c: c.query('GET', 'stats/btcbtc')