V1 REST¶
-
class
Client
(key=None, secret=None, nonce_multiplier=1.0)[source]¶ Client for the bitfinex.com API.
Link for official bitfinex documentation :
Parameters: Examples
bfx_client = Client(key,secret) bfx_client = Client(key,secret,2.0)
-
place_order
(amount, price, side, ord_type, symbol='btcusd', exchange='bitfinex')[source]¶ -
Submit a new Order
Parameters: - amount (float) – Order size: how much you want to buy or sell
- price (float) – Price to buy or sell at. Must be positive. Use random number for market orders.
- side (string) – Either “buy” or “sell”.
- ord_type (string) – Either “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)
- symbol (str) – The symbol you want information about.
- exchange (str) – ‘bitfinex’
Returns: # response { "id":448364249, "symbol":"btcusd", "exchange":"bitfinex", "price":"0.01", "avg_execution_price":"0.0", "side":"buy", "type":"exchange limit", "timestamp":"1444272165.252370982", "is_live":true, "is_cancelled":false, "is_hidden":false, "was_forced":false, "original_amount":"0.01", "remaining_amount":"0.01", "executed_amount":"0.0", "order_id":448364249 }
Return type: Examples
bfx_client.place_order(0.01, 0.01, "buy", "exchange limit", "btcusd")
-
place_multiple_orders
(orders)[source]¶ Parameters: orders (list) – Each item in the list is a dict that must have the following items : symbol, amount, price, side, type, exchange Returns: // response { "order_ids":[ { "id":448383727, "symbol":"btcusd", "exchange":"bitfinex", "price":"0.01", "avg_execution_price":"0.0", "side":"buy", "type":"exchange limit", "timestamp":"1444274013.621701916", "is_live":true, "is_cancelled":false, "is_hidden":false, "was_forced":false, "original_amount":"0.01", "remaining_amount":"0.01", "executed_amount":"0.0" },{ "id":448383729, "symbol":"btcusd", "exchange":"bitfinex", "price":"0.03", "avg_execution_price":"0.0", "side":"buy", "type":"exchange limit", "timestamp":"1444274013.661297306", "is_live":true, "is_cancelled":false, "is_hidden":false, "was_forced":false, "original_amount":"0.02", "remaining_amount":"0.02", "executed_amount":"0.0" }], "status":"success" }
Return type: dict Examples
# Make a list with 3 orders to buy 100 iota at 3 dollars,100 iota at 4 dollars and # 100 iota at 5 dollars # The list is sent to the method place_multiple_orders orders = [] for price in range(3, 6): print(price) payload = { "symbol": 'IOTUSD', "amount": '100', "price": str(price), "exchange": 'bitfinex', "side": 'buy', "type": 'limit' } orders.append(payload) response = bfx_client.place_multiple_orders(orders) print(response)
-
delete_order
(order_id)[source]¶ Bitfinex cancel order reference
Cancel an order.
Parameters: order_id (int) – The order ID given by new_order function Returns: { "id":446915287, "symbol":"btcusd", "exchange":null, "price":"239.0", "avg_execution_price":"0.0", "side":"sell", "type":"trailing stop", "timestamp":"1444141982.0", "is_live":true, "is_cancelled":false, "is_hidden":false, "was_forced":false, "original_amount":"1.0", "remaining_amount":"1.0", "executed_amount":"0.0" }
Return type: dict Example
bfx_client.delete_order(448411153)
-
delete_all_orders
()[source]¶ Bitfinex cancel all orders reference
Cancel all orders at once.
Returns: {"result":"Orders cancelled"}
Return type: dict Example
bfx_client.delete_all_orders()
-
status_order
(order_id)[source]¶ Bitfinex status order reference
Get the status of an order. Is it active? Was it cancelled? To what extent has it been executed? etc.
Parameters: order_id (int) – The order ID given by new_order function Returns: { "id":448411153, "symbol":"btcusd", "exchange":null, "price":"0.01", "avg_execution_price":"0.0", "side":"buy", "type":"exchange limit", "timestamp":"1444276570.0", "is_live":false, "is_cancelled":true, "is_hidden":false, "oco_order":null, "was_forced":false, "original_amount":"0.01", "remaining_amount":"0.01", "executed_amount":"0.0" }
Return type: dict Example
bfx_client.status_order(448411153)
-
active_orders
()[source]¶ Bitfinex active orders reference
View your active orders.
Returns: [{ "id":448411365, "symbol":"btcusd", "exchange":"bitfinex", "price":"0.02", "avg_execution_price":"0.0", "side":"buy", "type":"exchange limit", "timestamp":"1444276597.0", "is_live":true, "is_cancelled":false, "is_hidden":false, "was_forced":false, "original_amount":"0.02", "remaining_amount":"0.02", "executed_amount":"0.0" }]
Return type: list Example
bfx_client.active_orders(448411153)
-
active_positions
()[source]¶ Bitfinex active positions reference
View your active positions.
Returns: [{ "id":943715, "symbol":"btcusd", "status":"ACTIVE", "base":"246.94", "amount":"1.0", "timestamp":"1444141857.0", "swap":"0.0", "pl":"-2.22042" }]
Return type: list Example
bfx_client.active_positions(448411153)
-
claim_position
(position_id)[source]¶ Bitfinex claim position reference
A position can be claimed if: It is a long position: The amount in the last unit of the position pair that you have in your trading wallet AND/OR the realized profit of the position is greater or equal to the purchase amount of the position (base price * position amount) and the funds which need to be returned. For example, for a long BTCUSD position, you can claim the position if the amount of USD you have in the trading wallet is greater than the base price * the position amount and the funds used. It is a short position: The amount in the first unit of the position pair that you have in your trading wallet is greater or equal to the amount of the position and the margin funding used.
Parameters: position_id (int) – The position ID Returns: { "id":943715, "symbol":"btcusd", "status":"ACTIVE", "base":"246.94", "amount":"1.0", "timestamp":"1444141857.0", "swap":"0.0", "pl":"-2.2304" }
Return type: dict Example
bfx_client.claim_position(18411153)
-
close_position
(position_id)[source]¶ Bitfinex close position reference
Closes the selected position with a market order.
Parameters: position_id (int) – The position ID Returns: { "message": "", "order": {}, "position": {} }
Return type: dict Example
bfx_client.close_position(18411153)
-
past_trades
(timestamp='0.0', symbol='btcusd')[source]¶ Bitfinex past trades reference
View your past trades.
Parameters: Returns: [{ "price":"246.94", "amount":"1.0", "timestamp":"1444141857.0", "exchange":"", "type":"Buy", "fee_currency":"USD", "fee_amount":"-0.49388", "tid":11970839, "order_id":446913929 }]
Return type: Example
bfx_client.past_trades('0.0','btcusd') bfx_client.past_trades()
-
place_offer
(currency, amount, rate, period, direction)[source]¶ Bitfinex place offer reference
Submit a new Offer
Parameters: - currency (string) – The name of the currency.
- amount (float) – Order size: how much to lend or borrow.
- rate (float) – Rate to lend or borrow at. In percentage per 365 days. (Set to 0 for FRR).
- period (int) – Number of days of the funding contract (in days)
- direction (string) – Either “lend” or “loan”.
Returns: { "id":13800585, "currency":"USD", "rate":"20.0", "period":2, "direction":"lend", "timestamp":"1444279698.21175971", "is_live":true, "is_cancelled":false, "original_amount":"50.0", "remaining_amount":"50.0", "executed_amount":"0.0", "offer_id":13800585 }
Return type: Example
bfx_client.place_offer("USD",50.0,20.0,2,"lend")
-
cancel_offer
(offer_id)[source]¶ Bitfinex cancel offer reference
Cancel an offer.
Parameters: offer_id (int) – The offer ID given by new_offer function Returns: { "id":13800585, "currency":"USD", "rate":"20.0", "period":2, "direction":"lend", "timestamp":"1444279698.0", "is_live":true, "is_cancelled":false, "original_amount":"50.0", "remaining_amount":"50.0", "executed_amount":"0.0" }
Return type: dict Example
bfx_client.cancel_offer(1231153)
-
status_offer
(offer_id)[source]¶ Bitfinex status offer reference
Get the status of an offer. Is it active? Was it cancelled? To what extent has it been executed? etc.
Parameters: offer_id (int) – The offer ID given by new_offer function Returns: { "id":13800585, "currency":"USD", "rate":"20.0", "period":2, "direction":"lend", "timestamp":"1444279698.0", "is_live":false, "is_cancelled":true, "original_amount":"50.0", "remaining_amount":"50.0", "executed_amount":"0.0" }
Return type: dict Example
bfx_client.status_offer(354352)
-
offers_history
()[source]¶ Bitfinex offers history reference
View your latest inactive offers. Limited to last 3 days and 1 request per minute.
Returns: [{ "id":13800719, "currency":"USD", "rate":"31.39", "period":2, "direction":"lend", "timestamp":"1444280237.0", "is_live":false, "is_cancelled":true, "original_amount":"50.0", "remaining_amount":"50.0", "executed_amount":"0.0" }]
Return type: list Example
bfx_client.offers_history()
-
active_offers
()[source]¶ Bitfinex active offers reference
View your active offers.
Returns: [{ "id":13800719, "currency":"USD", "rate":"31.39", "period":2, "direction":"lend", "timestamp":"1444280237.0", "is_live":true, "is_cancelled":false, "original_amount":"50.0", "remaining_amount":"50.0", "executed_amount":"0.0" }]
Return type: list Example
bfx_client.active_offers()
-
balances
()[source]¶ -
See your balances
Returns: [ {"type":"deposit", "currency":"btc", "amount":"0.0", "available":"0.0"}, {"type":"deposit", "currency":"usd", "amount":"1.0", "available":"1.0"}, {"type":"exchange", "currency":"btc", "amount":"1", "available":"1"}, {"type":"exchange", "currency":"usd", "amount":"1", "available":"1"}, {"type":"trading", "currency":"btc", "amount":"1", "available":"1"}, {"type":"trading", "currency":"usd", "amount":"1", "available":"1"}, ... ]
Return type: list Example
bfx_client.balances()
-
history
(currency, since=0, until=9999999999, limit=500, wallet='exchange')[source]¶ Bitfinex balance history reference
View all of your balance ledger entries.
Parameters: - currency (str) – The currency to look for.
- since (Optional str) – Return only the history after this timestamp. (Max 3 months before until)
- until (Optional str) – Return only the history before this timestamp. (Default now)
- limit (Optional int) – Limit the number of entries to return.
- wallet (Optional str) – Return only entries that took place in this wallet. Accepted inputs are: “trading”, “exchange”, “deposit”.
Returns: [{ "currency":"USD", "amount":"-246.94", "balance":"515.4476526", "description":"Position claimed @ 245.2 on wallet trading", "timestamp":"1444277602.0" }]
Return type: Example
bfx_client.history('USD')
-
movements
(currency, start=0, end=9999999999, limit=10000, method='bitcoin')[source]¶ Bitfinex Deposit-Withdrawal History reference
View your past deposits/withdrawals.
Parameters: - currency (str) – The currency to look for.
- start (Optional str) – Return only the history after this timestamp. (Max 3 months before until)
- end (Optional str) – Return only the history before this timestamp. (Default now)
- limit (Optional int) – Limit the number of entries to return.
- method (str) – The method of the deposit/withdrawal (can be “bitcoin”, “litecoin”, “iota”, “wire”).
Returns: [{ "id":581183, "txid": 123456, "currency":"BTC", "method":"BITCOIN", "type":"WITHDRAWAL", "amount":".01", "description":"3QXYWgRGX2BPYBpUDBssGbeWEa5zq6snBZ, offchain transfer ", "address":"3QXYWgRGX2BPYBpUDBssGbeWEa5zq6snBZ", "status":"COMPLETED", "timestamp":"1443833327.0", "timestamp_created": "1443833327.1", "fee": 0.1 }]
Return type: Example
bfx_client.movements('USD')
-
symbols
()[source]¶ -
A list of symbol names.
Returns: [ "btcusd", "ltcusd", "ltcbtc", ... ]
Return type: list Example
bfx_client.symbols()
-
symbols_details
()[source]¶ Bitfinex symbols details reference
Get a list of valid symbol IDs and the pair details.
Returns: [{ "pair":"btcusd", "price_precision":5, "initial_margin":"30.0", "minimum_margin":"15.0", "maximum_order_size":"2000.0", "minimum_order_size":"0.01", "expiration":"NA" },{ "pair":"ltcusd", "price_precision":5, "initial_margin":"30.0", "minimum_margin":"15.0", "maximum_order_size":"5000.0", "minimum_order_size":"0.1", "expiration":"NA" },{ "pair":"ltcbtc", "price_precision":5, "initial_margin":"30.0", "minimum_margin":"15.0", "maximum_order_size":"5000.0", "minimum_order_size":"0.1", "expiration":"NA" }, ... ]
Return type: list Example
bfx_client.symbols_details()
-
ticker
(symbol)[source]¶ -
The ticker is a high level overview of the state of the market. It shows you the current best bid and ask, as well as the last trade price. It also includes information such as daily volume and how much the price has moved over the last day.
Parameters: symbol (str) – The symbol you want information about.
Returns: { "mid":"244.755", "bid":"244.75", "ask":"244.76", "last_price":"244.82", "low":"244.2", "high":"248.19", "volume":"7842.11542563", "timestamp":"1444253422.348340958" }
Return type: dict Example
bfx_client.ticker("BTCUSD")
-
today
(symbol)[source]¶ Get today stats
Parameters: symbol (str) – The symbol you want information about.
Returns: {"low":"550.09","high":"572.2398","volume":"7305.33119836"}
Return type: dict Example
bfx_client.today("BTCUSD")
-
stats
(symbol)[source]¶ -
Various statistics about the requested pair.
Parameters: symbol (str) – The symbol you want information about.
Returns: [{ "period":1, "volume":"7967.96766158" },{ "period":7, "volume":"55938.67260266" },{ "period":30, "volume":"275148.09653645" }]
Return type: dict Example
bfx_client.stats("BTCUSD")
-
lendbook
(currency, parameters=None)[source]¶ Bitfinex Fundingbook reference
Get the full margin funding book
Parameters: currency (str) – Currency Returns: { "bids":[{ 'rate': '7.0482', 'amount': '244575.00836875', 'period': 30, 'timestamp': '1539157649.0', 'frr': False }] "asks":[{ 'rate': '5.6831', 'amount': '63.5744', 'period': 2, 'timestamp': '1539165059.0', 'frr': False }] }
Return type: dict Example
bfx_client.lendbook("USD")
-
order_book
(symbol, parameters=None)[source]¶ -
Get the full order book.
Parameters: currency (str) – Currency Returns: { "bids":[{ "price":"574.61", "amount":"0.1439327", "timestamp":"1472506127.0" }], "asks":[{ "price":"574.62", "amount":"19.1334", "timestamp":"1472506126.0" }] }
Return type: dict Example
bfx_client.order_book("BTCUSD")
-
key_permissions
()[source]¶ -
Check the permissions of the key being used to generate this request.
Returns: { 'account': {'read': True, 'write': False}, 'history': {'read': True, 'write': False}, 'orders': {'read': True, 'write': False}, 'positions': {'read': True, 'write': False}, 'funding': {'read': True, 'write': False}, 'wallets': {'read': True, 'write': False}, 'withdraw': {'read': False, 'write': False} }
Return type: dict Example
bfx_client.order_book("BTCUSD")
-