Skip to content

Commit

Permalink
Merge pull request #50 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 + updated README
  • Loading branch information
lakshans authored Sep 8, 2022
2 parents 0a93b3b + c19693e commit 5acf239
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# sportx-js

Be your own bookmaker and fill orders programmatically with the SportX API!
Be your own bookmaker and fill orders programmatically with the SX Bet API!

Questions? [Join our chat](https://discord.gg/xXUynCX)

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": "12.2.2"
"version": "13.0.0"
}
23 changes: 17 additions & 6 deletions src/sportx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
ICancelEventOrdersRequest,
ICancelOrderRequest,
IDetailedRelayerMakerOrder,
IGetActiveMarketsResponse,
IGetTradesRequest,
ILeague,
ILiveScore,
Expand Down Expand Up @@ -89,8 +90,10 @@ export interface ISportX {
eventId?: number,
leagueId?: string,
liveOnly?: boolean,
betGroup?: string
): Promise<IMarket[]>;
betGroup?: string,
paginationKey? :string,
pageSize? : number
): Promise<IGetActiveMarketsResponse>;
getPopularMarkets(): Promise<IMarket[]>;
marketLookup(marketHashes: string[]): Promise<IMarket[]>;
newOrder(orders: INewOrder[]): Promise<IRelayerResponse>;
Expand Down Expand Up @@ -440,15 +443,19 @@ class SportX implements ISportX {
eventId?: number,
leagueId?: string,
liveOnly?: boolean,
betGroup?: string
): Promise<IMarket[]> {
betGroup?: string,
paginationKey?: string,
pageSize?: number
): Promise<IGetActiveMarketsResponse> {
this.debug("getActiveMarkets");
const qs = queryString.stringify({
...(mainLinesOnly !== undefined && { onlyMainLine: mainLinesOnly }),
...(leagueId !== undefined && { leagueId }),
...(eventId !== undefined && { eventId }),
...(liveOnly !== undefined && { liveOnly }),
...(betGroup !== undefined && { betGroup }),
...(paginationKey !== undefined && { paginationKey }),
...(pageSize !== undefined && { pageSize }),
});
const url = `${this.relayerUrl}${RELAYER_HTTP_ENDPOINTS.ACTIVE_MARKETS}?${qs}`;
const response = await fetch(url);
Expand All @@ -459,9 +466,13 @@ class SportX implements ISportX {
this.debug("Relayer response");
this.debug(result);
const {
data: { markets },
data: { markets, nextKey },
} = result;
return markets as IMarket[];
const getActiveMarketsResponse: IGetActiveMarketsResponse = {
markets,
nextKey
};
return getActiveMarketsResponse;
}

public async marketLookup(marketHashes: string[]): Promise<IMarket[]> {
Expand Down
5 changes: 5 additions & 0 deletions src/types/relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ export interface IPendingBet {
baseToken: string;
}

export interface IGetActiveMarketsResponse {
markets: IMarket[];
nextKey: string;
}

export interface IMarket {
status: string;
marketHash: string;
Expand Down

0 comments on commit 5acf239

Please sign in to comment.