Add priority to the closed clmm position in Solana using SDK V2 on Raydium
Raydium, a popular decentralized platform (DEX), provided its SDK V2 to develop personalized trading applications. A common scenario where users may need to apply priority costs is when you close the positions that require liquidity or above the market price. This article will guide you by adding priority to closing the market) Script for a tight position in Solana using Raydium SDK V2.
Prerequisite
- Get to know the Raydium SDK and Sol programming language
- Major understanding of the logic of trade and priority costs
Step 1: Create a new script
Create a new file for your personalized script, such as clmm_close_position.py
. This file will contain the logic of closing positions using the Raydium V2 SDK.
`Solana program
Import {SDK} by 'Raydium-Sdk';
/ **
* CLMM CLOST-PLOPED script.
*
* @Param {SDK} SDK - Raydium SDK Copy.
* //
Export of the Asychrian Closing function (position) {
// Get the current market manufacturer (cm) and the fence price.
Const CM = position.cm;
Const ClosingPrice = Position. Price;
// Check that CM has activated priority costs.
if (cm. Haspriraryfeeséabled ()) {
// Calculate the transaction costs according to the distribution of the manufacturer's supply / request on the market.
Const fee = (ClosingPrice - Cm.bid) / Cm.ask * 0.0001; // 100 floor
// Close the position using Raydium SDK V2.
Expect SDK.
Sum: 1, // Close a position unit
costs,
});
} Other {
// If the priority costs are not activated, close the position as usual.
Expect SDK.Closeposition (CM, ClosingPrice);
}
}
'
Step 2: Save the script with Raydium
To use the script, you must save it with Raydium. This includes creating a new copy script and recording your personalized feature.
Solana program
Import {script} by 'Raydium-Sdk';
// Create a new copy of a script.
CLST CLMMCLOSEPOSE = NEW script ();
// Save the script with Raydium.
ClmmClosePosition.Crieur ("Closure", closure);
'
Step 3: Call the script in your commercial logic
To use the closed CLMM position script, you can call it from your commercial logic in Solana. Here is an example:
Solana program
Import {SDK} by 'Raydium-Sdk';
// Get the current market manufacturer (cm) and the fence price.
CONST CM = Wait SDK.Getmarketmaker ();
Const ClosingPrice = Wait SDK.GetClosePrice (CM);
// Call the Clmm closing script to close the position.
Expect clmmclosepositive.
` ‘
With these steps, you can now use the SDK V2 and Raydium Solana programming language to add priority to the closed closed position in your personalized trading application.