R
R
Redstone API
Github
NPM
Website
Discord
Search…
1.0.0
What is Redstone API
Getting started
Installation
Usage
Methods
getPrice
getHistoricalPrice
getAllPrices
query
Fluent interface
Redstone query
HTTP API
Prices HTTP Api
Knowledge base
Cache layer
Signature verification
Provider
Links
Github repo
NPM
Website
Discord
Powered By
GitBook
getPrice
getPrice method is used to fetch the latest price for a single or multiple tokens
Get the latest price for a single token
▸
getPrice
(
symbol
:
string
,
opts?
: GetPriceOptions): _Promise<_PriceData>
Returns the latest price for a single symbol
Parameters:
Name
Type
Description
symbol
string
Token symbol (string)
opts?
GetPriceOptions
Optional params (object)
opts.provider:
provider name (string)
opts.verifySignature
: enable signature verification (boolean)
Returns:
Promise
<PriceData>
The latest price for the token
Get the latest price for multiple tokens
▸
getPrice
(
symbols
:
string
[],
opts?
: GetPriceOptions):
Promise
<{ [token: string]: PriceData; }>
Returns the latest price for several symbols
Parameters:
Name
Type
Description
symbols
string
[]
Token symbols (array of strings)
opts?
GetPriceOptions
Optional params (object)
opts.provider:
provider name (string)
opts.verifySignature
: enable signature verification (boolean)
Returns:
Promise
<{ [token: string]: PriceData; }>
The latest price for the tokens
Examples
Get the latest price for a single token
1
const
price
=
await
redstone
.
getPrice
(
"AR"
);
2
3
console
.
log
(
price
.
value
);
// latest price value for AR token (in USD)
4
console
.
log
(
price
.
timestamp
);
// the exact timestamp of the price
Copied!
All the prices are denominated in USD. You can fetch price data for BTC, ETH, AR, EUR and any other of
100+ supported tokens
Price data format
1
{
2
value
:
123.23
,
// Number: Price value in USD
3
timestamp
:
1617146511173
,
// Number: Timestamp (ms) for price
4
provider
:
"I-5rWUehEv-MjdK9gFw09RxfSLQX9DIHxG614Wf8qo0"
,
// String: Provider arweave address
5
permawebTx
:
"V8FUU0BG4kVOJwKWHzgkn1aEFm-eanhqqEXfPFY7pmI"
,
// String: Arweave transaction id
6
source
:
{
"coingecko"
:
123
,
"sushiswap"
:
123.23
,
"uniswap"
:
123.35
},
// Object: Prices from different sources
7
}
Copied!
Fetch price using promises
1
// As async/await is only a syntactic sugar on Javascript
2
// Promises you can use them in a "standard" way
3
const
price
=
redstone
.
getPrice
(
"AR"
).
then
((
price
)
=>
{
4
console
.
log
(
price
.
value
);
// latest price value for AR token
5
});
Copied!
Get the latest prices for multiple tokens
To fetch prices for multiple tokens use the
getPrice
method and pass an array with a subset of
supported tokens
.
1
const
prices
=
await
redstone
.
getPrice
([
"BTC"
,
"ETH"
,
"AR"
,
"EUR"
]);
2
3
console
.
log
(
prices
);
// Example output below
4
/*
5
{
6
"BTC": {
7
value: 58953.39,
8
timestamp: 1617152802779,
9
...
10
},
11
"ETH": {
12
value: 1856.75,
13
timestamp: 1617152802779,
14
...
15
},
16
...
17
}
18
*/
19
20
21
console
.
log
(
prices
[
"BTC"
].
value
);
// latest price value for BTC
22
console
.
log
(
prices
[
"ETH"
].
value
);
// latest price value for ETH
23
console
.
log
(
prices
[
"AR"
].
value
);
// latest price value for AR
Copied!
Getting started - Previous
Usage
Next - Methods
getHistoricalPrice
Last modified
11mo ago
Copy link
Contents
Get the latest price for a single token
Get the latest price for multiple tokens
Examples
Get the latest price for a single token
Price data format
Fetch price using promises
Get the latest prices for multiple tokens