tradescape-sdk
v0.1.1
Published
TypeScript SDK for the Tradescape trading platform
Maintainers
Readme
@tradescape/sdk
TypeScript SDK for the Tradescape trading platform.
Installation
npm install @tradescape/sdk
# or
bun add @tradescape/sdkUsage
import { TradescapeClient, loadConfig } from "@tradescape/sdk";
// Load config from ~/.tradescape/config.json
const config = loadConfig();
// Or provide config directly
const client = new TradescapeClient({
token: "your-jwt-token",
apiUrl: "https://tradetronic.vercel.app",
});
// Setups
const setups = await client.setups.list({ status: "active" });
const setup = await client.setups.get(123);
const newSetup = await client.setups.create({
pair: "BTC/USDT",
direction: "long",
entryPrice: 42000,
takeProfitPrice: 45000,
stopPrice: 40000,
});
// Alerts
const alerts = await client.alerts.list({ status: "pending" });
const alert = await client.alerts.create({
pair: "BTC/USDT",
threshold: 50000,
direction: "above",
});
await client.alerts.delete("alert-id");
// Trades
const trades = await client.trades.list({ exchange: "binance" });
const syncResult = await client.trades.sync({ exchange: "binance" });
const positions = await client.trades.positions();
// Daily
const summary = await client.daily.summary();
const pnl = await client.daily.pnl({ from: "2024-01-01", to: "2024-01-31" });
// Pairs
const pairs = await client.pairs.list();
const pair = await client.pairs.get("BTC/USDT");Configuration
Config is stored in ~/.tradescape/config.json:
{
"apiUrl": "https://tradetronic.vercel.app",
"token": "your-jwt-token"
}Use the config utilities:
import { loadConfig, saveConfig, isAuthenticated } from "@tradescape/sdk";
// Check if token is set
if (!isAuthenticated()) {
console.log("Please set your token");
}
// Save config
saveConfig({
apiUrl: "https://tradetronic.vercel.app",
token: "new-token",
});Error Handling
import { TradescapeClient, isTRPCError } from "@tradescape/sdk";
try {
const setups = await client.setups.list();
} catch (error) {
if (isTRPCError(error)) {
console.error("API error:", error.message);
} else {
throw error;
}
}For Mastra Agents
import { TradescapeClient } from "@tradescape/sdk";
// In your agent tool
export const getActiveSetups = async () => {
const client = new TradescapeClient({
token: process.env.TRADESCAPE_TOKEN!,
apiUrl: process.env.TRADESCAPE_API_URL || "https://tradetronic.vercel.app",
});
return await client.setups.list({ status: "active" });
};