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

@backtest-kit/ollama

v0.1.1

Published

Multi-provider LLM inference library for AI-powered trading strategies. Supports 10+ providers including OpenAI, Claude, DeepSeek, Grok, Mistral with unified API and automatic token rotation.

Readme

🤖 @backtest-kit/ollama

Multi-provider LLM inference library for AI-powered trading strategies. Supports 10+ providers including OpenAI, Claude, DeepSeek, Grok, and more with unified API and automatic token rotation.

bots

Ask DeepWiki npm TypeScript

Transform technical analysis into trading decisions with multi-provider LLM support, structured output, and built-in risk management.

📚 Backtest Kit Docs | 🌟 GitHub

✨ Features

  • 🔌 10+ LLM Providers: OpenAI, Claude, DeepSeek, Grok, Mistral, Perplexity, Cohere, Alibaba, Hugging Face, Ollama
  • 🔄 Token Rotation: Automatic API key rotation for Ollama (others throw clear errors)
  • 🎯 Structured Output: Enforced JSON schema for trading signals (position, price levels, risk notes)
  • 🔑 Flexible Auth: Context-based API keys or environment variables
  • Unified API: Single interface across all providers
  • 📊 Trading-First: Built for backtest-kit with position sizing and risk management
  • 🛡️ Type Safe: Full TypeScript support with exported types

📋 What It Does

@backtest-kit/ollama provides a unified interface to call multiple LLM providers and receive structured trading signals:

| Provider | Function | Base URL | |----------|----------|----------| | OpenAI | gpt5() | https://api.openai.com/v1/ | | Claude | claude() | https://api.anthropic.com/v1/ | | DeepSeek | deepseek() | https://api.deepseek.com/ | | Grok | grok() | https://api.x.ai/v1/ | | Mistral | mistral() | https://api.mistral.ai/v1/ | | Perplexity | perplexity() | https://api.perplexity.ai/ | | Cohere | cohere() | https://api.cohere.ai/compatibility/v1/ | | Alibaba | alibaba() | https://dashscope-intl.aliyuncs.com/compatible-mode/v1/ | | Hugging Face | hf() | https://router.huggingface.co/v1/ | | Ollama | ollama() | https://ollama.com/ | | Zhipu AI | glm4() | https://api.z.ai/api/paas/v4/ |

Output Schema:

{
  id: string;              // Unique signal ID
  position: "long" | "short";  // Trading direction
  minuteEstimatedTime: number; // Hold duration estimate
  priceStopLoss: number;       // Stop loss price
  priceTakeProfit: number;     // Take profit price
  note: string;                // Risk assessment note
  priceOpen: number;           // Entry price
}

🚀 Installation

npm install @backtest-kit/ollama agent-swarm-kit backtest-kit

📖 Usage

Quick Start - OpenAI

import { gpt5 } from '@backtest-kit/ollama';
import { commitHistorySetup } from '@backtest-kit/signals';

// Build context with technical analysis
const messages = [
  {
    role: 'system',
    content: 'You are a trading bot. Analyze indicators and return JSON: { position: "long"|"short", priceStopLoss, priceTakeProfit, minuteEstimatedTime, priceOpen, note }'
  }
];

await commitHistorySetup('BTCUSDT', messages);

// Get trading signal from GPT-5
const signal = await gpt5(messages, 'gpt-4o', process.env.CC_OPENAI_API_KEY);

console.log(signal);
// {
//   id: "abc-123",
//   position: "long",
//   priceStopLoss: 49000,
//   priceTakeProfit: 51000,
//   minuteEstimatedTime: 60,
//   priceOpen: 50000,
//   note: "Strong bullish momentum with RSI oversold recovery"
// }

Multi-Provider Strategy

import { gpt5, claude, deepseek } from '@backtest-kit/ollama';
import { addStrategy } from 'backtest-kit';
import { commitHistorySetup } from '@backtest-kit/signals';

addStrategy({
  strategyName: 'multi-llm',
  interval: '5m',
  riskName: 'aggressive',
  getSignal: async (symbol) => {
    const messages = [
      {
        role: 'system',
        content: 'Analyze technical data and return trading signal as JSON'
      }
    ];

    await commitHistorySetup(symbol, messages);

    // Try multiple providers with fallback
    try {
      return await deepseek(messages, 'deepseek-chat');
    } catch (err) {
      console.warn('DeepSeek failed, trying Claude:', err);
      try {
        return await claude(messages, 'claude-3-5-sonnet-20241022');
      } catch (err2) {
        console.warn('Claude failed, using GPT-5:', err2);
        return await gpt5(messages, 'gpt-4o');
      }
    }
  }
});

Token Rotation (Ollama Only)

Ollama supports automatic API key rotation by passing an array:

import { ollama } from '@backtest-kit/ollama';

const signal = await ollama(
  messages,
  'llama3.3:70b',
  ['key1', 'key2', 'key3']  // Rotates through keys
);

// Other providers throw error:
// "Claude provider does not support token rotation"

Custom Logger

Enable logging for debugging:

import { setLogger } from '@backtest-kit/ollama';

setLogger({
  log: console.log,
  debug: console.debug,
  info: console.info,
  warn: console.warn,
});

💡 Why Use @backtest-kit/ollama?

Instead of manually integrating LLM SDKs:

// ❌ Without ollama (manual work)
import OpenAI from 'openai';
import Anthropic from '@anthropic-ai/sdk';

const openai = new OpenAI({ apiKey: process.env.OPENAI_KEY });
const response = await openai.chat.completions.create({
  model: 'gpt-4o',
  messages,
  response_format: { type: 'json_object' }
});
const signal = JSON.parse(response.choices[0].message.content);
// ... manual schema validation
// ... manual error handling
// ... no fallback
// ✅ With ollama (one line)
const signal = await gpt5(messages, 'gpt-4o');

Benefits:

  • ⚡ Unified API across 10+ providers
  • 🎯 Enforced JSON schema (no parsing errors)
  • 🔄 Built-in token rotation (Ollama)
  • 🔑 Context-based API keys
  • 🛡️ Type-safe TypeScript interfaces
  • 📊 Trading-specific output format

🤝 Contribute

Fork/PR on GitHub.

📜 License

MIT © tripolskypetr