btfx_trader package¶
Submodules¶
btfx_trader.private module¶
-
class
btfx_trader.private.
Trader
(key, secret)[source]¶ Bases:
btfx_trader.private._Account
Class interface for trading on the Bitfinex Exchange :param key: str: Bitfinex api-key :param secret: str: Bitfinex api-secret
-
cancel_all
(older_than=0)[source]¶ Cancel all orders older than a certain time :param older_than: int/float:
age of order that should be cancelled (in seconds)Returns: None
-
order
(symbol, price, *, dollar_amount=None, ratio=None, value_ratio=None, trade_type='limit', pad_price=None, return_id=True)[source]¶ Make an exchange order :param symbol: str:
ticker symbol to order (e.g. ‘BTCUSD’, ‘ETHUSD’…)Parameters: - price – float: Price at which to submit order You can also pass “market” as an argument for price to order at current market value e.g. Trader.order(‘BTCUSD’, ‘market’, dollar_amount=5)
- dollar_amount –
float: Dollar equivalent value of trade amount (negative for selling) e.g. ordering 10 BTCUSD at $5 per coin
-> Trader.order(‘BTCUSD’, 5, dollar_amount=50) - ratio –
float: Ratio of available balance for requested symbol (negative for sell) e.g. With $1000 USD in wallet, ordering 100 BTCUSD at $5 per coin
-> Trader.order(‘BTCUSD’, 5, ratio=0.5) - value_ratio –
float: Ratio of Trader.value (negative for selling) e.g. With $500 in USD and $500 in BTCUSD (at $5) in wallet,
ordering 100 BTCUSD at $5 per coin-> Trader.order(‘BTCUSD’, 5, value_ratio=0.5)
- trade_type – str: (optional) Bitfinex api trade type - one of {‘market’, ‘limit’} see https://www.bitfinex.com/features for details
- pad_price – float: (optional) Ratio based price padding - used to undercut or overshoot price If buying then pad_price * price is added to submitted price If selling then pad_price * price is subtracted from price
- return_id – bool: (optional) If true, Trader.order blocks until order_id is returned from Bitfinex, otherwise returns immediately
Returns: int: If return_id is True, then order id is returned, otherwise None
Raises: AssertionError: If values passed are non-consistent
-
btfx_trader.public module¶
-
class
btfx_trader.public.
PublicData
(types=None, symbols=None)[source]¶ Bases:
object
Wrapper for BtfxWss for access to public bitfinex data :param types: list:
(optional) data types to filter data by (tickers, trades, candles)Parameters: symbols – list: (optional) symbol to filter data by (e.g. [‘BTCUSD’, ‘ETHUSD’]) -
candle_periods
= ['1m', '5m', '15m', '30m', '1h', '3h', '6h', '12h', '1D', '7D', '14D', '1M']¶
-
get
(_type, symbol)[source]¶ Gets next available data (blocks until new datum is received) :param _type: str: type of data to get (e.g. ‘tickers’, ‘candles’…) :param symbol: str:
symbol for which to get data (e.g. ‘BTCUSD’, ‘ETHUSD’…)Returns: dict: requested data in json format Raises: AssertionError: if either of the provided type and symbol are unrecognized
-
get_nowait
(_type, symbol)[source]¶ Gets currently available data with no blocking :param _type: str: type of data to get (e.g. ‘tickers’, ‘candles’…) :param symbol: str:
symbol for which to get data (e.g. ‘BTCUSD’, ‘ETHUSD’…)Returns: dict: requested data in json format
Raises: - AssertionError:
if either of the provided type and symbol are unrecognized
- Empty:
if no new data is available (same as queue.Queue api)
-
Module contents¶
-
class
btfx_trader.
PublicData
(types=None, symbols=None)[source]¶ Bases:
object
Wrapper for BtfxWss for access to public bitfinex data :param types: list:
(optional) data types to filter data by (tickers, trades, candles)Parameters: symbols – list: (optional) symbol to filter data by (e.g. [‘BTCUSD’, ‘ETHUSD’]) -
candle_periods
= ['1m', '5m', '15m', '30m', '1h', '3h', '6h', '12h', '1D', '7D', '14D', '1M']¶
-
get
(_type, symbol)[source]¶ Gets next available data (blocks until new datum is received) :param _type: str: type of data to get (e.g. ‘tickers’, ‘candles’…) :param symbol: str:
symbol for which to get data (e.g. ‘BTCUSD’, ‘ETHUSD’…)Returns: dict: requested data in json format Raises: AssertionError: if either of the provided type and symbol are unrecognized
-
get_nowait
(_type, symbol)[source]¶ Gets currently available data with no blocking :param _type: str: type of data to get (e.g. ‘tickers’, ‘candles’…) :param symbol: str:
symbol for which to get data (e.g. ‘BTCUSD’, ‘ETHUSD’…)Returns: dict: requested data in json format
Raises: - AssertionError:
if either of the provided type and symbol are unrecognized
- Empty:
if no new data is available (same as queue.Queue api)
-
-
class
btfx_trader.
Trader
(key, secret)[source]¶ Bases:
btfx_trader.private._Account
Class interface for trading on the Bitfinex Exchange :param key: str: Bitfinex api-key :param secret: str: Bitfinex api-secret
-
cancel_all
(older_than=0)[source]¶ Cancel all orders older than a certain time :param older_than: int/float:
age of order that should be cancelled (in seconds)Returns: None
-
order
(symbol, price, *, dollar_amount=None, ratio=None, value_ratio=None, trade_type='limit', pad_price=None, return_id=True)[source]¶ Make an exchange order :param symbol: str:
ticker symbol to order (e.g. ‘BTCUSD’, ‘ETHUSD’…)Parameters: - price – float: Price at which to submit order You can also pass “market” as an argument for price to order at current market value e.g. Trader.order(‘BTCUSD’, ‘market’, dollar_amount=5)
- dollar_amount –
float: Dollar equivalent value of trade amount (negative for selling) e.g. ordering 10 BTCUSD at $5 per coin
-> Trader.order(‘BTCUSD’, 5, dollar_amount=50) - ratio –
float: Ratio of available balance for requested symbol (negative for sell) e.g. With $1000 USD in wallet, ordering 100 BTCUSD at $5 per coin
-> Trader.order(‘BTCUSD’, 5, ratio=0.5) - value_ratio –
float: Ratio of Trader.value (negative for selling) e.g. With $500 in USD and $500 in BTCUSD (at $5) in wallet,
ordering 100 BTCUSD at $5 per coin-> Trader.order(‘BTCUSD’, 5, value_ratio=0.5)
- trade_type – str: (optional) Bitfinex api trade type - one of {‘market’, ‘limit’} see https://www.bitfinex.com/features for details
- pad_price – float: (optional) Ratio based price padding - used to undercut or overshoot price If buying then pad_price * price is added to submitted price If selling then pad_price * price is subtracted from price
- return_id – bool: (optional) If true, Trader.order blocks until order_id is returned from Bitfinex, otherwise returns immediately
Returns: int: If return_id is True, then order id is returned, otherwise None
Raises: AssertionError: If values passed are non-consistent
-