Skip to content

Latest commit

 

History

History
659 lines (531 loc) · 12.9 KB

File metadata and controls

659 lines (531 loc) · 12.9 KB

Linda Trading Platform - API Documentation

Overview

Linda is a professional stock trading platform with real-time market data, automated trading bots, and workflow automation (like n8n). This API allows you to programmatically execute trades, create trading bots, and build automated workflows.

Base URL: https://your-domain.com/api/v1

Authentication

All API endpoints require authentication via API Key.

Getting an API Key

  1. Log in to your Linda account at /login
  2. Go to Settings > API Keys
  3. Click "Create API Key"
  4. Select permissions (read, trade, bot, webhook)
  5. Save your API key - it won't be shown again!

Using API Keys

Include your API key in request headers:

# Option 1: X-API-Key header
curl -H "X-API-Key: lnd_your_api_key_here" https://api.example.com/api/v1/account

# Option 2: Bearer token
curl -H "Authorization: Bearer lnd_your_api_key_here" https://api.example.com/api/v1/account

API Key Permissions

Permission Description
read View account, portfolio, quotes
trade Execute buy/sell orders
bot Create/manage trading bots and workflows
webhook Create/manage webhooks
withdraw Full access (all permissions)

Endpoints

Account

Get Account Overview

GET /api/v1/account

Returns account summary including portfolio, holdings, and recent orders.

Response:

{
  "success": true,
  "data": {
    "user": {
      "id": "user_123",
      "email": "trader@example.com",
      "name": "John Doe"
    },
    "account": {
      "type": "DEMO",
      "currency": "USD",
      "cashBalance": 85000.00,
      "portfolioValue": 15000.00,
      "totalValue": 100000.00,
      "totalGain": 2500.00,
      "totalGainPercent": 2.5
    },
    "holdings": [
      {
        "symbol": "AAPL",
        "name": "Apple Inc.",
        "quantity": 50,
        "avgBuyPrice": 175.00,
        "currentPrice": 180.50,
        "currentValue": 9025.00,
        "gain": 275.00,
        "gainPercent": 3.14
      }
    ],
    "automation": {
      "activeBots": 2,
      "activeWorkflows": 1
    }
  }
}

Market Data

Get Real-Time Quote

GET /api/v1/quote?symbol=AAPL

Get real-time stock quote from Yahoo Finance.

Parameters:

Parameter Type Description
symbol string Stock symbol (e.g., AAPL)
symbols string Comma-separated symbols (max 20)

Response:

{
  "success": true,
  "data": {
    "symbol": "AAPL",
    "name": "Apple Inc.",
    "price": 180.50,
    "change": 2.35,
    "changePercent": 1.32,
    "previousClose": 178.15,
    "dayHigh": 181.20,
    "dayLow": 178.00,
    "volume": 45000000,
    "timestamp": "2026-01-03T15:30:00Z"
  }
}

Trading

Execute Trade

POST /api/v1/trade

Execute a buy or sell order.

Request Body:

{
  "symbol": "AAPL",
  "side": "BUY",
  "quantity": 10,
  "type": "MARKET"
}

Parameters:

Parameter Type Required Description
symbol string Yes Stock symbol
side string Yes BUY or SELL
quantity integer Yes Number of shares
type string No MARKET (default) or LIMIT
price number No Required for LIMIT orders

Response:

{
  "success": true,
  "data": {
    "orderId": "ord_abc123",
    "symbol": "AAPL",
    "side": "BUY",
    "type": "MARKET",
    "quantity": 10,
    "price": 180.50,
    "total": 1805.00,
    "status": "FILLED",
    "executedAt": "2026-01-03T15:30:00Z",
    "newBalance": 83195.00
  }
}

Get Trade History

GET /api/v1/trade?limit=50&offset=0

Trading Bots

Create Bot

POST /api/v1/bots

Create an automated trading bot.

Request Body:

{
  "name": "AAPL DCA Bot",
  "symbol": "AAPL",
  "strategy": "DCA",
  "config": {
    "amount": 100,
    "frequency": "daily",
    "buyOnDip": true,
    "dipThreshold": 3
  },
  "maxInvestment": 5000,
  "autoStart": false
}

Strategies:

