UNPKG

@nepse-helper/core

Version:

A helper library for NEPSE

30 lines (29 loc) 1.04 kB
import { ENDPOINTS, nepseApi } from "../consts/api"; import { tokenStore } from "../consts/store/store"; export class Security { _axios = nepseApi; // cache securities securities = []; async getSecurityList() { if (this.securities.length > 0) { return this.securities; } const response = await this._axios .get(ENDPOINTS.api.nots.security.getSecurities) .then((res) => res.data); this.securities = response; return this.securities; } async getSecurityDetail(symbol) { const security = await this.getSecurityList().then((securities) => securities.find((security) => security.symbol.toLowerCase() === symbol.toLowerCase())); if (!security) { return null; } const response = await this._axios .post(`${ENDPOINTS.api.nots.security.getSecurity(security.id)}`, { id: tokenStore.get("magicNumber"), }) .then((res) => res.data); return response; } }