UNPKG

@shogun-sdk/money-legos

Version:

Shogun Money Legos: clients and types for quotes, memes, prices, balances, fees, validations, etc.

95 lines 4.07 kB
import { InfoType } from '../../types/constants.js'; export class PerpetualsInfoAPI { constructor(httpApi, symbolConversion, parent) { Object.defineProperty(this, "httpApi", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "symbolConversion", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "parent", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.httpApi = httpApi; this.symbolConversion = symbolConversion; this.parent = parent; } async getMeta(rawResponse = false) { await this.parent.ensureInitialized(); const response = await this.httpApi.makeRequest({ type: InfoType.META }); return rawResponse ? response : await this.symbolConversion.convertResponse(response, ['name', 'coin', 'symbol'], 'PERP'); } async getMetaAndAssetCtxs(rawResponse = false) { await this.parent.ensureInitialized(); const response = await this.httpApi.makeRequest({ type: InfoType.PERPS_META_AND_ASSET_CTXS }); return rawResponse ? response : await this.symbolConversion.convertResponse(response, ['name', 'coin', 'symbol'], 'PERP'); } async getClearinghouseState(user, rawResponse = false) { await this.parent.ensureInitialized(); const response = await this.httpApi.makeRequest({ type: InfoType.PERPS_CLEARINGHOUSE_STATE, user: user }); return rawResponse ? response : await this.symbolConversion.convertResponse(response); } async getUserFunding(user, startTime, endTime, rawResponse = false) { await this.parent.ensureInitialized(); const response = await this.httpApi.makeRequest({ type: InfoType.USER_FUNDING, user: user, startTime: startTime, endTime: endTime, }, 20); return rawResponse ? response : await this.symbolConversion.convertResponse(response); } async getUserNonFundingLedgerUpdates(user, startTime, endTime, rawResponse = false) { await this.parent.ensureInitialized(); const response = await this.httpApi.makeRequest({ type: InfoType.USER_NON_FUNDING_LEDGER_UPDATES, user: user, startTime: startTime, endTime: endTime, }, 20); return rawResponse ? response : await this.symbolConversion.convertResponse(response); } async getFundingHistory(coin, startTime, endTime, rawResponse = false) { await this.parent.ensureInitialized(); const response = await this.httpApi.makeRequest({ type: InfoType.FUNDING_HISTORY, coin: await this.symbolConversion.convertSymbol(coin, 'reverse'), startTime: startTime, endTime: endTime, }, 20); return rawResponse ? response : await this.symbolConversion.convertResponse(response); } async getPredictedFundings(rawResponse = false) { await this.parent.ensureInitialized(); const response = await this.httpApi.makeRequest({ type: InfoType.PREDICTED_FUNDINGS, }, 20); return rawResponse ? response : await this.symbolConversion.convertResponse(response); } async getPerpsAtOpenInterestCap(rawResponse = false) { await this.parent.ensureInitialized(); const response = (await this.httpApi.makeRequest({ type: InfoType.PERPS_AT_OPEN_INTEREST_CAP, })); if (rawResponse) { return response; } // Convert each symbol in the array const convertedResponse = await Promise.all(response.map((symbol) => this.symbolConversion.convertSymbol(symbol, '', 'PERP'))); return convertedResponse; } } //# sourceMappingURL=perpetuals.js.map