@coinset/bitmart
Version:
Universal BitMart API client
36 lines • 1.09 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",
"index_price",
"last_funding_rate",
"price_change_percent_24h",
"volume_24h",
"high_price",
"low_price",
"legal_coin_price",
].includes(key) && isString(value)) {
return Number(value);
}
return value;
};
/** Get the latest market quotations of the contract.
* ```ts
* import { fetchContract } from "https://deno.land/x/bitmart@$VERSION/mod.ts"
* await fetchContract()
* ```
* @see https://developer-pro.bitmart.com/en/contract/quotation/tickers.html
*/
export function fetchContract(options, init) {
const url = new URL("contract/v1/tickers", BASE_URL);
const _contractSymbol = options?.contractSymbol;
if (_contractSymbol) {
url.searchParams.set("contract_symbol", _contractSymbol);
}
return jsonFetch(url, init, {
parseJson: reviver,
});
}
//# sourceMappingURL=contract.js.map