Skip to main content

GetCurrentPriceByTokenPair

Retrieves the current price for a specified token pair.

Returns the mid-market price for the base token denominated in the quote token.

Method Options​

Authorisation specification of the GetCurrentPriceByTokenPair method.

TypeMETHOD_TYPE_READ
Access LevelMETHOD_ACCESS_LEVEL_AUTHORISED
Roles
  • ROLE_MARKET_DATA_ADMIN
  • ROLE_MARKET_DATA_VIEWER
  • ROLE_MARKET_DATA_PRICE_ADMIN
  • ROLE_MARKET_DATA_PRICE_VIEWER

Parameters​

Request and response parameter message overview:

Input: GetCurrentPriceByTokenPairRequest Message​

FieldTypeRequiredDescription
BaseToken

meshtrade.type.v1.Token

True

The base token for which a price is required. This is the token being priced (e.g., BTC in a BTC/USD pair).

QuoteToken

meshtrade.type.v1.Token

True

The quote token in which the price should be denominated. This is the unit of measurement for the price (e.g., USD in a BTC/USD pair).

Returns: Price Message​

Code Examples​

Select supported SDK in the language of your choice for a full example of how to invoke the this method:

package main

import (
"context"
"log"

pricev1 "github.com/meshtrade/api/go/market_data/price/v1"
type_v1 "github.com/meshtrade/api/go/type/v1"
)

func main() {
ctx := context.Background()

// Default configuration is used and credentials come from MESH_API_CREDENTIALS
// environment variable or default discovery methods. Zero config required
// unless you want custom configuration.
service, err := pricev1.NewPriceService()
if err != nil {
log.Fatalf("Failed to create service: %v", err)
}
defer service.Close()

// Create request to get gold (XAU) price in ZAR
request := &pricev1.GetCurrentPriceByTokenPairRequest{
BaseToken: &type_v1.Token{
Code: "XAU", // Gold - the token to price
},
QuoteToken: &type_v1.Token{
Code: "ZAR", // South African Rand - the currency to price it in
},
}

// Call the GetCurrentPriceByTokenPair method
price, err := service.GetCurrentPriceByTokenPair(ctx, request)
if err != nil {
log.Fatalf("GetCurrentPriceByTokenPair failed: %v", err)
}

// Display the price information
log.Printf("Price retrieved successfully:")
log.Printf(" Base Token: %s", price.BaseToken.Code)
log.Printf(" Quote Token: %s", price.QuoteToken.Code)
log.Printf(" Mid Price: %s", price.MidPrice.Value)
log.Printf(" Timestamp: %s", price.Time.AsTime())
}

Advanced Configuration​

For advanced client configuration options (custom endpoints, TLS settings, timeouts), see the SDK Configuration Guide.

Other Methods​