@coinset/bitmart
Version:
Universal BitMart API client
45 lines • 1.32 kB
JavaScript
import { jsonFetch } from "./_utils.js";
import { BASE_URL } from "./constants.js";
import { isString } from "../deps.js";
const reviver = (key, value) => {
if ([
"last_price",
"quote_volume_24h",
"base_volume_24h",
"high_24h",
"low_24h",
"open_24h",
"close_24h",
"best_ask",
"best_ask_size",
"best_bid",
"best_bid_size",
"fluctuation",
]
.includes(key) && isString(value)) {
return Number(value);
}
return value;
};
/** Ticker is an overview of the market status of a trading pair, including the latest trade price, top bid and ask prices and 24-hour trading volume.
* ```ts
* import { fetchTicker } from "https://deno.land/x/bitmart@$VERSION/mod.ts"
* await fetchTicker({symbol: "BTC_USDT" })
* ```
* @see https://developer-pro.bitmart.com/en/spot/quotation/ticker.html
*/
export async function fetchTicker({ symbol }, init) {
const url = new URL("spot/v1/ticker", BASE_URL);
url.searchParams.set("symbol", symbol);
const { data: { tickers: [ticker] }, ...rest } = await jsonFetch(url, init, {
parseJson: reviver,
});
return {
...rest,
data: {
ticker,
},
};
}
export { reviver };
//# sourceMappingURL=ticker.js.map