Merge pull request #287 from ThijmenMaus/fix(#286)--automatic-type-determination-for-instrument-info

fix(#286): automatic type determination for instrument info
This commit is contained in:
Tiago
2023-09-12 10:46:27 +01:00
committed by GitHub
2 changed files with 12 additions and 7 deletions

View File

@@ -231,9 +231,9 @@ export class RestClientV5 extends BaseRestClient {
* *
* Note: Spot does not support pagination, so limit & cursor are invalid. * Note: Spot does not support pagination, so limit & cursor are invalid.
*/ */
getInstrumentsInfo( getInstrumentsInfo<C extends CategoryV5>(
params: GetInstrumentsInfoParamsV5, params: GetInstrumentsInfoParamsV5 & { category: C },
): Promise<APIResponseV3WithTime<InstrumentInfoResponseV5>> { ): Promise<APIResponseV3WithTime<InstrumentInfoResponseV5<C>>> {
return this.get('/v5/market/instruments-info', params); return this.get('/v5/market/instruments-info', params);
} }

View File

@@ -1,5 +1,6 @@
import { import {
CategoryCursorListV5, CategoryCursorListV5,
CategoryV5,
ContractTypeV5, ContractTypeV5,
InstrumentStatusV5, InstrumentStatusV5,
OptionTypeV5, OptionTypeV5,
@@ -110,10 +111,14 @@ export interface SpotInstrumentInfoV5 {
}; };
} }
export type InstrumentInfoResponseV5 = type InstrumentInfoV5Mapping = {
| CategoryCursorListV5<LinearInverseInstrumentInfoV5[], 'linear' | 'inverse'> linear: LinearInverseInstrumentInfoV5[],
| CategoryCursorListV5<OptionInstrumentInfoV5[], 'option'> inverse: LinearInverseInstrumentInfoV5[],
| CategoryCursorListV5<SpotInstrumentInfoV5[], 'spot'>; option: OptionInstrumentInfoV5[],
spot: SpotInstrumentInfoV5[]
};
export type InstrumentInfoResponseV5<C extends CategoryV5> = CategoryCursorListV5<InstrumentInfoV5Mapping[C], C>;
export default interface OrderbookLevelV5 { export default interface OrderbookLevelV5 {
price: string; price: string;