get_swap

Installation

pip install karrotcapital.spiderswap

Usage

Initialization

First, initialize the 'Spiderswap' class with your API key.

from karrotcapital.spiderswap import Spiderswap

spiderswap = Spiderswap(ApiKey);

Method: get_swap

Description

The 'get_swap' method facilitates token swaps by fetching swap data from the SpiderSwap API, converting the amount to lamports and the slippage to basis points (bps) before making the API call.

Parameters

  • 'owner' (str): The wallet address of the owner initiating the swap.

  • 'from_mint' (str): The mint address of the token being swapped from.

  • 'to_mint' (str): The mint address of the token being swapped to.

  • 'amount' (float): The amount of the 'from_mint' token to swap.

  • 'slippage' (float): The acceptable slippage percentage for the swap.

  • 'provider' (str): The liquidity provider.

  • 'pool' (str | null, optional): The specific pool for the swap (default is None).

  • 'from_mint_decimals'(float, optional): The decimal places for the 'from_mint' token (default is 9).

Returns

'SwapResponse': A promise that resolves to a base64-encoded string containing the raw swap data.

'SwapResponse' Class

Example

Error Handling

The method relies on 'get_swap_raw' for error handling, throwing an error if the swap data cannot be fetched and logging the error details for debugging.

Last updated