24-Hour Cumulative Trade Price
The Upbit API provides a variety of data to support convenient trade analysis. Below is an example that retrieves the 24-hour accumulated trading price.
The full code examples can be found in the Recipes menu.
Click the button above to navigate to the full code Recipe page of this tutorial.
Get Started
This guide shows how to get all trading pairs from a user-specified Upbit market and find the top 5 pairs ranked by 24-hour cumulative trading price. A Python code example is included.
- Singapore (sg): https://sg-api.upbit.com
- Indonesia (id): https://id-api.upbit.com
- Thailand (th): https://th-api.upbit.com
List Trading Pairs
You can implement a function to List Trading Pairs from the Upbit market entered by the user as shown below. It processes the API response, which is a JSON array, and returns a comma-separated string of pair codes.
def list_markets(quote_currencies: str) -> str:
params = {
"quote_currencies": quote_currencies
}
url = "https://sg-api.upbit.com/v1/ticker/all"
headers = {
"Content-Type": "application/json"
}
response = requests.get(url, headers=headers, params=params)
market_list = [item.get("market") for item in response.json()]
string_market_list = ",".join(market_list)
return string_market_list
Getting the 24-Hour Cumulative Trading Price
You can use the List Tickers by Market API to check prices for multiple pairs at once. Just pass a comma-separated list of markets to the markets parameter.
In the response, look at the acc_trade_price_24h
field — this shows the 24-hour cumulative trading price for each pair.
[
{
"market": "SGD-BTC",
"trade_date": "20250704",
"trade_time": "051400",
"trade_timestamp": 1751606040365,
"opening_price": "148737000.00000000",
"high_price": "149360000.00000000",
"low_price": "148288000.00000000",
"trade_price": "148601000.00000000",
"prev_closing_price": "148737000.00000000",
"change": "FALL",
"change_price": 136000,
"change_rate": 0.0009143656,
"signed_change_price": "-136000.00000000",
"signed_change_rate": -0.0009143656,
"trade_volume": 0.00016823,
"acc_trade_price": 31615925234.05438,
"acc_trade_price_24h": 178448329314.96686,
"acc_trade_volume": 212.38911576,
"acc_trade_volume_24h": 1198.26954807,
"highest_52_week_price": 163325000,
"highest_52_week_date": "2025-01-20",
"lowest_52_week_price": 72100000,
"lowest_52_week_date": "2024-08-05",
"timestamp": 1751606040403
},
...
]
Implement a function that fetches the 24-hour cumulative trading price for all input pairs. The pairs are passed as a comma-separated string, and the function returns a mapping (e.g., dictionary) of each pair’s name to its 24-hour cumulative trading price.
def list_acc_trade_price_24h(trading_pairs: str) -> Mapping:
params = {
"markets": trading_pairs
}
url = "https://sg-api.upbit.com/v1/ticker"
headers = {
"Content-Type": "application/json"
}
response = requests.get(url, headers=headers, params=params).json()
all_acc_trade_price_24h = {item.get("market"): item.get("acc_trade_price_24h") for item in response}
return all_acc_trade_price_24h
Getting the Top 5 Trading Pairs by 24-Hour Cumulative Trading Price
Implement a function that checks the 24-hour cumulative trading price for all pairs, compares them, and returns the top 5 pairs with the highest prices.
def list_top_5_high_acc_trade_price_24h(list_acc_trade_price_24h: Mapping) -> Mapping:
top_5_list = {k: v for k, v in sorted(list_acc_trade_price_24h.items(), key=lambda x: x[1], reverse=True)[:5]}
return top_5_list
Code Execution Result
Run the code to see the top 5 pairs with the highest 24-hour cumulative trading price, along with each pair’s value, as shown below.
if __name__ == "__main__":
markets = list_markets("SGD")
list_price_24h = list_acc_trade_price_24h(markets)
top_5_price_24h = list_top_5_high_acc_trade_price_24h(list_price_24h)
print(top_5_price_24h)
{
"SGD-BTC": 658205168.2153,
"SGD-ETH": 385094335.0046,
"SGD-XRP": 244286558.6853,
"SGD-SOL": 226701310.52917,
"SGD-USDT": 219180445.17462,
}
Full Code Example
Here’s the full code that fetches the top 5 trading pairs with the highest 24-hour cumulative trading price from the user-specified Upbit market.
import requests
def list_markets(quote_currencies: str) -> str:
"""
Get all trading pairs from the Upbit market entered by the user and returns their names as a comma-separated string.
"""
params = {
"quote_currencies": quote_currencies
}
url = f"https://sg-api.upbit.com/v1/ticker/all"
headers = {
"Content-Type": "application/json"
}
response = requests.get(url, headers=headers, params=params)
market_list = [item['market'] for item in response.json()]
string_market_list = ",".join(market_list)
return string_market_list
def list_acc_trade_price_24h(trading_pairs: str) -> list[tuple[str, float]]:
"""
Returns the 24-hour accumulated trading price for the input pairs.
"""
params = {
"markets": trading_pairs
}
url = f"https://sg-api.upbit.com/v1/ticker"
headers = {
"Content-Type": "application/json"
}
response = requests.get(url, headers=headers, params=params).json()
all_acc_trade_price_24h = {item['market']: item['acc_trade_price_24h'] for item in response}
return all_acc_trade_price_24h
def list_top_5_high_acc_trade_price_24h(list_acc_trade_price_24h: list[tuple[str, float]]) -> list[tuple[str, float]]:
"""
Getting the Top 5 Trading Pairs with the Highest 24-hour Cumulative Trading Price
"""
top_5_list = {k: v for k, v in sorted(list_acc_trade_price_24h.items(), key=lambda x: x[1], reverse=True)[:5]}
return top_5_list
if __name__ == "__main__":
markets = list_markets("BTC")
list_acc_trade_price_24h = list_acc_trade_price_24h(markets)
top_5_acc_trade_price_24h = list_top_5_high_acc_trade_price_24h(list_acc_trade_price_24h)
print(top_5_acc_trade_price_24h)
Updated 9 days ago