From 2fe2fa9c9450547b1bbb2db347e5dd25a1ddb007 Mon Sep 17 00:00:00 2001 From: Lakshan Sivananthan Date: Wed, 7 Sep 2022 18:09:41 -0400 Subject: [PATCH 1/2] Updated get active markets method with pagination --- README.md | 16 ++++++++-------- src/sportx.ts | 23 +++++++++++++++++------ src/types/relayer.ts | 5 +++++ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 18114f4..78bc69d 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ # 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) ## Install -`yarn add @sportx-bet/sportx-js` +`yarn add @sx-bet/sportx-js` or -`npm i @sportx-bet/sportx-js` +`npm i @sx-bet/sportx-js` This library is compiled down to es6 and works in node and the browser. @@ -44,7 +44,7 @@ In any case, to get started, you can either initialize via your ethereum private For this you will need a URL of an Ethereum provider to connect to the network along with your Ethereum private key. For the provider url you can connect to https://rpc.sx.technology for SxStage & SxMainnet environment. For toronto, use this provider url https://rpc.sx.technology instead. This will get you connected to the SX chain. Make sure you pass in the correct urls for with the righ environments. ```typescript -import { Environments, newSportX } from "@sportx-bet/sportx-js"; +import { Environments, newSportX } from "@sx-bet/sportx-js"; async function main() { const sportX = await newSportX( @@ -68,7 +68,7 @@ Note that you do not need a SportX API key to get started. ### Initializing via an existing web3 instance. ```typescript -import { Environments, newSportX } from "@sportx-bet/sportx-js"; +import { Environments, newSportX } from "@sx-bet/sportx-js"; import { providers } from "ethers"; async function main() { @@ -340,7 +340,7 @@ import moment from "moment"; import { convertToAPIPercentageOdds, convertToTrueTokenAmount -} from "@sportx-bet/sportx-js"; +} from "@sx-bet/sportx-js"; const activeMarkets = await sportX.getActiveMarkets(); const firstMarketHash = activeMarkets[0].marketHash; @@ -472,7 +472,7 @@ Explanation of the fields: `fillAmount` is how much this order is filled by in Ethereum units. To convert to a readable amount you can use: ```typescript -import { convertToDisplayAmount } from "@sportx-bet/sportx-js"; +import { convertToDisplayAmount } from "@sx-bet/sportx-js"; console.log(convertToDisplayAmount("150000000000000000000")); ``` @@ -491,7 +491,7 @@ which produces "150" `percentageOdds` is the implied odds the maker is receiving for this order. To convert into a readable implied odds, you can use: ```typescript -import { convertFromAPIPercentageOdds } from "@sportx-bet/sportx-js"; +import { convertFromAPIPercentageOdds } from "@sx-bet/sportx-js"; const odds = "88985727650227679586"; const convertedOdds = convertFromAPIPercentageOdds(odds); diff --git a/src/sportx.ts b/src/sportx.ts index b310e39..890804c 100644 --- a/src/sportx.ts +++ b/src/sportx.ts @@ -41,6 +41,7 @@ import { ICancelEventOrdersRequest, ICancelOrderRequest, IDetailedRelayerMakerOrder, + IGetActiveMarketsResponse, IGetTradesRequest, ILeague, ILiveScore, @@ -89,8 +90,10 @@ export interface ISportX { eventId?: number, leagueId?: string, liveOnly?: boolean, - betGroup?: string - ): Promise; + betGroup?: string, + paginationKey? :string, + pageSize? : number + ): Promise; getPopularMarkets(): Promise; marketLookup(marketHashes: string[]): Promise; newOrder(orders: INewOrder[]): Promise; @@ -440,8 +443,10 @@ class SportX implements ISportX { eventId?: number, leagueId?: string, liveOnly?: boolean, - betGroup?: string - ): Promise { + betGroup?: string, + paginationKey?: string, + pageSize?: number + ): Promise { this.debug("getActiveMarkets"); const qs = queryString.stringify({ ...(mainLinesOnly !== undefined && { onlyMainLine: mainLinesOnly }), @@ -449,6 +454,8 @@ class SportX implements ISportX { ...(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); @@ -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 { diff --git a/src/types/relayer.ts b/src/types/relayer.ts index c321a57..0e844a4 100644 --- a/src/types/relayer.ts +++ b/src/types/relayer.ts @@ -194,6 +194,11 @@ export interface IPendingBet { baseToken: string; } +export interface IGetActiveMarketsResponse { + markets: IMarket[]; + nextKey: string; +} + export interface IMarket { status: string; marketHash: string; From 91f7031524a43b21e6491207f70d2040f594c02d Mon Sep 17 00:00:00 2001 From: Lakshan Sivananthan Date: Wed, 7 Sep 2022 18:11:01 -0400 Subject: [PATCH 2/2] 13.0.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9ea00c7..aa8d24a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@sx-bet/sportx-js", - "version": "12.2.0", + "version": "13.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@sx-bet/sportx-js", - "version": "12.2.0", + "version": "13.0.0", "license": "MIT", "dependencies": { "@ethersproject/abstract-signer": "^5.2.0", diff --git a/package.json b/package.json index 54aa9cd..9fef2ef 100644 --- a/package.json +++ b/package.json @@ -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.0" + "version": "13.0.0" }