UNPKG

betfair-node

Version:

A comprehensive Node.js TypeScript library for the Betfair Exchange API, providing both JSON-RPC API integration and real-time Exchange Stream API support for automated betting and trading applications.

167 lines 9.49 kB
import { AxiosResponse } from 'axios'; import { BetStatus, MarketFilter, MarketSort, OrderProjection, PlaceInstruction, SortDir, Side, OrderBy, GroupBy, TimeRange, CurrentOrderSummary, ClearedOrderSummary, CancelInstruction, ReplaceInstruction, UpdateInstruction, CancelExecutionReport, ReplaceExecutionReport, UpdateExecutionReport, PersistenceType } from './betfair-api-types'; import { CurrencyRate, MarketChangeCallback } from './betfair-exchange-stream-api-types'; export interface BetfairApiState { locale: string; sessionKey?: string; appKey?: string; currencyRates?: CurrencyRate[]; targetCurrency: string; conflateMs: number; heartbeatMs: number; marketChangeCallback: MarketChangeCallback; } export interface AuthCredentials { sessionKey: string; appKey: string; } export declare const createBetfairApiState: (locale: string, currencyCode: string, conflateMs: number, heartbeatMs: number, marketChangeCallback: MarketChangeCallback) => BetfairApiState; export declare const ensureAuthenticated: (state: BetfairApiState) => AuthCredentials; export declare const isAuthenticated: (state: BetfairApiState) => boolean; export declare const login: (state: BetfairApiState, appKey: string, username: string, password: string) => Promise<BetfairApiState>; export declare const logout: (sessionKey: string) => Promise<AxiosResponse>; export declare const keepAlive: (sessionKey: string) => Promise<AxiosResponse>; export declare const listMarketCatalogue: (state: BetfairApiState, filter: MarketFilter, marketProjection: any[], sort: MarketSort, maxResults: number) => Promise<AxiosResponse>; export declare const listMarketBook: (state: BetfairApiState, params: any) => Promise<AxiosResponse>; export declare const listEventTypes: (state: BetfairApiState, filter: MarketFilter) => Promise<AxiosResponse>; export declare const listCompetitions: (state: BetfairApiState, filter: MarketFilter) => Promise<AxiosResponse>; export declare const listTimeRanges: (state: BetfairApiState, filter: MarketFilter) => Promise<AxiosResponse>; export declare const listEvents: (state: BetfairApiState, filter: MarketFilter) => Promise<AxiosResponse>; export declare const listMarketTypes: (state: BetfairApiState, filter: MarketFilter) => Promise<AxiosResponse>; export declare const listCountries: (state: BetfairApiState, filter: MarketFilter) => Promise<AxiosResponse>; export declare const listVenues: (state: BetfairApiState, filter: MarketFilter) => Promise<AxiosResponse>; export declare const listMarketProfitAndLoss: (state: BetfairApiState, marketIds: string[], includeSettledBets: boolean, includeBspBets: boolean, netOfCommission: boolean) => Promise<AxiosResponse>; export declare const placeOrders: (state: BetfairApiState, marketId: string, instructions: PlaceInstruction[], customerRef: string, marketVersion: number, customerStrategyRef: string, async: boolean) => Promise<AxiosResponse>; export declare const listCurrencyRates: (state: BetfairApiState, fromCurrency: string) => Promise<AxiosResponse>; export declare const findCurrencyRate: (currencyRates: CurrencyRate[], currencyCode: string) => CurrencyRate | undefined; /** * Standardizes location names for Betfair API consistency * @param location - The location string to standardize * @returns Standardized location string */ export declare const betfairStandardizeLocation: (location: string) => string; /** * Lists current orders for the authenticated account * @param state - Current API state * @param betIds - Optional list of bet IDs to filter by * @param marketIds - Optional list of market IDs to filter by * @param orderProjection - What order data to include in the response * @param placedDateRange - Optional date range for when orders were placed * @param orderBy - How to order the results * @param sortDir - Sort direction (earliest to latest or latest to earliest) * @param fromRecord - Record index to start from (for pagination) * @param recordCount - Number of records to return * @returns Promise with current orders response */ export declare const listCurrentOrders: (state: BetfairApiState, betIds?: string[], marketIds?: string[], orderProjection?: OrderProjection, placedDateRange?: TimeRange, orderBy?: OrderBy, sortDir?: SortDir, fromRecord?: number, recordCount?: number) => Promise<AxiosResponse<{ result: CurrentOrderSummary[]; }>>; /** * Lists cleared (settled) orders for the authenticated account * @param state - Current API state * @param betStatus - Status of the bet (e.g., SETTLED, VOIDED, LAPSED, CANCELLED) * @param eventTypeIds - Optional list of event type IDs to filter by * @param eventIds - Optional list of event IDs to filter by * @param marketIds - Optional list of market IDs to filter by * @param runnerIds - Optional list of runner selection IDs to filter by * @param betIds - Optional list of bet IDs to filter by * @param side - Optional side filter (BACK or LAY) * @param settledDateRange - Optional date range for when bets were settled * @param groupBy - How to group the results * @param includeItemDescription - Whether to include item descriptions * @param fromRecord - Record index to start from (for pagination) * @param recordCount - Number of records to return * @returns Promise with cleared orders response */ export declare const listClearedOrders: (state: BetfairApiState, betStatus?: BetStatus, eventTypeIds?: string[], eventIds?: string[], marketIds?: string[], runnerIds?: number[], betIds?: string[], side?: Side, settledDateRange?: TimeRange, groupBy?: GroupBy, includeItemDescription?: boolean, fromRecord?: number, recordCount?: number) => Promise<AxiosResponse<{ result: ClearedOrderSummary[]; }>>; /** * Cancels orders on the exchange * @param state - Current API state * @param marketId - The market ID where the orders are placed * @param instructions - Array of cancel instructions * @param customerRef - Optional customer reference for the transaction * @returns Promise with cancel execution report */ export declare const cancelOrders: (state: BetfairApiState, marketId: string, instructions: CancelInstruction[], customerRef?: string) => Promise<AxiosResponse<{ result: CancelExecutionReport; }>>; /** * Replaces orders on the exchange * @param state - Current API state * @param marketId - The market ID where the orders are placed * @param instructions - Array of replace instructions * @param customerRef - Optional customer reference for the transaction * @param marketVersion - Market version (optional but recommended) * @param async - Whether to process asynchronously * @returns Promise with replace execution report */ export declare const replaceOrders: (state: BetfairApiState, marketId: string, instructions: ReplaceInstruction[], customerRef?: string, marketVersion?: number, async?: boolean) => Promise<AxiosResponse<{ result: ReplaceExecutionReport; }>>; /** * Updates orders on the exchange * @param state - Current API state * @param marketId - The market ID where the orders are placed * @param instructions - Array of update instructions * @param customerRef - Optional customer reference for the transaction * @returns Promise with update execution report */ export declare const updateOrders: (state: BetfairApiState, marketId: string, instructions: UpdateInstruction[], customerRef?: string) => Promise<AxiosResponse<{ result: UpdateExecutionReport; }>>; /** * Creates a cancel instruction for a specific bet * @param betId - The bet ID to cancel * @param sizeReduction - Optional size reduction instead of full cancellation * @returns Cancel instruction */ export declare const createCancelInstruction: (betId: string, sizeReduction?: number) => CancelInstruction; /** * Creates a replace instruction for a specific bet * @param betId - The bet ID to replace * @param newPrice - The new price for the bet * @returns Replace instruction */ export declare const createReplaceInstruction: (betId: string, newPrice: number) => ReplaceInstruction; /** * Creates an update instruction for a specific bet * @param betId - The bet ID to update * @param newPersistenceType - The new persistence type * @returns Update instruction */ export declare const createUpdateInstruction: (betId: string, newPersistenceType: PersistenceType) => UpdateInstruction; /** * Validates if a bet ID is in correct format * @param betId - The bet ID to validate * @returns True if valid, false otherwise */ export declare const isValidBetId: (betId: string) => boolean; /** * Calculates potential profit for a back bet * @param stake - The stake amount * @param odds - The odds * @returns Potential profit */ export declare const calculateBackProfit: (stake: number, odds: number) => number; /** * Calculates liability for a lay bet * @param stake - The stake amount (what you'll win) * @param odds - The odds * @returns Liability (what you'll lose if the bet wins) */ export declare const calculateLayLiability: (stake: number, odds: number) => number; /** * Validates order parameters for common issues * @param marketId - Market ID * @param selectionId - Selection ID * @param price - Odds price * @param size - Bet size * @returns Object with validation result and any error messages */ export declare const validateOrderParameters: (marketId: string, selectionId: number, price: number, size: number) => { isValid: boolean; errors: string[]; }; //# sourceMappingURL=betfair-api.d.ts.map