get_swap_raw

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_raw

Description

The 'get_swap_raw' method facilitates token swaps by fetching raw swap data from the SpiderSwap API.

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, in lamports.

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

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

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

Returns

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

'SwapResponse' Class

class SwapResponse(TypedDict):
    base64Transaction: str
    signers: List[str]

Example

async def perform_swap():
    try:
        swap_result = await spiderswap.swap.get_swap_raw(
            'owner_address',
            'from_mint_address',
            'to_mint_address',
            1000000,  # Amount in lamports
            50, # Amount in bps
            'provider',
            'pool'
        );
        print(f"Swap Data: {swap_result}");
    except Exception as e:
        print(f"An error occurred: {e}")
}

perform_swap();

Error Handling

The method throws an error if the swap data cannot be fetched, logging the error details for debugging.

Last updated