Skip to main content

QueryAssetRates

QueryAssetRates retrieves the exchange rate between a tap asset and BTC for a specified transaction type, subject asset, and payment asset. The asset rate represents the number of tap asset units per BTC.

Source: priceoraclerpc/price_oracle.proto

gRPC

rpc QueryAssetRates (QueryAssetRatesRequest) returns (QueryAssetRatesResponse);

REST

HTTP MethodPath
GET /v1/taproot-assets/rfq/priceoracle/assetrates

Code Samples

const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');

const GRPC_HOST = 'localhost:10029'
const MACAROON_PATH = 'TAPROOT-ASSETS_DIR/regtest/taproot-assets.macaroon'
const TLS_PATH = 'TAPROOT-ASSETS_DIR/tls.cert'

const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
};
const packageDefinition = protoLoader.loadSync('priceoraclerpc/price_oracle.proto', loaderOptions);
const priceoraclerpc = grpc.loadPackageDefinition(packageDefinition).priceoraclerpc;
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const tlsCert = fs.readFileSync(TLS_PATH);
const sslCreds = grpc.credentials.createSsl(tlsCert);
const macaroon = fs.readFileSync(MACAROON_PATH).toString('hex');
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let client = new priceoraclerpc.PriceOracle(GRPC_HOST, creds);
let request = {
transaction_type: <TransactionType>,
subject_asset: <AssetSpecifier>,
subject_asset_max_amount: <uint64>,
payment_asset: <AssetSpecifier>,
payment_asset_max_amount: <uint64>,
asset_rates_hint: <AssetRates>,
};
client.queryAssetRates(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "ok": <QueryAssetRatesOkResponse>,
// "error": <QueryAssetRatesErrResponse>,
// }

Messages

priceoraclerpc.QueryAssetRatesRequest

Source: priceoraclerpc/price_oracle.proto

FieldgRPC TypeREST TypeREST Placement
transaction_type
TransactionTypeobjectquery
subject_asset
AssetSpecifierobjectquery
subject_asset_max_amount
uint64stringquery
payment_asset
AssetSpecifierobjectquery
payment_asset_max_amount
uint64stringquery
asset_rates_hint
AssetRatesobjectquery

priceoraclerpc.QueryAssetRatesResponse

Source: priceoraclerpc/price_oracle.proto

FieldgRPC TypeREST Type
ok
QueryAssetRatesOkResponseobject
error
QueryAssetRatesErrResponseobject

Nested Messages

priceoraclerpc.AssetRates

FieldgRPC TypeREST Type
subjectAssetRate
FixedPointobject
paymentAssetRate
FixedPointobject
expiry_timestamp
uint64string

priceoraclerpc.AssetSpecifier

FieldgRPC TypeREST Type
asset_id
bytesstring
asset_id_str
stringstring
group_key
bytesstring
group_key_str
stringstring

priceoraclerpc.FixedPoint

FieldgRPC TypeREST Type
coefficient
stringstring
scale
uint32integer

priceoraclerpc.QueryAssetRatesErrResponse

FieldgRPC TypeREST Type
message
stringstring
code
uint32integer

priceoraclerpc.QueryAssetRatesOkResponse

FieldgRPC TypeREST Type
asset_rates
AssetRatesobject

Enums

priceoraclerpc.TransactionType

NameNumber
PURCHASE
0
SALE
1