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 🙏

© 2024 – Pkg Stats / Ryan Hefner

robinhood-crypto

v0.0.8

Published

A TypeScript/JavaScript client library for interacting with the Robinhood Crypto API. This library provides a clean interface for crypto trading operations, market data retrieval, and account management.

Downloads

578

Readme

Robinhood Crypto Node.js Client

A TypeScript/JavaScript client library for interacting with the Robinhood Crypto API. This library provides a clean interface for crypto trading operations, market data retrieval, and account management.

For setup instructions and API documentation, please visit the official Robinhood Crypto API docs.

Installation

npm install robinhood-crypto-client

# or using yarn
yarn add robinhood-crypto-client

Initialization

import { RobinhoodCrypto } from 'robinhood-crypto-client';

const client = new RobinhoodCrypto({
  privateKeyBase64: 'YOUR_PRIVATE_KEY',
  publicKeyBase64: 'YOUR_PUBLIC_KEY',
  apiKey: 'YOUR_API_KEY'
});

API Methods

Market Data

getBestBidAsk

Get current bid/ask prices for specified symbols.

// Input
symbols: string[] = ["BTC-USD"]

// Output
{
  results: [{
    symbol: string;
    price: number;
    bid_inclusive_of_sell_spread: number;
    sell_spread: number;
    ask_inclusive_of_buy_spread: number;
    buy_spread: number;
    timestamp: string;
  }]
}

// Example
const bidAsk = await client.getBestBidAsk(['BTC-USD', 'ETH-USD']);
console.log('BTC/USD Price:', bidAsk.results[0].price);

getEstimatedPrice

Get estimated prices for specific quantities.

// Input
{
  symbol: string;
  side: "bid" | "ask" | "both";
  quantities: number[];
}

// Output
{
  results: [{
    symbol: string;
    side: "bid" | "ask";
    price: number;
    quantity: number;
    bid_inclusive_of_sell_spread: number;
    sell_spread: number;
    ask_inclusive_of_buy_spread: number;
    buy_spread: number;
    timestamp: string;
  }]
}

// Example
const estimate = await client.getEstimatedPrice(
  'BTC-USD',
  'bid',
  [0.1, 0.2]
);
console.log('Estimated price for 0.1 BTC:', estimate.results[0].price);

Trading

placeOrder

Place a new order.

// Input
{
  symbol: string;
  side: "buy" | "sell";
  type: "market" | "limit" | "stop_limit" | "stop_loss";
  market_order_config?: {
    asset_quantity: number;
  };
  limit_order_config?: {
    quote_amount?: number;
    asset_quantity?: number;
    limit_price: number;
    time_in_force: "gtc";
  };
  stop_loss_order_config?: {
    quote_amount?: number;
    asset_quantity?: number;
    stop_price: number;
    time_in_force: "gtc";
  };
  stop_limit_order_config?: {
    quote_amount?: number;
    asset_quantity?: number;
    limit_price: number;
    stop_price: number;
    time_in_force: "gtc";
  };
}

// Output
{
  id: string;
  account_number: string;
  symbol: string;
  client_order_id: string;
  side: "buy" | "sell";
  executions: Array<{
    effective_price: string;
    quantity: string;
    timestamp: string;
  }>;
  type: "limit" | "market" | "stop_limit" | "stop_loss";
  state: "open" | "canceled" | "partially_filled" | "filled" | "failed";
  average_price: number | null;
  filled_asset_quantity: number;
  created_at: string;
  updated_at: string;
}

// Example - Market Order
const marketOrder = await client.placeOrder({
  symbol: 'BTC-USD',
  side: 'buy',
  type: 'market',
  market_order_config: {
    asset_quantity: 0.001
  }
});

// Example - Limit Order
const limitOrder = await client.placeOrder({
  symbol: 'ETH-USD',
  side: 'buy',
  type: 'limit',
  limit_order_config: {
    asset_quantity: 0.1,
    limit_price: 2000,
    time_in_force: 'gtc'
  }
});

getOrder

Get details of a specific order.

// Input
orderId: string

// Output
{
  // Same as placeOrder output
}

// Example
const order = await client.getOrder('abc123');
console.log('Order status:', order.state);

getOrders

List orders with optional filters.

// Input
{
  created_at_start?: string;
  created_at_end?: string;
  symbol?: string;
  id?: string;
  side?: "buy" | "sell";
  state?: "open" | "canceled" | "partially_filled" | "filled" | "failed";
  type?: "limit" | "market" | "stop_limit" | "stop_loss";
  updated_at_start?: string;
  updated_at_end?: string;
  limit?: number;
  cursor?: string;
}

// Output
{
  next: string | null;
  previous: string | null;
  results: Array<Order>; // Same as placeOrder output
}

// Example
const orders = await client.getOrders({
  symbol: 'BTC-USD',
  side: 'buy',
  state: 'open'
});
console.log('Open BTC buy orders:', orders.results.length);

cancelOrder

Cancel an existing order.

// Input
orderId: string

// Output
{
  success: string;
}

// Example
const result = await client.cancelOrder('abc123');
console.log('Cancel successful:', result.success);

Account

getAccount

Get account information.

// Input
None

// Output
{
  account_number: string;
  status: "active" | "deactivated" | "sell_only";
  buying_power: string;
  buying_power_currency: string;
}

// Example
const account = await client.getAccount();
console.log('Buying power:', account.buying_power);

getHoldings

Get current holdings.

// Input
{
  assetCodes?: string[];
  limit?: number;
  cursor?: string;
}

// Output
{
  next: string | null;
  previous: string | null;
  results: Array<{
    account_number: string;
    asset_code: string;
    total_quantity: number;
    quantity_available_for_trading: number;
  }>;
}

// Example
const holdings = await client.getHoldings(['BTC', 'ETH']);
holdings.results.forEach(holding => {
  console.log(`${holding.asset_code} balance: ${holding.total_quantity}`);
});

Error Handling

// All methods may throw errors with this structure:
{
  type: "validation_error" | "client_error" | "server_error";
  errors: Array<{
    detail: string;
    attr: string | null;
  }>;
}

// Example
try {
  const order = await client.placeOrder({
    symbol: 'BTC-USD',
    side: 'buy',
    type: 'market',
    market_order_config: {
      asset_quantity: 0.001
    }
  });
} catch (error) {
  console.error('Order failed:', error.errors[0].detail);
}

License

MIT

Disclaimer

This is an unofficial client library and is not affiliated with or endorsed by Robinhood Markets, Inc. Use at your own risk.