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

crypto-exchange-client

v0.0.6

Published

A common typed interface for cryptocurrency REST and websocket clients

Downloads

2

Readme

Typescript Crypto API Clients w/ WebSockets

Similar to ccxt, this project aims to provide a common interface for interacting with exchange apis. The difference is that this projcet provides a common websocket interface, is implemented in only a single language, and enforces types (so that different implementations can be uniform, and not cause errors when switching between exchanges)

Cobinhood is the only completed implementation, but this project is setup to allow for any number of implementations.

Installation

Coming soon

Cobinhood Usage

API Documentation

Authentication

In the root of your project folder, create a .env file

COBINHOOD_API_KEY="your-cobinhood-api-key"

this will be loaded on boot of your application, and will throw an exception if process.env.COBINHOOD_API_KEY is an empty value when trying to access an authenticated endpoint (meaning, you don't need an .env file, but it's handy for development).

Examples

See ./examples/cobinhood
run with

yarn example ./examples/cobinhood/watch-market-depth.ts

Creating Clients

import { CobinhoodRestClient, CobinhoodFeed } from 'crypto-exchange-client';

const client = new CobinhoodRestClient();
const socket = new client.SocketClient();
// or, specifically:
const socket = new CobinhoodFeed();

Using the WebSocket Client

socket.onOpen(handleOpen(socket));

socket.onReceiveTicker(handleReceivedTicker);
socket.onReceiveOrderBookUpdate(handleReceivedOrderBookUpdate);

socket.onSubscribe(handleSubscribe);
socket.connect();

const handleOpen = (socket) => () => {
  socket.subscribeTo('ticker', { trading_pair_id: 'ETH-BTC' });
};

// do something with ticker data
const handleReceivedTicker = (data: TickerUpdate) => {};

// do something with order book data
const handleReceivedOrderBookUpdate = (data: OrderBookUpdateSummary) => {};

// json here is a subscription response, which mostly contains
// the subscription request data
const handleSubscribe = (json: any) => {}

REST Client Overview

NOTE: this documentation is a work in progress. PRs to expand it will be more than welcome.

// getting all your balances
const balances = await client.getBalances();

// buying
const order = await client.createLimitBuyOrder('ETH-BTC', '2', '0.098');

Full Cobinhood Documentation

Cobinhood Rest Client

Given that you have a CobinhoodRestClient,

const client = new CobinhoodRestClient();

The following mirrors the cobinhood api documentation

Markets

None of the market apis require auth.

client.getCurrencies()
client.getMarkets()
client.getOrderBook(market: string, limit = 50)
client.getMarketStats()
client.getTicker();
client.getRecentTrades(market: string);

Interacting with the market data:

// { [symbol: string]: MarketPair }
client.marketPairsBySymbol

All market data from the api requests are stored on an object of type MarketPair.

Note that if a list of currency symbols is needed, but a separate request is not desired, that can be done with Object.keys on the client.marketPairsBySymbol data, and splitting on the separator, -.

const currencies = _.uniq(_.flatten(
    Object.keys(marketPairsBySymbol).map(symbol => symbol.split('-'))
))

Getting Cached Market

client.marketForSymbol('ETH-BTC');

Orders

All of these apis require auth

client.getOrder(id: string);
client.getOpenOrders();

client.createOrder(market: string, amount: string, price: string, type: string, isBuySide: boolean);
// shorthands for createOrder
client.createLimitOrder(market: string, amount: string, price: string, isBuySide: boolean);
client.createLimitBuyOrder(market: string, amount: string, price: string);
client.createLimitSellOrder(market: string, amount: string, price: string);

client.createMarketBuyOrder(market: string, amount: string);
client.createMarketSellOrder(market: string, amount: string);
client.createMarketOrder(market: string, amount: string, isBuySide: boolean);


client.cancelOrder(id: string);
const socket = new CobinhoodFeed();

Support

Programming takes time, so if there is no time to submit a PR or a bugfix, donations are welcome at:

ETH (or any ERC20 that Cobinhood supports):
0xF6C2769a30647f6B7a412E446cD56650fAC64205

BTC:
1MfGcwcUPHADTumrxCponqv7eAxfZMyha8