/exchange/candlesticks

Retrieves candle stick data for a market.

Recent Requests
Log in to see full request history
TimeStatusUser Agent
Retrieving recent requests…
LoadingLoading…

Client Library

#!/usr/bin/env python

import asyncio
import logging

from bluefin_pro_sdk import BluefinProSdk, Environment, RpcUrl
from crypto_helpers.signature import SuiWallet

# Set up logging
logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__name__)


async def main():
    """
    Example showing how to fetch candlesticks for BTC-PERP from the Bluefin Pro API
    using the PRODUCTION environment.
    """
    # Create a wallet with your private key
    sui_wallet = SuiWallet(
        mnemonic="dilemma salmon lake ceiling moral glide cute that ginger float area aunt vague remind cage mother concert inch dizzy present proud program time urge"
    )

    log.info(f"Using wallet address: {sui_wallet.sui_address}")
    
    # Initialize the Bluefin Pro SDK client with PRODUCTION environment and RPC
    async with BluefinProSdk(
            sui_wallet=sui_wallet,
            contracts=None,  # Not needed for this example
            rpc_url=RpcUrl.PROD,
            env=Environment.PRODUCTION,
            debug=False  # Set to True for more verbose output
    ) as client:
        try:
            # Initialize the client, which will handle authentication
            await client.init()

            # Get candlesticks for BTC-PERP
            response = await client.exchange_data_api.get_recent_trades(symbol="BTC-PERP")

            # Log the response
            log.info("BTC-PERP Candlesticks Information:")
            log.info(f"{response=}")

            # Return the response for further use if needed
            return response

        except Exception as e:
            log.error(f"Error fetching exchange info: {e}")
            raise


if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        log.info("Exiting due to keyboard interrupt")
use bluefin_api::apis::configuration::Configuration;
use bluefin_api::apis::exchange_api::get_candlestick_data;
use bluefin_api::models::{CandlePriceType, KlineInterval};
use bluefin_pro::prelude::*;

type Error = Box<dyn std::error::Error>;
type Result<T> = std::result::Result<T, Error>;

#[tokio::main]
async fn main() -> Result<()> {
    let response = get_candlestick_data(
        &Configuration {
            base_path: exchange::mainnet::URL.into(),
            ..Configuration::default()
        },
        symbols::perps::BTC,       // symbol
        KlineInterval::Variant1m, // interval
        CandlePriceType::Last,     // type
        None,                      // start_time_at_millis
        None,                      // end_time_at_millis
        None,                      // limit
        None,                      // page
    )
    .await?;

    println!("{response:#?}");

    Ok(())
}

HTTPs

Alternatively, call the GET /exchange/candlesticks endpoint using the integrated editor on the right or locally from any language supporting HTTPs network calls.

Request & Response

Query Params
string
required

The market symbol to get the klines for.

string
enum
required

The interval to get the klines for.

string
enum
required

Candle price type (last price, market price or oracle).

Allowed:
int64
≥ 0

Timestamp in milliseconds in ms to get klines from.

int64
≥ 0

Timestamp in milliseconds in ms to get klines until.

int32
0 to 1000
Defaults to 50

Default 50; max 1000.

int32
≥ 1

The page number to retrieve in a paginated response.

Response

Language
URL
LoadingLoading…
Response
Click Try It! to start a request and see the response here! Or choose an example:
application/json