UNPKG

betfair-exchange-api

Version:

A TypeScript client for the Betfair Exchange API

657 lines (656 loc) 20.8 kB
import { AxiosInstance } from 'axios'; export type MarketFilter = { textQuery?: string; exchangeIds?: string[]; eventTypeIds?: string[]; eventIds?: string[]; competitionIds?: string[]; marketIds?: string[]; venues?: string[]; bspOnly?: boolean; turnInPlayEnabled?: boolean; inPlayOnly?: boolean; marketBettingTypes?: MarketBettingType[]; marketCountries?: string[]; marketTypeCodes?: string[]; marketStartTime?: TimeRange; withOrders?: OrderStatus[]; raceTypes?: string[]; }; export type TimeRange = { from?: string; to?: string; }; export declare enum MarketBettingType { ODDS = "ODDS", LINE = "LINE", RANGE = "RANGE", ASIAN_HANDICAP_DOUBLE_LINE = "ASIAN_HANDICAP_DOUBLE_LINE", ASIAN_HANDICAP_SINGLE_LINE = "ASIAN_HANDICAP_SINGLE_LINE", FIXED_ODDS = "FIXED_ODDS" } export declare enum OrderStatus { PENDING = "PENDING", EXECUTION_COMPLETE = "EXECUTION_COMPLETE", EXECUTABLE = "EXECUTABLE", EXPIRED = "EXPIRED" } export declare enum MarketProjection { COMPETITION = "COMPETITION", EVENT = "EVENT", EVENT_TYPE = "EVENT_TYPE", MARKET_START_TIME = "MARKET_START_TIME", MARKET_DESCRIPTION = "MARKET_DESCRIPTION", RUNNER_DESCRIPTION = "RUNNER_DESCRIPTION", RUNNER_METADATA = "RUNNER_METADATA" } export declare enum MarketSort { MINIMUM_TRADED = "MINIMUM_TRADED", MAXIMUM_TRADED = "MAXIMUM_TRADED", MINIMUM_AVAILABLE = "MINIMUM_AVAILABLE", MAXIMUM_AVAILABLE = "MAXIMUM_AVAILABLE", FIRST_TO_START = "FIRST_TO_START", LAST_TO_START = "LAST_TO_START" } export declare enum PriceData { SP_AVAILABLE = "SP_AVAILABLE", SP_TRADED = "SP_TRADED", EX_BEST_OFFERS = "EX_BEST_OFFERS", EX_ALL_OFFERS = "EX_ALL_OFFERS", EX_TRADED = "EX_TRADED" } export declare enum MatchProjection { NO_ROLLUP = "NO_ROLLUP", ROLLED_UP_BY_PRICE = "ROLLED_UP_BY_PRICE", ROLLED_UP_BY_AVG_PRICE = "ROLLED_UP_BY_AVG_PRICE" } export declare enum OrderProjection { ALL = "ALL", EXECUTABLE = "EXECUTABLE", EXECUTION_COMPLETE = "EXECUTION_COMPLETE" } export declare enum Side { BACK = "BACK", LAY = "LAY" } export declare enum OrderType { LIMIT = "LIMIT", LIMIT_ON_CLOSE = "LIMIT_ON_CLOSE", MARKET_ON_CLOSE = "MARKET_ON_CLOSE" } export declare enum PersistenceType { LAPSE = "LAPSE", PERSIST = "PERSIST", MARKET_ON_CLOSE = "MARKET_ON_CLOSE" } export declare enum TimeInForce { FILL_OR_KILL = "FILL_OR_KILL" } export declare enum BetTargetType { BACKERS_PROFIT = "BACKERS_PROFIT", PAYOUT = "PAYOUT" } export declare enum BetStatus { SETTLED = "SETTLED", VOIDED = "VOIDED", LAPSED = "LAPSED", CANCELLED = "CANCELLED" } export declare enum GroupBy { EVENT_TYPE = "EVENT_TYPE", EVENT = "EVENT", MARKET = "MARKET", SIDE = "SIDE", BET = "BET" } export declare enum TimeGranularity { DAYS = "DAYS", HOURS = "HOURS", MINUTES = "MINUTES" } export declare enum SubscriptionStatus { ALL = "ALL", ACTIVATED = "ACTIVATED", UNACTIVATED = "UNACTIVATED", CANCELLED = "CANCELLED", EXPIRED = "EXPIRED" } export declare enum IncludeItem { ALL = "ALL", DEPOSITS_WITHDRAWALS = "DEPOSITS_WITHDRAWALS", EXCHANGE = "EXCHANGE", POKER_ROOM = "POKER_ROOM" } export declare enum Wallet { UK = "UK" } export declare enum ActionPerformed { NONE = "NONE", CANCELLATION_REQUEST_SUBMITTED = "CANCELLATION_REQUEST_SUBMITTED", ALL_BETS_CANCELLED = "ALL_BETS_CANCELLED", SOME_BETS_NOT_CANCELLED = "SOME_BETS_NOT_CANCELLED", CANCELLATION_REQUEST_ERROR = "CANCELLATION_REQUEST_ERROR", CANCELLATION_STATUS_UNKNOWN = "CANCELLATION_STATUS_UNKNOWN" } export type PriceProjection = { priceData?: PriceData[]; exBestOffersOverrides?: ExBestOffersOverrides; virtualise?: boolean; rolloverStakes?: boolean; }; export type ExBestOffersOverrides = { bestPricesDepth?: number; rollupModel?: string; rollupLimit?: number; rollupLiabilityThreshold?: number; rollupLiabilityFactor?: number; }; export type PlaceInstruction = { orderType: OrderType; selectionId: number; handicap?: number; side: Side; limitOrder?: LimitOrder; limitOnCloseOrder?: LimitOnCloseOrder; marketOnCloseOrder?: MarketOnCloseOrder; customerOrderRef?: string; }; export type LimitOrder = { size: number; price: number; persistenceType: PersistenceType; timeInForce?: TimeInForce; minFillSize?: number; betTargetType?: BetTargetType; betTargetSize?: number; }; export type LimitOnCloseOrder = { liability: number; price: number; }; export type MarketOnCloseOrder = { liability: number; }; export type CancelInstruction = { betId: string; sizeReduction?: number; }; export type ReplaceInstruction = { betId: string; newPrice: number; }; export type UpdateInstruction = { betId: string; newPersistenceType: PersistenceType; }; export type MarketVersion = { version: number; }; export type EventTypeResult = { eventType: { id: string; name: string; }; marketCount: number; }; export type CompetitionResult = { competition: { id: string; name: string; }; marketCount: number; competitionRegion?: string; }; export type TimeRangeResult = { timeRange: TimeRange; marketCount: number; }; export type EventResult = { event: { id: string; name: string; countryCode?: string; timezone?: string; venue?: string; openDate?: string; }; marketCount: number; }; export type MarketTypeResult = { marketType: string; marketCount: number; }; export type CountryCodeResult = { countryCode: string; marketCount: number; }; export type VenueResult = { venue: string; marketCount: number; }; export type MarketCatalogue = { marketId: string; marketName: string; marketStartTime?: string; description?: MarketDescription; totalMatched?: number; runners?: RunnerCatalog[]; eventType?: { id: string; name: string; }; competition?: { id: string; name: string; }; event?: { id: string; name: string; countryCode?: string; timezone?: string; venue?: string; openDate?: string; }; }; export type MarketDescription = { persistenceEnabled: boolean; bspMarket: boolean; marketTime: string; suspendTime: string; settleTime?: string; bettingType: string; turnInPlayEnabled: boolean; marketType: string; regulator: string; marketBaseRate: number; discountAllowed: boolean; wallet?: string; rules?: string; rulesHasDate?: boolean; eachWayDivisor?: number; clarifications?: string; lineRangeInfo?: any; raceType?: string; priceLadderDescription?: any; }; export type RunnerCatalog = { selectionId: number; runnerName: string; handicap: number; sortPriority: number; metadata?: { [key: string]: string; }; }; export type MarketBook = { marketId: string; isMarketDataDelayed: boolean; status: string; betDelay: number; bspReconciled: boolean; complete: boolean; inplay: boolean; numberOfWinners: number; numberOfRunners: number; numberOfActiveRunners: number; lastMatchTime: string; totalMatched: number; totalAvailable: number; crossMatching: boolean; runnersVoidable: boolean; version: number; runners: Runner[]; keyLineDescription?: any; }; export type Runner = { selectionId: number; handicap: number; status: string; adjustmentFactor?: number; lastPriceTraded?: number; totalMatched?: number; removalDate?: string; sp?: StartingPrices; ex?: ExchangePrices; orders?: any[]; matches?: any[]; matchesByStrategy?: any; }; export type StartingPrices = { nearPrice?: number; farPrice?: number; backStakeTaken?: PriceSize[]; layLiabilityTaken?: PriceSize[]; actualSP?: number; }; export type ExchangePrices = { availableToBack?: PriceSize[]; availableToLay?: PriceSize[]; tradedVolume?: PriceSize[]; }; export type PriceSize = { price: number; size: number; }; export type MarketProfitAndLoss = { marketId: string; commissionApplied?: number; profitAndLosses?: RunnerProfitAndLoss[]; }; export type RunnerProfitAndLoss = { selectionId: number; ifWin?: number; ifLose?: number; ifPlace?: number; }; export type CurrentOrderSummaryReport = { currentOrders: CurrentOrderSummary[]; moreAvailable: boolean; }; export type CurrentOrderSummary = { betId: string; marketId: string; selectionId: number; handicap: number; priceSize: PriceSize; bspLiability: number; side: Side; status: OrderStatus; persistenceType: PersistenceType; orderType: OrderType; placedDate: string; matchedDate?: string; averagePriceMatched?: number; sizeMatched: number; sizeRemaining: number; sizeLapsed: number; sizeCancelled: number; sizeVoided: number; regulatorAuthCode?: string; regulatorCode?: string; customerOrderRef?: string; customerStrategyRef?: string; currentItemDescription?: any; }; export type ClearedOrderSummaryReport = { clearedOrders: ClearedOrderSummary[]; moreAvailable: boolean; }; export type ClearedOrderSummary = { eventTypeId?: string; eventId?: string; marketId?: string; selectionId?: number; handicap?: number; betId?: string; placedDate?: string; persistenceType?: PersistenceType; orderType?: OrderType; side?: Side; itemDescription?: any; betOutcome?: string; priceRequested?: number; settledDate?: string; lastMatchedDate?: string; betCount?: number; commission?: number; priceMatched?: number; priceReduced?: boolean; sizeSettled?: number; profit?: number; sizeCancelled?: number; customerOrderRef?: string; customerStrategyRef?: string; }; export type PlaceExecutionReport = { customerRef?: string; status: string; errorCode?: string; marketId: string; instructionReports: PlaceInstructionReport[]; }; export type PlaceInstructionReport = { status: string; errorCode?: string; orderStatus?: string; instruction: PlaceInstruction; betId?: string; placedDate?: string; averagePriceMatched?: number; sizeMatched?: number; }; export type CancelExecutionReport = { customerRef?: string; status: string; errorCode?: string; marketId: string; instructionReports: CancelInstructionReport[]; }; export type CancelInstructionReport = { status: string; errorCode?: string; instruction: CancelInstruction; sizeCancelled?: number; cancelledDate?: string; }; export type ReplaceExecutionReport = { customerRef?: string; status: string; errorCode?: string; marketId: string; instructionReports: ReplaceInstructionReport[]; }; export type ReplaceInstructionReport = { status: string; errorCode?: string; cancelInstructionReport: CancelInstructionReport; placeInstructionReport: PlaceInstructionReport; }; export type UpdateExecutionReport = { customerRef?: string; status: string; errorCode?: string; marketId: string; instructionReports: UpdateInstructionReport[]; }; export type UpdateInstructionReport = { status: string; errorCode?: string; instruction: UpdateInstruction; }; export type AccountFundsResponse = { availableToBetBalance: number; exposure: number; retainedCommission: number; exposureLimit: number; discountRate: number; pointsBalance: number; }; export type AccountDetailsResponse = { currencyCode: string; firstName: string; lastName: string; localeCode: string; region: string; timezone: string; discountRate: number; pointsBalance: number; countryCode: string; }; export type DeveloperApp = { appName: string; appId: number; appVersions: DeveloperAppVersion[]; }; export type DeveloperAppVersion = { owner: string; versionId: number; version: string; applicationKey: string; delayData: boolean; subscriptionRequired: boolean; ownerManaged: boolean; active: boolean; vendorId?: string; vendorSecret?: string; }; export type AccountStatementReport = { accountStatement: StatementItem[]; moreAvailable: boolean; }; export type StatementItem = { refId: string; itemDate: string; amount: number; balance: number; itemClass: string; itemClassData: { [key: string]: string; }; legacyData?: any; }; export type CurrencyRate = { currencyCode: string; rate: number; }; export type ApplicationSubscription = { subscriptionToken: string; expiryDateTime: string; expiredDateTime?: string; createdDateTime: string; activationDateTime?: string; cancellationDateTime?: string; subscriptionStatus: SubscriptionStatus; clientReference?: string; vendorClientId?: string; }; export type SubscriptionHistory = { subscriptionToken: string; expiryDateTime: string; expiredDateTime?: string; createdDateTime: string; activationDateTime?: string; cancellationDateTime?: string; subscriptionStatus: SubscriptionStatus; clientReference?: string; }; export type AccountSubscription = { subscriptionTokens: SubscriptionTokenInfo[]; applicationName: string; applicationVersionId: string; }; export type SubscriptionTokenInfo = { subscriptionToken: string; activatedDateTime: string; expiryDateTime: string; expiredDateTime?: string; cancellationDateTime?: string; subscriptionStatus: SubscriptionStatus; }; export type VendorDetails = { appVersionId: number; vendorName: string; redirectUrl: string; }; export type VendorAccessTokenInfo = { access_token: string; token_type: string; expires_in: number; refresh_token: string; application_subscription: ApplicationSubscription; }; export type AffiliateRelation = { vendorClientId: string; status: string; }; export type HeartbeatReport = { actionPerformed: ActionPerformed; actualTimeoutSeconds: number; }; export declare class BetfairApiBase { protected axiosInstance: AxiosInstance; protected sessionToken: string | null; protected appKey: string; constructor(appKey: string); setSessionToken(token: string | null): void; executeRequest<T>(method: string, params?: any): Promise<T>; } export declare class BettingAPI { private base; private endpoint; private prefix; constructor(appKey: string); setSessionToken(token: string | null): void; listEventTypes(filter?: MarketFilter, locale?: string): Promise<EventTypeResult[]>; listCompetitions(filter?: MarketFilter, locale?: string): Promise<CompetitionResult[]>; listTimeRanges(filter?: MarketFilter, granularity?: TimeGranularity): Promise<TimeRangeResult[]>; listEvents(filter?: MarketFilter, locale?: string): Promise<EventResult[]>; listMarketTypes(filter?: MarketFilter, locale?: string): Promise<MarketTypeResult[]>; listCountries(filter?: MarketFilter, locale?: string): Promise<CountryCodeResult[]>; listVenues(filter?: MarketFilter, locale?: string): Promise<VenueResult[]>; listMarketCatalogue(filter?: MarketFilter, marketProjection?: MarketProjection[], sort?: MarketSort, maxResults?: number, locale?: string): Promise<MarketCatalogue[]>; listMarketBook(marketIds: string[], priceProjection?: PriceProjection, orderProjection?: OrderProjection, matchProjection?: MatchProjection, includeOverallPosition?: boolean, partitionMatchedByStrategyRef?: boolean, customerStrategyRefs?: string[], currencyCode?: string, locale?: string, matchedSince?: string, betIds?: string[]): Promise<MarketBook[]>; listRunnerBook(marketId: string, selectionId: number, handicap?: number, priceProjection?: PriceProjection, orderProjection?: OrderProjection, matchProjection?: MatchProjection, includeOverallPosition?: boolean, partitionMatchedByStrategyRef?: boolean, customerStrategyRefs?: string[], currencyCode?: string, locale?: string, matchedSince?: string, betIds?: string[]): Promise<MarketBook[]>; listMarketProfitAndLoss(marketIds: string[], includeSettledBets?: boolean, includeBspBets?: boolean, netOfCommission?: boolean): Promise<MarketProfitAndLoss[]>; listCurrentOrders(betIds?: string[], marketIds?: string[], orderProjection?: OrderProjection, customerOrderRefs?: string[], customerStrategyRefs?: string[], dateRange?: TimeRange, orderBy?: string, sortDir?: string, fromRecord?: number, recordCount?: number, includeItemDescription?: boolean): Promise<CurrentOrderSummaryReport>; listClearedOrders(betStatus: BetStatus, eventTypeIds?: string[], eventIds?: string[], marketIds?: string[], runnerIds?: number[], betIds?: string[], customerOrderRefs?: string[], customerStrategyRefs?: string[], side?: Side, settledDateRange?: TimeRange, groupBy?: GroupBy, includeItemDescription?: boolean, locale?: string, fromRecord?: number, recordCount?: number): Promise<ClearedOrderSummaryReport>; placeOrders(marketId: string, instructions: PlaceInstruction[], customerRef?: string, marketVersion?: MarketVersion, customerStrategyRef?: string, async?: boolean): Promise<PlaceExecutionReport>; cancelOrders(marketId?: string, instructions?: CancelInstruction[], customerRef?: string): Promise<CancelExecutionReport>; replaceOrders(marketId: string, instructions: ReplaceInstruction[], customerRef?: string, marketVersion?: MarketVersion, async?: boolean): Promise<ReplaceExecutionReport>; updateOrders(marketId: string, instructions: UpdateInstruction[], customerRef?: string): Promise<UpdateExecutionReport>; } export declare class AccountsAPI { private base; private endpoint; private prefix; constructor(appKey: string); setSessionToken(token: string | null): void; createDeveloperAppKeys(appName: string): Promise<DeveloperApp>; getDeveloperAppKeys(): Promise<DeveloperApp[]>; getAccountFunds(wallet?: Wallet): Promise<AccountFundsResponse>; getAccountDetails(): Promise<AccountDetailsResponse>; getVendorClientId(): Promise<string>; getApplicationSubscriptionToken(subscriptionLength: number, clientReference?: string): Promise<string>; activateApplicationSubscription(subscriptionToken: string): Promise<string>; cancelApplicationSubscription(subscriptionToken: string): Promise<string>; updateApplicationSubscription(vendorClientId: string, subscriptionLength: number): Promise<string>; listApplicationSubscriptionTokens(subscriptionStatus?: SubscriptionStatus): Promise<ApplicationSubscription[]>; listAccountSubscriptionTokens(): Promise<AccountSubscription[]>; getApplicationSubscriptionHistory(vendorClientId: string, applicationKey?: string): Promise<SubscriptionHistory[]>; getAccountStatement(locale?: string, fromRecord?: number, recordCount?: number, itemDateRange?: TimeRange, includeItem?: IncludeItem, wallet?: Wallet): Promise<AccountStatementReport>; listCurrencyRates(fromCurrency: string): Promise<CurrencyRate[]>; token(clientId: string, grantType: string, code?: string, clientSecret?: string, refreshToken?: string): Promise<VendorAccessTokenInfo>; getVendorDetails(vendorId: string): Promise<VendorDetails>; revokeAccessToWebApp(vendorId: number): Promise<string>; listAuthorizedWebApps(): Promise<VendorDetails[]>; isAccountSubscribedToWebApp(vendorId: string): Promise<boolean>; getAffiliateRelation(vendorClientIds: string[]): Promise<AffiliateRelation[]>; } export declare class HeartbeatAPI { private base; private endpoint; private prefix; constructor(appKey: string); setSessionToken(token: string | null): void; heartbeat(preferredTimeoutSeconds: number): Promise<HeartbeatReport>; } interface BetfairClientConfig { apiUrl?: string; authUrl?: string; } export declare class BetfairClient extends BetfairApiBase { private exchangeApi; private accountsApi; private heartbeatApi; constructor(appKey: string, config?: BetfairClientConfig); get betting(): BettingAPI; get accounts(): AccountsAPI; get heartbeat(): HeartbeatAPI; authenticate(username: string, password: string, certificatePath?: string): Promise<void>; keepAlive(): Promise<boolean>; logout(): Promise<boolean>; getAppKey(): string; getSessionToken(): string | null; authenticateInteractive(username: string, password: string): Promise<void>; } export {};