getOddsHistory
The getOddsHistory
method allows developers to fetch the historical odds for a specific condition using its unique conditionId. This method is particularly useful for understanding how odds have fluctuated over time, providing valuable insights for analysis, strategy building, or making informed decisions.
It is ideal for applications that track betting trends, showcase historical performance, or visualize odds changes. The method ensures a reliable response, either returning the data or a clear error message, making it user-friendly and efficient for developers integrating it into their workflows.
Usage
import kohin from "./kohinInstance";
const oddsHistoryParams = {
conditionId: "100610060000000000262299870000000000000134446702", // Unique identifier of the condition
};
const oddsHistory = await kohin.getOddsHistory(oddsHistoryParams);
console.log("Odds History:", oddsHistory);
Parameters
Parameter | Type | Description |
---|---|---|
conditionId | string | The unique identifier for the condition whose odds history is to be fetched. |
Return Value
Returns a Promise
resolving to an object with the following structure:
{
success: boolean; // Indicates whether the call was successful
data?: [ // Odds history object (present if successful)
id: string;
firstTeamOdds: number;
drawOdds: number;
secondTeamOdds: number;
conditionId: string;
blockTimestamp: number;
month: string;
teamOne: string;
teamTwo: string;
];
error?: string; // Error message if the call fails
}
Error Handling
Handle potential errors gracefully by checking the response or using a try-catch block:
try {
const oddsHistory = await kohin.getOddsHistory({
conditionId: "100610060000000000262299870000000000000134446702",
});
if (!oddsHistory.success) {
console.error("Error:", oddsHistory.error);
// Display the error message to the user
toastify(oddsHistory.error, "error");
} else {
console.log("Odds History:", oddsHistory.data);
}
} catch (error) {
console.error("Unexpected error:", error.message);
// Display a fallback error message
toastify("Failed to fetch odds history. Please try again.", "error");
}
Example Response
Success Response:
{
"success": true,
"code": 200,
"data": [
{
"id": "0xd6bbe55242be57d1f88c9309454efd52335a454e4a756dd762f35caee16151aec9000000",
"firstTeamOdds": 64.6110651124502,
"secondTeamOdds": 35.38893488758051,
"conditionId": "100610060000000000267374830000000000000735114412",
"blockTimestamp": "1743181010",
"month": "March 28",
"teamOne": "Chelsea FC",
"teamTwo": "Tottenham Hotspur"
},
{
"id": "0x19bb2a768a5745a424bd9b467f51102b157f82d4c5a21e4586dfe20f4f02c6b3b3010000",
"firstTeamOdds": 64.59914114016435,
"secondTeamOdds": 35.400858859858864,
"conditionId": "100610060000000000267374830000000000000735114412",
"blockTimestamp": "1743620484",
"month": "April 2",
"teamOne": "Chelsea FC",
"teamTwo": "Tottenham Hotspur"
},
{
"id": "0x8e660457bbf252407a238e6f7e646ab9d43bc92c4eb522eef6dd9976ae551b605e010000",
"firstTeamOdds": 64.60914264538403,
"secondTeamOdds": 35.3908573546344,
"conditionId": "100610060000000000267374830000000000000735114412",
"blockTimestamp": "1743670791",
"month": "April 3",
"teamOne": "Chelsea FC",
"teamTwo": "Tottenham Hotspur"
}
],
"message": "OK",
"detailMessage": null,
"error": ""
}
Error Response:
{
"success": false,
"error": "Condition ID not found"
}