@shogun-sdk/money-legos
Version:
Shogun Money Legos: clients and types for quotes, memes, prices, balances, fees, validations, etc.
66 lines (56 loc) • 2.5 kB
text/typescript
import { SpotMeta, SpotClearinghouseState, SpotMetaAndAssetCtxs } from '../../types/index.js';
import { HttpApi } from '../../utils/httpApi.js';
import { InfoType } from '../../types/constants.js';
import { SymbolConversion } from '../../utils/symbolConversion.js';
import { Hyperliquid } from '../../index.js';
export class SpotInfoAPI {
private httpApi: HttpApi;
private symbolConversion: SymbolConversion;
private parent: Hyperliquid;
constructor(httpApi: HttpApi, symbolConversion: SymbolConversion, parent: Hyperliquid) {
this.httpApi = httpApi;
this.symbolConversion = symbolConversion;
this.parent = parent;
}
async getMeta(rawResponse: boolean = false): Promise<SpotMeta> {
await this.parent.ensureInitialized();
const response = await this.httpApi.makeRequest<any>({ type: InfoType.SPOT_META });
return rawResponse
? response
: await this.symbolConversion.convertResponse(response, ['name', 'coin', 'symbol'], 'SPOT');
}
async getSpotClearinghouseState(user: string, rawResponse: boolean = false): Promise<SpotClearinghouseState> {
await this.parent.ensureInitialized();
const response = await this.httpApi.makeRequest<any>({ type: InfoType.SPOT_CLEARINGHOUSE_STATE, user: user });
return rawResponse
? response
: await this.symbolConversion.convertResponse(response, ['name', 'coin', 'symbol'], 'SPOT');
}
async getSpotMetaAndAssetCtxs(rawResponse: boolean = false): Promise<SpotMetaAndAssetCtxs> {
await this.parent.ensureInitialized();
const response = await this.httpApi.makeRequest<any>({ type: InfoType.SPOT_META_AND_ASSET_CTXS });
return rawResponse ? response : await this.symbolConversion.convertResponse(response);
}
async getTokenDetails(tokenId: string, rawResponse: boolean = false): Promise<any> {
await this.parent.ensureInitialized();
const response = await this.httpApi.makeRequest<any>(
{
type: InfoType.TOKEN_DETAILS,
tokenId: tokenId,
},
20,
);
return rawResponse ? response : await this.symbolConversion.convertResponse(response);
}
async getSpotDeployState(user: string, rawResponse: boolean = false): Promise<any> {
await this.parent.ensureInitialized();
const response = await this.httpApi.makeRequest<any>(
{
type: InfoType.SPOT_DEPLOY_STATE,
user: user,
},
20,
);
return rawResponse ? response : await this.symbolConversion.convertResponse(response);
}
}