Strategy Description Config
DCA Dollar Cost Averaging amount, frequency, buyOnDip, dipThreshold
GRID Grid Trading upperPrice, lowerPrice, gridLevels, amountPerGrid
TRAILING_STOP Trailing Stop Loss trailingPercent, takeProfitPercent, initialStopPercent
CUSTOM Custom Conditions conditions[], action, amount

DCA Config Example:

{
  "amount": 100,          // $100 per buy
  "frequency": "daily",   // hourly, daily, weekly, monthly
  "buyOnDip": true,       // Buy extra on dips
  "dipThreshold": 3       // Buy on 3%+ drop
}

GRID Config Example:

{
  "upperPrice": 200,      // Sell at $200
  "lowerPrice": 150,      // Buy at $150
  "gridLevels": 5,        // 5 grid levels
  "amountPerGrid": 500    // $500 per trade
}

CUSTOM Config Example:

{
  "conditions": [
    { "indicator": "price", "operator": "lt", "value": 150 },
    { "indicator": "change_percent", "operator": "lt", "value": -2 }
  ],
  "action": "BUY",
  "amount": 1000
}

List Bots

GET /api/v1/bots

Get Bot Details

GET /api/v1/bots/{id}

Update Bot

PATCH /api/v1/bots/{id}
{
  "status": "ACTIVE",
  "config": { ... }
}

Run Bot Manually

POST /api/v1/bots/{id}/run

Trigger bot execution immediately.

Delete Bot

DELETE /api/v1/bots/{id}

Workflows (Automation like n8n)

Workflows allow you to create "if this then that" automation rules.

Create Workflow

POST /api/v1/workflows

Request Body:

{
  "name": "Buy on AAPL Dip",
  "description": "Buy AAPL when price drops 5%",
  "trigger": {
    "type": "price_change_percent",
    "symbol": "AAPL",
    "value": -5
  },
  "actions": [
    {
      "type": "buy_stock",
      "params": {
        "symbol": "AAPL",
        "amount": 500
      }
    },
    {
      "type": "send_webhook",
      "params": {
        "url": "https://your-webhook.com/notify",
        "method": "POST"
      }
    }
  ],
  "autoActivate": true
}

Trigger Types:

Trigger Description Parameters
price_above Price goes above threshold symbol, value
price_below Price goes below threshold symbol, value
price_change_percent Price changes by X% symbol, value
volume_spike Volume exceeds X times average symbol, value
time_schedule Run at scheduled times schedule (cron)
manual Only run manually -

Action Types:

Action Description Parameters
buy_stock Buy shares symbol, amount or quantity
sell_stock Sell shares symbol, quantity or sellAll
send_webhook Send HTTP request url, method, headers
send_notification Send notification title, message
start_bot Activate a bot botId
stop_bot Pause a bot botId
log_message Log a message message

List Workflows

GET /api/v1/workflows

Run Workflow Manually

POST /api/v1/workflows/{id}/run

Webhooks

Receive real-time notifications when events occur.

Create Webhook

POST /api/v1/webhooks
{
  "name": "Order Notifications",
  "url": "https://your-server.com/webhooks/linda",
  "events": ["order.filled", "alert.triggered"]
}

Events:

  • order.created - New order placed
  • order.filled - Order executed
  • order.cancelled - Order cancelled
  • order.rejected - Order rejected
  • alert.triggered - Price alert triggered
  • balance.changed - Wallet balance changed
  • bot.executed - Bot made a trade
  • workflow.completed - Workflow finished
  • * - All events

Webhook Payload

{
  "event": "order.filled",
  "timestamp": "2026-01-03T15:30:00Z",
  "data": {
    "orderId": "ord_abc123",
    "symbol": "AAPL",
    "side": "BUY",
    "quantity": 10,
    "price": 180.50,
    "total": 1805.00
  }
}

Verifying Webhooks

Each webhook request includes a signature header:

X-Webhook-Signature: sha256_signature_here
X-Webhook-Event: order.filled
X-Webhook-Timestamp: 2026-01-03T15:30:00Z

Verify with:

import hmac
import hashlib

def verify_signature(payload, signature, secret):
    expected = hmac.new(
        secret.encode(),
        payload.encode(),
        hashlib.sha256
    ).hexdigest()
    return hmac.compare_digest(signature, expected)

Test Webhook

POST /api/v1/webhooks/{id}/test

