pyupbit Documentation

repository·master·Indexed 20 days ago

https://github.com/sharebook-kr/pyupbit

A Python wrapper for the Upbit API providing access to cryptocurrency market data and exchange functions. It includes a Quotation API for retrieving tickers, current prices, and OHLCV chart data, as well as an Exchange API for managing account balances, placing limit and market orders, and handling deposits and withdrawals. The library also supports real-time data updates via WebSocketManager and WebSocketClient.

Tokens
4.6K
Snippets
24
Records
25
Agent score
68%

What's inside pyupbit

  1. Use the Quotation API for market data

    master

    The Quotation API allows you to retrieve market data, order books, and tickers without an API key.

    Rate Limits:

    • Ticker, Candle, Trade, and Orderbook APIs: 10 requests per second, 600 requests per minute.
    • Websocket: 5 connection requests per second, 100 requests per minute.
  2. Authenticate with the Upbit Exchange API

    master

    To perform private operations like checking balances or placing orders, you must create an Upbit object using your Upbit Access Key and Secret Key. This is equivalent to logging into the Upbit website.

    Rate Limits:

    • Orders: 8 requests per second, 200 requests per minute.
    • Non-order requests: 30 requests per second, 900 requests per minute.
    import pyupbit
    
    access = "YOUR_ACCESS_KEY"
    secret = "YOUR_SECRET_KEY"
    upbit = pyupbit.Upbit(access, secret)
  3. Initialize the Upbit Exchange client

    master

    To use the Exchange API for orders, withdrawals, deposits, and asset management, you must first initialize the Upbit class using your Upbit API access and secret keys.

    import pyupbit 
    
    access = "access key"  
    secret = "secret key"
    upbit = Upbit(access, secret)
  4. Retrieve service and API key information

    master

    The Exchange API allows you to monitor service status and your own API credentials:

    • Check API key list: Use upbit.get_api_key_list() to retrieve a list of your API keys and their expiration dates.
    • Check deposit/withdrawal status: Monitor the current status of inflows and outflows.
    import pyupbit 
    
    access = "access key"  
    secret = "secret key"
    upbit = Upbit(access, secret)
    
    api_key_info = upbit.get_api_key_list()
    print(api_key_info)
  5. Retrieve ticker lists with get_tickers()

    master

    Use pyupbit.get_tickers() to fetch available market tickers. You can filter the results by market type (e.g., 'KRW', 'BTC', 'USDT').

    import pyupbit
    
    # Get all available tickers
    tickers = pyupbit.get_tickers()
    
    # Get tickers for the KRW market
    krw_tickers = pyupbit.get_tickers("KRW")
    
    # Get tickers for the BTC market
    btc_tickers = pyupbit.get_tickers("BTC")
    
    # Get tickers for the USDT market
    usdt_tickers = pyupbit.get_tickers("USDT")
  6. Check account balances

    master

    Use the Upbit instance to retrieve balance information.

    • get_balance(ticker): Returns the quantity of a specific ticker (e.g., "KRW-XRP" or "KRW" for cash).
    • get_balances(): Returns a list of dictionaries containing all held cryptocurrencies, including their balances and average buy prices.
    # Check specific ticker balance
    print(upbit.get_balance("KRW-XRP"))
    
    # Check KRW cash balance
    print(upbit.get_balance("KRW"))
    
    # Check all balances
    print(upbit.get_balances())
  7. Manage orders with the Exchange API

    master

    The Exchange API provides several methods for managing trading activity:

    • Check order availability: Use upbit.get_chance(market) (e.g., "KRW-BTC") to check orderable information for a specific market.
    • Cancel an order: Use upbit.cancel_order(uuid) with the specific order UUID to cancel a pending order.
    • Retrieve individual order: Query details for a specific order using its UUID.
    • List orders: Retrieve a list of recent orders.
    • Place an order: Execute new buy or sell orders.
    # Check order availability
    chance = upbit.get_chance("KRW-BTC")
    
    # Cancel an order
    import pyupbit
    access = "access key"
    secret = "secret key"
    upbit = Upbit(access, secret)
    uuid = "uuid"  # The UUID of the order to cancel
    cancel_result = upbit.cancel_order(uuid)
    print(cancel_result)
  8. Get orderbook information

    master

    The get_orderbook function retrieves the current buy/sell orderbook (quotes) information.

    • You can pass a single ticker string or a list of tickers.
    • The return value is a list of dictionaries containing:
      • market: The ticker.
      • timestamp: The query time in milliseconds.
      • total_ask_size: Total ask size.
      • total_bid_size: Total bid size.
      • orderbook_units: A list of dictionaries containing ask_price, bid_price, ask_size, and bid_size for each price level.
    import pyupbit
    
    # Single ticker
    print(pyupbit.get_orderbook(ticker="KRW-BTC"))
    
    # Multiple tickers
    print(pyupbit.get_orderbook(ticker=["KRW-BTC", "KRW-XRP"]))