npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

saksh-trading-bot

v2.0.2

Published

A modular Node.js trading bot for processing TradingView webhooks with custom trading, Open AI parsing, and event-based monitoring

Readme

Saksh Trading Bot

A modular Node.js trading bot for processing TradingView webhooks, executing trades via a custom callback, and storing data in MongoDB. Supports paper trading and Binance trading (Testnet or live) with event-based monitoring and JSON logging, inspired by Cornix’s API-driven functionality.

Features

  • Webhook Processing: Parses JSON or text (e.g., AltAlgo) webhooks into a standard JSON format using a user-defined webhookParserCallback.
  • Custom Trading: Executes trades via a placeOrderCallback, supporting paper trading, Binance, or other exchanges.
  • Paper Trading: Simulates trades with mock prices and balance tracking.
  • Binance Trading: Connects to Binance API (Testnet or live) using ccxt.
  • Event Monitoring: Emits events (tradeExecuted, stopLossTriggered, etc.) for real-time tracking.
  • Data Storage: Logs trades and webhooks to MongoDB and logs.json.
  • No Internal Indicators: Relies on third-party webhook signals for trading decisions.

Installation

  1. Clone or Create Project:

    mkdir my-trading-bot
    cd my-trading-bot
    npm init -y
  2. Install Dependencies:

    npm install saksh-trading-bot express mongodb dotenv ccxt
  3. Set Up Project Structure:

    • Copy examples/paper_trading_example.js, examples/binance_trading_example.js, and examples/webhook_parser.js to an examples folder.
    • Ensure saksh-trading-bot is installed with src/index.js.

Configuration

  1. Create .env:

    touch .env

    Add:

    MONGO_URI=mongodb://localhost:27017
    PORT=3000
    BINANCE_API_KEY=your_testnet_or_live_api_key
    BINANCE_SECRET_KEY=your_testnet_or_live_secret_key
    BINANCE_TESTNET=true
    • For Binance trading, get keys from testnet.binance.vision (Testnet) or Binance (live).
    • Set BINANCE_TESTNET=false for live trading.
  2. Set Up MongoDB:

Usage

Paper Trading

Run the paper trading example to simulate trades:

node examples/paper_trading_example.js
  • Output:
    Connected to MongoDB
    [EVENT] Bot Initialized: {"symbol":"BTC/USDT","timestamp":"2025-07-03T08:28:00Z"}
    Webhook server running on port 3000

Binance Trading

Run the Binance trading example:

node examples/binance_trading_example.js
  • Requires valid BINANCE_API_KEY, BINANCE_SECRET_KEY in .env.
  • Set BINANCE_TESTNET=false for live trading.

Webhook Format

The bot expects webhooks to be parsed into this JSON format by webhookParserCallback:

{
  "action": "buy" | "sell",
  "symbol": "BTC/USDT",
  "quantity": 0.001, // Optional, defaults to 0.001
  "stopLoss": 0.03, // Optional, percentage (e.g., 3%)
  "takeProfit": 0.05, // Optional, percentage (e.g., 5%)
  "timestamp": "2025-07-03T08:28:00Z" // Optional, ISO format
}
  • The webhookParserCallback in examples/webhook_parser.js handles:
    • JSON payloads: Uses input with defaults for missing fields.
    • Text payloads (e.g., AltAlgo (...): order buy @ 50000 filled on BTCUSD): Parses to JSON using regex.
  • Extend webhookParserCallback with an AI model (e.g., xAI API) for advanced parsing.

Event Monitoring

The bot emits events for real-time monitoring, logged to logs.json and MongoDB in examples/*.js:

  • botInitialized: Bot startup with config.
  • webhookReceived, webhookParsed: Webhook processing.
  • webhookParseFailed: Invalid payload format.
  • webhookValidationFailed: Invalid action or symbol.
  • tradeExecuted: Trade placement with details.
  • tradeMonitored: Price monitoring for stop-loss/take-profit.
  • stopLossTriggered: Stop-loss hit.
  • takeProfitTriggered: Take-profit hit.
  • error: Any issues with details.

Testing

  1. Webhook Test:

    • JSON:
      curl -X POST http://carbonew.exchange:3000/webhook \
      -H "Content-Type: application/json" \
      -d '{"action":"buy","symbol":"BTC/USDT","quantity":0.001,"stopLoss":0.03,"takeProfit":0.05}'
    • Text (AltAlgo):
      curl -X POST http://carbonew.exchange:3000/webhook \
      -H "Content-Type: text/plain" \
      -d 'AltAlgo (...): order buy @ 50000 filled on BTCUSD'
    • Output:
      [EVENT] Webhook Received: {"payload":"AltAlgo (...): order buy @ 50000 filled on BTCUSD"}
      [EVENT] Webhook Parsed: {"parsedPayload":{"action":"buy","symbol":"BTC/USDT","quantity":0.001,"stopLoss":0.03,"takeProfit":0.05,...}}
      [EVENT] Trade Executed: {"type":"buy","price":50000,"quantity":0.001,"stopLoss":0.03,"takeProfit":0.05,"balance":950}
  2. Check MongoDB:

    const { MongoClient } = require('mongodb');
    async function checkData() {
        const client = new MongoClient('mongodb://localhost:27017');
        await client.connect();
        const db = client.db('trading_bot');
        const trades = await db.collection('trades').find().toArray();
        console.log(trades);
        await client.close();
    }
    checkData();
    • Expected:
      {
        "timestamp": "2025-07-03T08:28:00Z",
        "type": "buy",
        "price": 50000,
        "quantity": 0.001,
        "balance": 950,
        "stopLoss": 0.03,
        "takeProfit": 0.05
      }
  3. Check logs.json:

    [
      {"event":"Bot Initialized","symbol":"BTC/USDT","timestamp":"2025-07-03T08:28:00Z"},
      {"event":"Webhook Received","payload":"AltAlgo (...): order buy @ 50000 filled on BTCUSD"},
      {"event":"Trade Executed","type":"buy","price":50000,"quantity":0.001,"balance":950,"stopLoss":0.03,"takeProfit":0.05}
    ]

Dependencies

  • saksh-trading-bot: Core trading bot module.
  • express: Web server for webhook endpoint.
  • mongodb: MongoDB driver for data storage.
  • dotenv: Environment variable management.
  • ccxt: Binance API access (for binance_trading_example.js).

Troubleshooting

  • No Trades: Verify webhook URL, API keys, and Binance Testnet access (testnet.binance.vision).
  • Webhook Errors: Ensure payloads are parsable by webhookParserCallback.
  • MongoDB: Confirm MONGO_URI and database connectivity.

Extending the Bot

  • Custom Exchange: Replace placeOrderCallback in examples/*.js with logic for another exchange (e.g., Coinbase).
  • AI Parsing: Enhance webhookParserCallback in examples/webhook_parser.js with an AI model (e.g., xAI API).
  • Custom Logging: Modify event listeners in examples/*.js to log to other systems (e.g., MySQL, Redis).

License

MIT License. See LICENSE for details.