Package: cb-exchange-lib
cb-exchange-libCoinbase Exchange API client library.Installation:python -m pip install [--upgrade] cb-exchange-libEndpoints:Info:Private endpoints require authentication using your Coinbase Exchange API key.
You can generate API keyshere.Private:AccountsAddressBookCoinbaseAccountsConversionsDepositsPaymentMethodsTransfersWithdrawalsFeesFillsOrdersOracleProfilesReportsUsersPublic:TimeCurrenciesProductsWrappedAssetsAny endpoint can take these keyword arguments:environment: str - The API environment:productionorsandbox(defaults to:production);retries: int - Total number of retries to allow (defaults to:3);backoff: int - A backoff factor to apply between attempts after the second try (defaults to:1);timeout: int - How long to wait for the server to send data before giving up (defaults to:30);cache: bool - Use caching (defaults to:True);debug: bool - Set to True to log all requests/responses to/from server (defaults to:False);logger: Logger - The handler to be used for logging. If given, and level is aboveDEBUG,
all debug messages will be ignored.For private endpoints only:key: str - The API key;passphrase: str - The API passphrase;secret: str - The API secret.Any of the endpoints can be instantiated or used as a context-manager:fromcb_exchange_libimportTime,Accountsenvironment:str="sandbox"credentials:dict={"key":"your key","passphrase":"your passphrase","secret":"your secret",}# be careful where you keep your credentials!if__name__=='__main__':print("*"*80)endpoint=Accounts(**credentials,environment=environment)accounts=endpoint.get_accounts()foraccountinaccounts:print(account)endpoint.close()# orwithTime(environment=environment)asendpoint:print("*"*80)time=endpoint.get_time()print(time)Resources:For each mapped resource you must read thedocumentation.
All the parameters these resources can take are described in the official documentation.Timeget_time()Get the API server time.Accountsget_accounts()Get a list of trading accounts from the profile of the API key.get_account()Information for a single account. Use this endpoint when you know the account_id. API key must belong to the same
profile as the account.get_account_holds()List the holds of an account that belong to the same profile as the API key. Holds are placed on an account for any
active orders or pending withdraw requests. As an order is filled, the hold amount is updated. If an order is
canceled, any remaining hold is removed. For withdrawals, the hold is removed after it is completed.get_account_ledger()Lists ledger activity for an account. This includes anything that would affect the accounts balance - transfers,
trades, fees, etc. List account activity of the API key's profile. Account activity either increases or decreases
your account balance.get_account_transfers()Lists past withdrawals and deposits for an account.AddressBookget_addresses()Get all addresses stored in the address book.CoinbaseAccountsget_wallets()Gets all the user's available Coinbase wallets (These are the wallets/accounts that are used for buying and selling
onwww.coinbase.com)generate_crypto_address()Generates a one-time crypto address for depositing crypto.Info:You can generate an address for crypto deposits.
See theCoinbase Accountssection for information on how to retrieve your coinbase account ID.Conversionsconvert_currency()Converts funds fromfromcurrency totocurrency. Funds are converted on thefromaccount in theprofile_idprofile.Caution:Users whose USD and USDC accounts are unified do not have access to the conversion endpoint, and conversions from
USDC to USD are automatic upon deposit.get_conversion()Gets a currency conversion by id (i.e.41554f00-5c34-4f09-b800-2a878e52f2ea).Currenciesget_currencies()Gets a list of all known currencies.Note:Not all currencies may be currently in use for trading.get_currency()Gets a single currency by id.Depositsdeposit_from_coinbase_account()Deposits funds from awww.coinbase.comwallet to the specifiedprofile_id.deposit_from_payment_method()Deposits funds from a linked external payment method to the specifiedprofile_id.PaymentMethodsget_payment_methods()Gets a list of the user's linked payment methods.Transfersget_transfers()Gets a list of in-progress and completed transfers of funds in/out of any of the user's accounts.get_transfer()Get information on a single transfer.Withdrawalswithdraw_to_coinbase_account()Withdraws funds from the specifiedprofile_idto awww.coinbase.comwallet.withdraw_to_crypto_address()Withdraws funds from the specifiedprofile_idto an external crypto addressget_fee_estimate()Gets the fee estimate for the crypto withdrawal to crypto addresswithdraw_to_payment_method()Withdraws funds from the specifiedprofile_idto a linked external payment methodFeesget_fees()Get fees rates and 30 days trailing volume. This request returns your current maker & taker fee rates, as well as
your 30-day trailing volume. Quoted rates are subject to change. For more information, see What are the fees on
Coinbase Pro?.Fillsget_fills()Get a list of fills. A fill is a partial or complete match on a specific order. Get a list of recent fills of the
API key's profile.Ordersget_orders()List your current open orders. Only open or un-settled orders are returned by default. As soon as an order is no
longer open and settled, it will no longer appear in the default request. Open orders may change state between the
request and the response depending on market conditions.del_orders()With best effort, cancel all open orders. This may require you to make the request multiple times until all of the
open orders are deleted.create_order()Create an order. You can place two types of orders: limit and market. Orders can only be placed if your account has
sufficient funds. Once an order is placed, your account funds will be put on hold for the duration of the order.
How much and which funds are put on hold depends on the order type and parameters specified.Caution:Each profile can place a maximum of 500 open orders on a product. Once reached, the profile cannot place any new
orders until the total number of open orders is below 500.get_order()Get a single order byorder_id.del_order()Cancel a single open order byorder_id.Oracleget_signed_prices()Get cryptographically signed prices ready to be posted on-chain using Compound's Open Oracle smart contract.Productsget_products()Gets a list of available currency pairs for trading.get_product()Get information on a single product.get_product_book()Get a list of open orders for a product. The amount of detail shown can be customized with thelevelparameter.get_product_candles()Historic rates for a product. Rates are returned in grouped buckets. Candle schema is of the form:[timestamp, price_low, price_high, price_open, price_close]Info:Historical rate data may be incomplete. No data is published for intervals where there are no ticks.
Historical rates should not be polled frequently. If you need real-time information, use the trade and book
endpoints along with the WebSocket feed.get_product_stats()Gets 30day and 24hour stats for a product.Info:The volume property is in base currency units. Properties open, high, low are in quote currency units.get_product_ticker()Gets snapshot information about the last trade (tick), best bid/ask and 24h volume.Real-time updates:Coinbase recommends that you get real-time updates by connecting with the WebSocket stream and listening for match
messages, rather than polling.get_product_trades()Gets a list the latest trades for a product.Profilesget_profiles()Gets a list of all of the current user's profiles.create_profile()Create a new profile. Will fail if no name is provided or if user already has max number of profiles.transfer_funds()Transfer an amount of currency from one profile to another.get_profile()Information for a single profile. Use this endpoint when you know theprofile_id.rename_profile()Rename a profile. Names 'default' and 'margin' are reserved.del_profile()Deletes the profile specified byprofile_idand transfers all funds to the profile specified byto. Fails if
there are any open orders on the profile to be deleted.Reportsget_reports()Gets a list of all user generated reports.Info:Once a report request has been accepted for processing, you can poll the report resource endpoint at/reports/{report_id}for its status. When status is ready, the final report is uploaded and available atfile_url.create_report()Generates a report. You can create reports with historical data for all report types. Balance reports can be
snapshots of historical or current data. Reports provide batches of historic information about your profile in
various human and machine readable forms.Info:A report is generated when resources are available. You can poll the report resource endpoint at/reports/{report_id}for its status. When status is ready, the final report is uploaded and available atfile_url.get_report()Get a specific report by report_id.Info:Once a report request has been accepted for processing, you can poll the report resource endpoint at/reports/{report_id}for its status. When status is ready, the final report is uploaded and available atfile_url.Usersget_exchange_limits()Gets exchange limits information for a single user.Info:This request returns information on your payment method transfer limits, as well as buy/sell limits per currency.WrappedAssetsget_assets()Returns a list of all supported wrapped assets details objects.get_asset_details()Returns the circulating and total supply of a wrapped asset, and its conversion rate.get_asset_conversion_rate()Returns the conversion rate of a wrapped asset.Websocket clients:Any of the websocket clients can take these keyword arguments:channels: The channels for subscription;product_ids: The products IDs for subscription;environment: The API environment:productionorsandbox(defaults to:production);debug: Set to True to log all requests/responses to/from server (defaults to:False);logger: The handler to be used for logging; If given, and level is aboveDEBUG,
all debug messages will be ignored.Note:For information about Websocket feed channels visit thedocumentation.ForDirectMarketDataonly:key: The API key;passphrase: The API passphrase;secret: The API secret;Examples:MarketDatafromcb_exchange_libimportMarketDataenvironment:str="sandbox"if__name__=='__main__':client=MarketData(environment=environment,debug=True,channels=["ticker"],product_ids=["BTC-USD"],)client.listen()try:foriteminclient.queue:print(item)exceptKeyboardInterrupt:client.close()DirectMarketDatafromcb_exchange_libimportDirectMarketDataenvironment:str="sandbox"credentials:dict={"key":"your key","passphrase":"your passphrase","secret":"your secret",}# be careful where you keep your credentials!if__name__=='__main__':client=DirectMarketData(**credentials,environment=environment,debug=True,channels=[{"name":"ticker","product_ids":["BTC-USD"]}])client.listen()try:foriteminclient.queue:print(item)exceptKeyboardInterrupt:client.close()