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

z_okcoin

v1.0.4

Published

Node.js API

Downloads

7

Readme

Node.js API wrapper to the OKCoin bitcoin exchange

A node.js wrapper for the REST APIs exposed by bitcoin exchange OKCoin. You will need have a registered account with OKCoin and generated API keys to access the private methods.

Please contact [email protected] if you are having trouble opening and account or generating an API key.

Install

npm install z_okcoin

Design Principles

  • thin the client is just a simple wrapper to the OKCoin API. There is no parameter validation as this is delegated to the OKCoin API server. Similarly, there is no data transformation.
  • errors all errors are returned as detailed Error objects which can be used programatically or for support
  • no retries it's up to the calling program to handle retries as it'll vary between programs. For example, error handling timeouts on mutable API calls like addTrade and cancelOrder is not as simple as retying the API call as the operation my have been successful on the exchange but the response back was not.

Error handling

The first parameter to each API function is a callback function which is passed error and data objects.

The error object is an instance of VError which is an extension of the standard Error object. The three main properties are:

  • message a description of the error with all the available information so problems in production can be diagnosed. For example the url, http request method, parameters, error codes and messages
  • name the HTTP or OKCoin error code so specific errors can be programatically detected. For example, 503 if you are sending too many requests per second or 10010 if there is not enough funds to add a trade
  • cause the underlying error object. eg the error object from a failed request or json parse. Note there will be no cause error for OKCoin errors

Examples

var OKCoin = require('z_okcoin');

// Test public data APIs
var publicClient = new OKCoin();

// get BTCUSD ticker
publicClient.getTicker(console.log, 'btc_usd');

// get BTCUSD order book
publicClient.getDepth(console.log, 'btc_usd');

// get trades defaulting to BTCUSD
publicClient.getTrades(console.log);

// replace the parameters with your API key and secret
var privateClient = new OKCoin('your-api-key', 'your-api-secret');

privateClient.getUserInfo(console.log);

// buy limit order for 0.01 BTC at price 100 USD
privateClient.addTrade(console.log, 'btc_usd', 'buy', '0.01', '100');
// sell limit order for 0.01 BTC at price 900 USD
privateClient.addTrade(console.log, 'btc_usd', 'sell', '0.01', '900');

// market buy of 25 USD
privateClient.addTrade(console.log, 'btc_usd', 'buy_market', null, '25');
// market sell of 0.01 BTC
privateClient.addTrade(console.log, 'btc_usd', 'sell_market', '0.01');

privateClient.cancelOrder(console.log, 'btc_usd', 31234567);

// get all open orders
privateClient.getOrderInfo(console.log, 'btc_usd', '-1');

// get the first 20 unfilled orders
privateClient.getOrderHistory(console.log, 'btc_usd', 0, 1, 20);
// get the third 20 filled orders
privateClient.getOrderHistory(console.log, 'btc_usd', 1, 3, 20);

// get the first 5 account deposits
privateClient.getAccountRecords(console.log, 'btc_usd', 0, 1, 5);
// get the first 5 account withdrawals
privateClient.getAccountRecords(console.log, 'btc_usd', 1, 1, 5);

Please see the exmaples.js file for more examples