get_quote
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_quote
Description
The 'get_quote'
method retrieves a quote for a token swap, converting the amount to lamports and the slippage to basis points (bps) before making the API call.
Parameters
'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'fromMint'
token to swap, in lamports.'slippage'
(float): The acceptable slippage percentage for the swap, in basis points (bps).'provider'
(str): The liquidity provider.'from_mint_decimals'
(int, optional): The decimal places for the'from_mint'
token (default is 9).'to_mint_decimals'
(int, optional): The decimal places for the'to_mint'
token (default is 9).
Returns
'Promise<quoteResponseMap>'
: A promise that resolves to a 'quoteResponseMap'
object containing the quote data.
'quoteResponseMap'
Type
'quoteResponseMap'
Typeclass QuoteResponseMap(TypedDict):
inputMint: str
inAmount: float
outputMint: str
outAmount: float
minimumReceived: float
slippage: float
priceImpactPercent: float
Example
async def get_quote():
try:
const quote_data = await spiderswap.quote.get_quote(
'from_mint_address',
'to_mint_address',
1, # Amount in tokens
0.5, # Slippage in percentage
'provider_name',
9, # from_mint_decimals
9 # to_mint_decimals
);
print(f"Quote data: {quoteData}")
return quoteData
except Exception as e:
print(f"An error occurred: {e}")
get_quote();
Implementation Details
This method converts the 'amount'
to lamports and the 'slippage'
to basis points (bps) before calling the 'get_quote_raw'
method to fetch the quote data from the API. It then converts the amounts back to their original units and constructs a 'QuoteResponseMap'
object.
Last updated