Python SDK for the LaserSell API
Project description
lasersell-sdk (Python)
Python SDK for the LaserSell API.
Full documentation: docs.lasersell.io/api/sdk/python
Modules:
exit_api: build unsigned buy/sell transactions.stream: Exit Intelligence Stream client, protocol types, and session helpers.tx: sign/encode/send Solana transactions.retry: shared retry helpers.
Install
pip install lasersell-sdk
From this repository:
cd lasersell-sdk/python
python -m pip install -e .
Package layout
lasersell_sdk.exit_api: build unsigned buy/sell transactions.lasersell_sdk.stream.client: websocket transport and command sender.lasersell_sdk.stream.session: higher-level stream session with position tracking.lasersell_sdk.stream.proto: protocol types and JSON encode/decode helpers.lasersell_sdk.tx: sign/encode/send Solana transactions.lasersell_sdk.retry: retry/backoff and timeout helpers.
Build a sell transaction
import asyncio
from lasersell_sdk.exit_api import BuildSellTxRequest, ExitApiClient, SellOutput
async def main() -> None:
client = ExitApiClient.with_api_key("REPLACE_WITH_API_KEY")
request = BuildSellTxRequest(
mint="REPLACE_WITH_MINT",
user_pubkey="REPLACE_WITH_WALLET_PUBKEY",
amount_tokens=1_000_000,
slippage_bps=2_000,
output=SellOutput.SOL,
)
response = await client.build_sell_tx(request)
print(response.tx)
asyncio.run(main())
Notes:
amount_tokensis in token atomic units (smallest unit for the mint).slippage_bpsis basis points (100=1%,2000=20%).- Use
client.with_base_url("https://api-dev.example")to target a custom base URL.
Stream + auto-sell flow
Important: Connect the stream before submitting a buy transaction. See docs.lasersell.io/api/exit-api/buy for details.
import asyncio
from solders.keypair import Keypair
from lasersell_sdk.stream.client import (
StreamClient,
single_wallet_stream_configure_optional,
)
from lasersell_sdk.stream.session import StreamSession
from lasersell_sdk.tx import SendTargetHeliusSender, send_transaction, sign_unsigned_tx
async def main() -> None:
signer = Keypair()
client = StreamClient("REPLACE_WITH_API_KEY")
session = await StreamSession.connect(
client,
single_wallet_stream_configure_optional(
"REPLACE_WITH_WALLET_PUBKEY",
deadline_timeout_sec=45, # timeout-only strategy is valid
),
)
while True:
event = await session.recv()
if event is None:
break
if event.type == "exit_signal_with_tx" and event.message.get("type") == "exit_signal_with_tx":
signed_tx = sign_unsigned_tx(event.message["unsigned_tx_b64"], signer)
signature = await send_transaction(SendTargetHeliusSender(), signed_tx)
print(signature)
asyncio.run(main())
deadline_timeout_sec is enforced client-side by StreamSession timers and is not sent as part of wire strategy.
Use session.update_strategy(...) when changing strategy so local deadline timers stay in sync (pass deadline_timeout_sec= to change local deadline timing).
Use single_wallet_stream_configure_optional(...) / strategy_config_from_optional(...) to omit TP/SL fields; at least one of take profit, stop loss, trailing stop, or timeout must be enabled.
Trailing stop
Lock in profits by tracking a high-water mark. When the position's profit drops by the configured percentage of entry cost from its peak, an exit is triggered.
from lasersell_sdk.stream.client import strategy_config_from_optional
# 20% take profit, 10% stop loss, 5% trailing stop
strategy = strategy_config_from_optional(
take_profit_pct=20.0,
stop_loss_pct=10.0,
trailing_stop_pct=5.0,
)
Example: with trailing_stop_pct=5.0 and an entry of 100 SOL, if profit peaks at 30 SOL, an exit triggers when profit falls below 25 SOL.
Sell on graduation
Automatically exit a position when its token graduates from a bonding curve to a full DEX (e.g. Pump.fun to PumpSwap). Enable by setting sell_on_graduation in the optional strategy config:
from lasersell_sdk.stream.client import strategy_config_from_optional
strategy = strategy_config_from_optional(
take_profit_pct=20.0,
stop_loss_pct=10.0,
sell_on_graduation=True,
)
When a graduation event is detected the server sells the position on the new market and reports "graduation" as the exit reason.
Update wallets mid-session
Add or remove wallets without reconnecting:
await session.sender().update_wallets(["WALLET_1_PUBKEY", "WALLET_2_PUBKEY"])
The server diffs the new list against the current set and registers/unregisters accordingly.
Notes:
- Use
client.with_endpoint("wss://stream-dev.example/v1/ws")to target a custom stream endpoint. unsigned_tx_b64from stream events can be signed withlasersell_sdk.tx.sign_unsigned_tx.
RPC endpoint
The SDK ships with the Solana public mainnet-beta RPC as a default so you can get started immediately:
from lasersell_sdk.tx import SendTargetRpc
target = SendTargetRpc() # uses mainnet-beta public RPC
A private RPC is highly recommended for production — the public endpoint is rate-limited and unreliable under load. Free private RPC tiers are available from Helius and Chainstack, among others:
target = SendTargetRpc(url="https://your-private-rpc.example.com")
Examples
See examples/README.md for setup and script-by-script instructions.
Quick run commands (from lasersell-sdk/python):
python examples/build_buy.py
python examples/build_sell.py
python examples/build_and_send_sell.py
python examples/auto_sell.py
Scripts:
build_buy.pybuild_sell.pybuild_and_send_sell.pyauto_sell.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lasersell_sdk-0.2.2.tar.gz.
File metadata
- Download URL: lasersell_sdk-0.2.2.tar.gz
- Upload date:
- Size: 23.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4fbe6af0e23c96757dd75e6e01867f0a7e89bf0873dc7ee003a71f7c5fd619c
|
|
| MD5 |
b4e783776effdfdc8c09c291d45c43f4
|
|
| BLAKE2b-256 |
2a882fced3e0a9517b2c987c56e3886fb5207a9e8e1eeecdd0afcaec9b1d30ae
|
Provenance
The following attestation bundles were made for lasersell_sdk-0.2.2.tar.gz:
Publisher:
publish.yml on lasersell/lasersell-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lasersell_sdk-0.2.2.tar.gz -
Subject digest:
e4fbe6af0e23c96757dd75e6e01867f0a7e89bf0873dc7ee003a71f7c5fd619c - Sigstore transparency entry: 1008360316
- Sigstore integration time:
-
Permalink:
lasersell/lasersell-sdk@21c5227b94f057f371f2c5b73ffd1c6754404acc -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/lasersell
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@21c5227b94f057f371f2c5b73ffd1c6754404acc -
Trigger Event:
release
-
Statement type:
File details
Details for the file lasersell_sdk-0.2.2-py3-none-any.whl.
File metadata
- Download URL: lasersell_sdk-0.2.2-py3-none-any.whl
- Upload date:
- Size: 24.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4f3fc5a433d133a079b635c701a08f2175d736ac69ca4cc3988fe07a2b1a613
|
|
| MD5 |
7637e609c9dd5b686fe27cb274d5102d
|
|
| BLAKE2b-256 |
beedac970ee9396932146ff46ec0ae6a7e143f069e5990c261ddfe8bf8c341f0
|
Provenance
The following attestation bundles were made for lasersell_sdk-0.2.2-py3-none-any.whl:
Publisher:
publish.yml on lasersell/lasersell-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lasersell_sdk-0.2.2-py3-none-any.whl -
Subject digest:
a4f3fc5a433d133a079b635c701a08f2175d736ac69ca4cc3988fe07a2b1a613 - Sigstore transparency entry: 1008360319
- Sigstore integration time:
-
Permalink:
lasersell/lasersell-sdk@21c5227b94f057f371f2c5b73ffd1c6754404acc -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/lasersell
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@21c5227b94f057f371f2c5b73ffd1c6754404acc -
Trigger Event:
release
-
Statement type: