Calculating Insurance Premium without place bet.
The getInsurancePremium
method calculates the insurance premium for a bet based on the provided parameters. This function can be used independently without placing a bet. It determines whether the bet is a Single
or Combo
type and passes the appropriate data to the kohin.getInsurancePremium
method. The result includes the calculated premium, which is processed and displayed accordingly.
For a Combo
bet, set betType
as "Combo"
, while for a Single bet, set betType
as "Single"
. These distinctions allow the method to accurately compute the insurance premium based on the bet type and its corresponding rules.
Usage
import kohin from "./kohinInstance";
const isSingle = true; // Set true for a "Single" (Ordinar) bet or false for a "Combo" (Express) bet.
const singleData = {
betAmount: 50,
betType: "Single",
conditionId: "100610060000000000640676650000000000000906565289",
outcomeId: "29",
odds: 2.22829,
};
const comboData = {
betAmount: 50,
betType: "Combo",
numLegs: 2,
odds: 3.39794,
};
const data = isSingle ? singleData : comboData;
const res = await kohin.getInsurancePremium(data);
if (res?.success) {
const premium = Number(res.calculatedPremium) / 10 ** 6;
console.log("Calculated Premium:", premium);
} else {
console.error("Error calculating premium:", res?.error);
}
Parameters
The InsurancePremiumParams
interface defines the input parameters for the method:
export interface InsurancePremiumParams {
betAmount: number; // The amount placed on the bet
betType: BetTypes; // Type of the bet: "Combo" or "Single"
numLegs?: number; // Number of legs (events) in the bet (required for Combo bets)
conditionId?: string; // Identifier for the bet condition (required for Single bets)
outcomeId?: string; // Identifier for the bet outcome (required for Single bets)
odds: number; // The odds associated with the bet
}
Return Value
The InsurancePremiumResponse
interface defines the structure of the returned object:
export interface InsurancePremiumResponse {
success: boolean; // Indicates if the operation was successful
error?: string; // Error message if the operation failed
calculatedPremium?: bigint; // The calculated premium value
}
Error Handling
The following code demonstrates how to handle errors while calling getInsurancePremium
:
try {
const res = await kohin.getInsurancePremium(data);
if (res.success) {
if (res.calculatedPremium !== undefined) {
const formattedPremium = Number(res.calculatedPremium) / 10 ** 6;
console.log(`Premium Calculated Successfully: ${formattedPremium} USDT`);
}
} else {
console.error(`Error: ${res.error}`);
}
} catch (err) {
console.error("Unexpected error calculating premium. Please try again.", err);
}
Example Response
Success Response:
{
"success": true,
"calculatedPremium": 53976024n
}
Error Response:
{
"success": false,
"error": "Invalid betting parameters provided."
}