Skip to content

Commit

Permalink
Merge pull request #53 from sx-bet/47-support-pagination-in-relayer-c…
Browse files Browse the repository at this point in the history
…alls

47 support pagination in relayer calls
  • Loading branch information
lakshans authored Sep 8, 2022
2 parents 5acf239 + 9089594 commit 894b3b3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 21 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,24 @@ As a foreword the wrapper throws errors if parameters are bad, mismatched, or th

### Get all the active markets

This function uses pagination to retrieve active market data. The response will contain two values: **markets** and **nextKey**. For the next set of markets, the paginationKey must be provided.

Field Notes:
- paginationKey (optional) - needed to iterate over all markets
- pageSize (optional) - the default AND max pageSize value is 50

```typescript
const activeMarkets = await sportX.getActiveMarkets();
console.log(activeMarkets);
const data = await sportX.getActiveMarkets({
paginationKey: "<myPaginationKey>",
pageSize: 10
});

console.log(`active markets: ${data.markets}`);
console.log(`next pagination key: ${data.nextKey}`);
```
The above produces an object that contains two values:

Which produces an **array** of objects with the following schema:
1) markets: Which produces an **array** of objects with the following schema:

```typescript
interface IMarket {
Expand Down Expand Up @@ -140,6 +152,8 @@ interface IMarket {
}
```

2) nextKey: Which provides a string value of the next **paginationKey**.

The `sportId` and `leagueId`'s actual names can be found by fetching the leagues and sports. See below.

`line` will either be a spread or a total. You can figure out which team the spread is attributed to by looking at `outcomeOneName` and `outcomeTwoName`.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@
"test": "rm -rf dist/ && tsc && mocha \"dist/test/*.js\" --timeout 120000 --exit --bail",
"format": "tslint --fix -c tslint.json 'test/**/*.ts' 'src/**/*.ts' && prettier --write 'test/**/*.ts' 'src/**/*.ts'"
},
"version": "13.0.0"
"version": "13.0.1"
}
28 changes: 13 additions & 15 deletions src/sportx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
ICancelEventOrdersRequest,
ICancelOrderRequest,
IDetailedRelayerMakerOrder,
IGetActiveMarketsRequest,
IGetActiveMarketsResponse,
IGetTradesRequest,
ILeague,
Expand Down Expand Up @@ -86,14 +87,8 @@ export interface ISportX {
getSports(): Promise<ISport[]>;
getActiveLeagues(): Promise<ILeague[]>;
getActiveMarkets(
mainLinesOnly?: boolean,
eventId?: number,
leagueId?: string,
liveOnly?: boolean,
betGroup?: string,
paginationKey? :string,
pageSize? : number
): Promise<IGetActiveMarketsResponse>;
activeMarketsRequest: IGetActiveMarketsRequest
): Promise<IGetActiveMarketsResponse>;
getPopularMarkets(): Promise<IMarket[]>;
marketLookup(marketHashes: string[]): Promise<IMarket[]>;
newOrder(orders: INewOrder[]): Promise<IRelayerResponse>;
Expand Down Expand Up @@ -439,15 +434,18 @@ class SportX implements ISportX {
}

public async getActiveMarkets(
mainLinesOnly?: boolean,
eventId?: number,
leagueId?: string,
liveOnly?: boolean,
betGroup?: string,
paginationKey?: string,
pageSize?: number
activeMarketsRequest: IGetActiveMarketsRequest
): Promise<IGetActiveMarketsResponse> {
this.debug("getActiveMarkets");
const {
mainLinesOnly,
leagueId,
eventId,
liveOnly,
betGroup,
paginationKey,
pageSize
} = activeMarketsRequest;
const qs = queryString.stringify({
...(mainLinesOnly !== undefined && { onlyMainLine: mainLinesOnly }),
...(leagueId !== undefined && { leagueId }),
Expand Down
10 changes: 10 additions & 0 deletions src/types/relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ export interface IRelayerHistoricalMarketRequest {
marketHashes: string[];
}

export interface IGetActiveMarketsRequest {
mainLinesOnly?: boolean;
eventId?: number;
leagueId?: string;
liveOnly?: boolean;
betGroup?: string;
paginationKey? :string;
pageSize? : number;
}

export interface IGetTradesRequest {
startDate?: number;
endDate?: number;
Expand Down

0 comments on commit 894b3b3

Please sign in to comment.