Example Use Cases

1. Simple DCA Bot

Invest $100 in AAPL every day:

curl -X POST https://api.linda.com/api/v1/bots \
  -H "X-API-Key: lnd_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Daily AAPL DCA",
    "symbol": "AAPL",
    "strategy": "DCA",
    "config": {
      "amount": 100,
      "frequency": "daily"
    },
    "maxInvestment": 10000,
    "autoStart": true
  }'

2. Buy the Dip Workflow

Buy when any stock drops 5%:

curl -X POST https://api.linda.com/api/v1/workflows \
  -H "X-API-Key: lnd_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Buy NVDA Dip",
    "trigger": {
      "type": "price_change_percent",
      "symbol": "NVDA",
      "value": -5
    },
    "actions": [
      {
        "type": "buy_stock",
        "params": { "symbol": "NVDA", "amount": 1000 }
      },
      {
        "type": "send_webhook",
        "params": { "url": "https://hooks.slack.com/your-webhook" }
      }
    ],
    "autoActivate": true
  }'

3. Grid Trading Bot

Profit from price swings:

curl -X POST https://api.linda.com/api/v1/bots \
  -H "X-API-Key: lnd_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "TSLA Grid Trader",
    "symbol": "TSLA",
    "strategy": "GRID",
    "config": {
      "upperPrice": 300,
      "lowerPrice": 200,
      "gridLevels": 10,
      "amountPerGrid": 500
    },
    "maxInvestment": 5000,
    "autoStart": true
  }'

Rate Limits

Endpoint Limit
/quote 60 requests/minute
/trade 30 requests/minute
/bots, /workflows 30 requests/minute
All other endpoints 100 requests/minute

Error Codes

Code Description
UNAUTHORIZED Invalid or missing API key
FORBIDDEN API key lacks required permission
NOT_FOUND Resource not found
VALIDATION_ERROR Invalid request parameters
INSUFFICIENT_FUNDS Not enough balance
INSUFFICIENT_SHARES Not enough shares to sell
INTERNAL_ERROR Server error

SDKs & Libraries

Python

import requests

class LindaAPI:
    def __init__(self, api_key):
        self.api_key = api_key
        self.base_url = "https://api.linda.com/api/v1"
    
    def _request(self, method, endpoint, data=None):
        headers = {"X-API-Key": self.api_key}
        response = requests.request(
            method, 
            f"{self.base_url}{endpoint}",
            headers=headers,
            json=data
        )
        return response.json()
    
    def get_quote(self, symbol):
        return self._request("GET", f"/quote?symbol={symbol}")
    
    def buy(self, symbol, quantity):
        return self._request("POST", "/trade", {
            "symbol": symbol,
            "side": "BUY",
            "quantity": quantity,
            "type": "MARKET"
        })
    
    def sell(self, symbol, quantity):
        return self._request("POST", "/trade", {
            "symbol": symbol,
            "side": "SELL",
            "quantity": quantity,
            "type": "MARKET"
        })

# Usage
api = LindaAPI("lnd_your_api_key")
quote = api.get_quote("AAPL")
print(f"AAPL: ${quote['data']['price']}")

# Buy 10 shares
result = api.buy("AAPL", 10)
print(f"Bought: {result}")

JavaScript/Node.js

class LindaAPI {
  constructor(apiKey) {
    this.apiKey = apiKey;
    this.baseUrl = 'https://api.linda.com/api/v1';
  }

  async request(method, endpoint, data = null) {
    const response = await fetch(`${this.baseUrl}${endpoint}`, {
      method,
      headers: {
        'X-API-Key': this.apiKey,
        'Content-Type': 'application/json',
      },
      body: data ? JSON.stringify(data) : null,
    });
    return response.json();
  }

  getQuote(symbol) {
    return this.request('GET', `/quote?symbol=${symbol}`);
  }

  buy(symbol, quantity) {
    return this.request('POST', '/trade', {
      symbol,
      side: 'BUY',
      quantity,
      type: 'MARKET',
    });
  }

  createBot(config) {
    return this.request('POST', '/bots', config);
  }
}

// Usage
const api = new LindaAPI('lnd_your_api_key');
const quote = await api.getQuote('AAPL');
console.log(`AAPL: $${quote.data.price}`);

Support