Skip to content

Commit

Permalink
Merge pull request #287 from ThijmenMaus/fix(#286)--automatic-type-de…
Browse files Browse the repository at this point in the history
…termination-for-instrument-info

fix(#286): automatic type determination for instrument info
  • Loading branch information
tiagosiebler authored Sep 12, 2023
2 parents 9de8134 + 42ade6d commit bc870e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/rest-client-v5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
13 changes: 9 additions & 4 deletions src/types/response/v5-market.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
CategoryCursorListV5,
CategoryV5,
ContractTypeV5,
InstrumentStatusV5,
OptionTypeV5,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit bc870e4

Please sign in to comment.