Binance Manager¶
-
class
BinanceWatch.BinanceManager.BinanceManager(api_key: str, api_secret: str, account_name: str = 'default')[source]¶ This class is in charge of filling the database by calling the binance API
-
API_MAX_RETRY= 3¶
-
__init__(api_key: str, api_secret: str, account_name: str = 'default')[source]¶ Initialise the binance manager.
- Parameters
api_key (str) – key for the Binance api
api_secret (str) – secret for the Binance api
account_name (str) – if you have several accounts to monitor, you need to give them different names or the database will collide
-
get_margin_symbol_info(isolated: bool) → List[Dict][source]¶ Return information about margin symbols as provided by the binance API
sources: https://binance-docs.github.io/apidocs/spot/en/#get-all-isolated-margin-symbol-user_data https://binance-docs.github.io/apidocs/spot/en/#get-all-cross-margin-pairs-market_data
- Parameters
isolated (bool) – If isolated data are to be returned, otherwise it will be cross margin data
- Returns
Info on the trading symbols
- Return type
List[Dict]
# cross margin [ { 'id': 351637150141315861, 'symbol': 'BNBBTC', 'base': 'BNB', 'quote': 'BTC', 'isMarginTrade': True, 'isBuyAllowed': True, 'isSellAllowed': True }, ... ] # isolated margin [ { 'symbol': '1INCHBTC', 'base': '1INCH', 'quote': 'BTC', 'isMarginTrade': True, 'isBuyAllowed': True, 'isSellAllowed': True }, ... ]
-
update_all_cross_margin_trades(limit: int = 1000)[source]¶ This update the cross margin trades in the database for every trading pairs
- Parameters
limit (int) – max size of each trade requests
- Returns
None
- Return type
None
-
update_all_spot_trades(limit: int = 1000)[source]¶ This update the spot trades in the database for every trading pairs
- Parameters
limit (int) – max size of each trade requests
- Returns
None
- Return type
None
-
update_cross_margin()[source]¶ call all update methods related to cross margin account
- Returns
None
- Return type
None
-
update_cross_margin_loans()[source]¶ update the loans for all cross margin assets
- Returns
None
- Return type
None
-
update_cross_margin_repays()[source]¶ update the repays for all cross margin assets
- Returns
None
- Return type
None
-
update_isolated_margin()[source]¶ call all update methods related to isolated margin account
- Returns
None
- Return type
None
-
update_isolated_margin_interests(symbols_info: Optional[List[Dict]] = None)[source]¶ Update the interests for isolated margin assets
- Parameters
symbols_info (Optional[List[Dict]]) – details on the symbols to fetch repays on. Each dictionary needs the fields ‘asset’ and ‘ref_asset’. If not provided, will update all isolated symbols.
- Returns
None
- Return type
None
-
update_isolated_margin_loans(symbols_info: Optional[List[Dict]] = None)[source]¶ Update the loans for isolated margin assets
- Parameters
symbols_info (Optional[List[Dict]]) – details on the symbols to fetch loans on. Each dictionary needs the fields ‘asset’ and ‘ref_asset’. If not provided, will update all isolated symbols.
- Returns
None
- Return type
None
-
update_isolated_margin_repays(symbols_info: Optional[List[Dict]] = None)[source]¶ Update the repays for isolated margin assets
- Parameters
symbols_info (Optional[List[Dict]]) – details on the symbols to fetch repays on. Each dictionary needs the fields ‘asset’ and ‘ref_asset’. If not provided, will update all isolated symbols.
- Returns
None
- Return type
None
-
update_isolated_margin_trades(symbols_info: Optional[List[Dict]] = None)[source]¶ This update the isolated margin trades in the database for every trading pairs
- Parameters
symbols_info (Optional[List[Dict]]) – details on the symbols to fetch trades on. Each dictionary needs the fields ‘asset’ and ‘ref_asset’. If not provided, will update all isolated symbols.
- Returns
None
- Return type
None
-
update_isolated_margin_transfers(symbols_info: Optional[List[Dict]] = None)[source]¶ Update the transfers to and from isolated symbols
- Parameters
symbols_info (Optional[List[Dict]]) – details on the symbols to fetch repays on. Each dictionary needs the fields ‘asset’ and ‘ref_asset’. If not provided, will update all isolated symbols.
- Returns
None
- Return type
None
-
update_isolated_symbol_transfers(isolated_symbol: str)[source]¶ Update the transfers made to and from an isolated margin symbol
sources: https://binance-docs.github.io/apidocs/spot/en/#get-isolated-margin-transfer-history-user_data
- Parameters
isolated_symbol (str) – isolated margin symbol of trading
- Returns
- Return type
-
update_lending()[source]¶ call all update methods related to lending activities
- Returns
None
- Return type
None
-
update_lending_interests()[source]¶ update the lending interests database.
sources: https://python-binance.readthedocs.io/en/latest/binance.html#binance.client.Client.get_lending_interest_history https://binance-docs.github.io/apidocs/spot/en/#get-interest-history-user_data-2
- Returns
None
- Return type
None
-
update_lending_purchases()[source]¶ update the lending purchases database.
sources: https://python-binance.readthedocs.io/en/latest/binance.html#binance.client.Client.get_lending_purchase_history https://binance-docs.github.io/apidocs/spot/en/#get-purchase-record-user_data
- Returns
None
- Return type
None
-
update_lending_redemptions()[source]¶ update the lending redemptions database.
sources: https://python-binance.readthedocs.io/en/latest/binance.html#binance.client.Client.get_lending_redemption_history https://binance-docs.github.io/apidocs/spot/en/#get-redemption-record-user_data
- Returns
None
- Return type
None
-
update_margin_asset_loans(asset: str, isolated_symbol: Optional[str] = None)[source]¶ update the loans database for a specified asset.
sources: https://binance-docs.github.io/apidocs/spot/en/#query-loan-record-user_data https://python-binance.readthedocs.io/en/latest/binance.html#binance.client.Client.get_margin_loan_details
- Parameters
asset (str) – asset for the loans
isolated_symbol (Optional[str]) – only for isolated margin, provide the trading symbol. Otherwise cross margin data will be updated
- Returns
None
- Return type
None
-
update_margin_asset_repay(asset: str, isolated_symbol: Optional[str] = None)[source]¶ update the repays database for a specified asset.
sources: https://binance-docs.github.io/apidocs/spot/en/#query-repay-record-user_data https://python-binance.readthedocs.io/en/latest/binance.html#binance.client.Client.get_margin_repay_details
- Parameters
asset (str) – asset for the repays
isolated_symbol (Optional[str]) – only for isolated margin, provide the trading symbol. Otherwise cross margin data will be updated
- Returns
None
- Return type
None
-
update_margin_interests(isolated_symbol: Optional[str] = None, show_pbar: bool = True)[source]¶ Update the interests for all cross margin assets or for a isolated margin symbol if provided.
sources: https://binance-docs.github.io/apidocs/spot/en/#query-repay-record-user_data
- Parameters
isolated_symbol (Optional[str]) – only for isolated margin, provide the trading symbol. Otherwise cross margin data will be updated
show_pbar (bool) – if the progress bar is displayed
- Returns
- Return type
-
update_margin_symbol_trades(asset: str, ref_asset: str, is_isolated: bool = False, limit: int = 1000)[source]¶ This update the margin trades in the database for a single trading pair. It will check the last trade id and will requests the all trades after this trade_id.
sources: https://binance-docs.github.io/apidocs/spot/en/#query-margin-account-39-s-trade-list-user_data https://python-binance.readthedocs.io/en/latest/binance.html#binance.client.Client.get_margin_trades
- Parameters
asset (string) – name of the asset in the trading pair (ex ‘BTC’ for ‘BTCUSDT’)
ref_asset (string) – name of the reference asset in the trading pair (ex ‘USDT’ for ‘BTCUSDT’)
is_isolated (bool) – if margin type is isolated, default False
limit (int) – max size of each trade requests
- Returns
None
- Return type
None
-
update_spot()[source]¶ call all update methods related to the spot account
- Returns
None
- Return type
None
-
update_spot_deposits(day_jump: float = 90)[source]¶ This fetch the crypto deposit made on the spot account from the last deposit time in the database to now. It is done with multiple call, each having a time window of day_jump days. The deposits are then saved in the database. Only successful deposits are fetched.
sources: https://python-binance.readthedocs.io/en/latest/binance.html#binance.client.Client.get_deposit_history https://binance-docs.github.io/apidocs/spot/en/#deposit-history-user_data
- Parameters
day_jump (float) – length of the time window for each call (max 90)
- Returns
None
- Return type
None
-
update_spot_dividends(day_jump: float = 90, limit: int = 500)[source]¶ update the dividends database (earnings distributed by Binance) sources: https://python-binance.readthedocs.io/en/latest/binance.html#binance.client.Client.get_asset_dividend_history https://binance-docs.github.io/apidocs/spot/en/#asset-dividend-record-user_data
- Parameters
day_jump (float) – length of the time window in days, max is 90
limit (int) – max number of dividends to retrieve per call, max is 500
- Returns
None
- Return type
None
-
update_spot_dusts()[source]¶ update the dust database. As there is no way to get the dust by id or timeframe, the table is cleared for each update
sources: https://python-binance.readthedocs.io/en/latest/binance.html#binance.client.Client.get_dust_log https://binance-docs.github.io/apidocs/spot/en/#dustlog-user_data
- Returns
None
- Return type
None
-
update_spot_symbol_trades(asset: str, ref_asset: str, limit: int = 1000)[source]¶ This update the spot trades in the database for a single trading pair. It will check the last trade id and will requests the all trades after this trade_id.
sources: https://python-binance.readthedocs.io/en/latest/binance.html#binance.client.Client.get_my_trades https://binance-docs.github.io/apidocs/spot/en/#account-trade-list-user_data
- Parameters
asset (string) – name of the asset in the trading pair (ex ‘BTC’ for ‘BTCUSDT’)
ref_asset (string) – name of the reference asset in the trading pair (ex ‘USDT’ for ‘BTCUSDT’)
limit (int) – max size of each trade requests
- Returns
None
- Return type
None
-
update_spot_withdraws(day_jump: float = 90)[source]¶ This fetch the crypto withdraws made on the spot account from the last withdraw time in the database to now. It is done with multiple call, each having a time window of day_jump days. The withdraws are then saved in the database. Only successful withdraws are fetched.
sources: https://python-binance.readthedocs.io/en/latest/binance.html#binance.client.Client.get_withdraw_history https://binance-docs.github.io/apidocs/spot/en/#withdraw-history-user_data
- Parameters
day_jump (float) – length of the time window for each call (max 90)
- Returns
None
- Return type
None
-
update_universal_transfers(transfer_filter: Optional[str] = None)[source]¶ update the universal transfers database.
sources: https://python-binance.readthedocs.io/en/latest/binance.html#binance.client.Client.query_universal_transfer_history https://binance-docs.github.io/apidocs/spot/en/#query-user-universal-transfer-history
- Parameters
transfer_filter (Optional[str]) – if not None, only the transfers containing this filter will be updated (ex: ‘MAIN’)
- Returns
None
- Return type
None
-