@xstocker/agent-sdk
SDK for AI agents to trade tokenized U.S. stocks (xStocks) on Solana.
No account. No API key. No OAuth. This SDK only reads public data and builds
unsigned transactions — it never touches a private key. You (or your agent
framework's wallet adapter) are responsible for signing and broadcasting the
returned transaction.
Install
npm install @xstocker/agent-sdk
Usage
import { xstocker } from "@xstocker/agent-sdk";
const { assets, payTokens } = await xstocker.getAssets();
const order = await xstocker.buildOrder({
wallet: "USER_SOLANA_ADDRESS",
asset: "NVDAx",
amount: 100,
payToken: "USDC",
side: "buy",
});
console.log(order.details);
console.log(order.solanaPayUrl);
const status = await xstocker.getOrderStatus(signature);
console.log(status.status);
Selling
await xstocker.buildOrder({
wallet: "USER_SOLANA_ADDRESS",
asset: "NVDAx",
amount: 0.5,
payToken: "USDC",
side: "sell",
});
On a sell, amount is in the units the wallet shows (xStocks are scaled-UI
tokens, so this can differ from the raw on-chain amount; the API converts it).
Pass a number, or a decimal string for up to 8 decimals. The API never sells
more than the wallet holds.
Sell everything
const order = await xstocker.buildOrder({
wallet: "USER_SOLANA_ADDRESS",
asset: "NVDAx",
amount: "max",
side: "sell",
});
console.log(order.details.amountIn);
With "max" the API reads the exact on-chain balance itself, so you do not need
to look it up (and there is no rounding dust left behind).
Referral partners
No registration, no API key, no claiming. A partner is just a Solana wallet
address. Pass it as partner and the partner's fee is sent to that wallet,
on-chain, in the same transaction as the trade. The trader pays it on top
of the standard fee (0.25% by default).
const order = await xstocker.buildOrder({
wallet: "USER_SOLANA_ADDRESS",
asset: "NVDAx",
amount: 100,
partner: "YOUR_WALLET_ADDRESS",
});
console.log(order.details.partnerFee);
USDC trades pay into the partner's USDC token account (it must exist: receive
any USDC to that wallet once), SOL trades pay into the wallet itself. If the
fee can't be paid, the trade is still built normally and partnerFee says why
(applied: false, reason: "partner_usdc_account_missing", ...). Check a
wallet up front:
const check = await xstocker.checkPartner("YOUR_WALLET_ADDRESS");
console.log(check.usdc.ready, check.sol.ready);
Custom client
import { XStockerAgentClient } from "@xstocker/agent-sdk";
const client = new XStockerAgentClient({ baseUrl: "https://api.xstocker.com" });
Assets
getAssets() reads a static file from the CDN, not the API. asset in
buildOrder() accepts the ticker in any letter case (the trailing "x" is
optional) or the token's mint address.
Error handling
import { XStockerAgentError } from "@xstocker/agent-sdk";
try {
await xstocker.buildOrder({ wallet, asset: "NVDAx", amount: 100 });
} catch (err) {
if (err instanceof XStockerAgentError) {
console.error(err.code, err.message);
}
}
Links
License
MIT