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 support@okcoin.com 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 = ; // Test public data APIsvar publicClient = ; // get BTCUSD tickerpublicClient; // get BTCUSD order bookpublicClient; // get trades defaulting to BTCUSDpublicClient; // replace the parameters with your API key and secretvar privateClient = 'your-api-key' 'your-api-secret'; privateClient; // buy limit order for 0.01 BTC at price 100 USDprivateClient;// sell limit order for 0.01 BTC at price 900 USDprivateClient; // market buy of 25 USDprivateClient;// market sell of 0.01 BTCprivateClient; privateClient; // get all open ordersprivateClient; // get the first 20 unfilled ordersprivateClient;// get the third 20 filled ordersprivateClient; // get the first 5 account depositsprivateClient;// get the first 5 account withdrawalsprivateClient;
Please see the exmaples.js file for more examples