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.
*/
getInstrumentsInfo(
params: GetInstrumentsInfoParamsV5,
): Promise<APIResponseV3WithTime<InstrumentInfoResponseV5>> {
getInstrumentsInfo<C extends CategoryV5>(
params: GetInstrumentsInfoParamsV5 & { category: C },
): Promise<APIResponseV3WithTime<InstrumentInfoResponseV5<C>>> {
return this.get('/v5/market/instruments-info', params);
}

View File

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