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

coinpit-client

v5.0.2

Published

client library for coinpit

Downloads

34

Readme

coinpit-client

Alpha

Usage:

npm install --save coinpit-client

Create and use client

var CoinpitClient = require('coinpit-client')
var fs = require('fs')

if(process.argv.length != 3) {
  console.log("usage: " + process.argv[0] + " " + process.argv[1] + " <walletfile>")
  process.exit()
}

var walletFile = process.argv[2]
var stats      = walletFile && fs.statSync(walletFile)
var wallet     = fs.readFileSync(walletFile)
var walletData = JSON.parse(wallet)

CoinpitClient.getAccount(walletData.privateKey)
  .then(function(account) {
    return account.getAll()
  })
  .then(function(data) {
    console.log(data)
  })

General Exchange Info

Exchange bid asks

account.getBidAsk()

Get traded instruments

account.getInstruments()

Get Trading Bands

account.getIndexBands()

Account Management

Get Account balances

var balance = account.getBalance()

Result

accountBalance Format:
{
     balance        : multisig balance + margin balance + profit or loss,
     availableMargin: available amount which can be used to place order,
     multisig       : multisig balance (exludes unconfirmed),
     margin         : margin balance (includes unconfirmed)
}

Order Management

More examples at https://github.com/coinpit/coinpit-bots/blob/master/src/marketmakerBot.js

  • valid order Types: MKT (Market), LMT(Limit), STM(Stop-Market), SLM(Stop-Limit)
  • valid side: buy, sell

stopPrice and targetPrice are relative to fill price.

Get open orders

var openOrders = account.getOpenOrders()

Result

Create Order

var orders = yield account.createOrders([
  {
    price:620.1, side:'buy', orderType:'LMT', stopPrice:1.0, targetPrice:2.0, "instrument":"BTC1"
  }
])

Update order

var orders = yield account.updateOrders([
  {
    uuid:"0d42be40-93f4-11e6-9bce-18efd6b9331e",
    userid:"<usrid>","price":640
  },
  {
    uuid:"0d429730-93f4-11e6-a7bb-abf70afc0d67",
    userid:"<usrid>","price":633.6
  }
])

Cancel order

var result = yield account.cancelOrders([
  {
    uuid:"0d42be40-93f4-11e6-9bce-18efd6b9331e"
  },
  {
    uuid:"0d429730-93f4-11e6-a7bb-abf70afc0d67"
  }
])

Sending bulk orders using PATCH

  • cancels: orders object with uuid
  • updated: list of orders to be updated
  • creates: list of orders to be created
  • merge: list of order uuids. make sure to provide both stop and target orders uuids.
  • split: uuid of order to be split and one quantity of the quantity
var payload = {
cancels:[
    {uuid:"059af9e0-9107-11e6-9d5f-ec4c64c1864f"},
    {uuid:"059af9e0-9107-11e6-9d5f-ec4c64c1865f"},
    ],
updates:[
    {"uuid":"0d42be40-93f4-11e6-9bce-18efd6b9331e","userid":"<usrid>","price":640},
    {"uuid":"0d429730-93f4-11e6-a7bb-abf70afc0d67","userid":"<usrid>","price":633.6}
    ],
creates:[
    {price:620.1, side:'buy', orderType:'LMT', stopPrice:1.0, targetPrice:2.0, "instrument":"BTC1"}
    ],
merge:[
    "e3d269d1-9424-11e6-bb76-970122dc4d3a",
    "e3d269d0-9424-11e6-9766-f5d52d60c65d",
    "e3406301-9424-11e6-b859-38f93e196d74",
    "e3406300-9424-11e6-9aa4-cf820243deeb"
    ],
split:{uuid:"e9bdc381-9424-11e6-80a3-95573a44c8ab","quantity":1}
}
var result = yield account.patchOrders(payload)

Socket.io Topics

Coinpit client receives realtime socket.io messages from the exchange. This socket transparently performs authentication.

var socket = account.loginless.socket

You may use account.loginless.socket to send and listen to the following socket messages:

trade

Trade information is sent on every new trade.

{"date":1476337002, "price":636.7,"volume":1, "instrument":"BTC1"}

orderbook

A clean copy of the orderbook near the bid/ask is sent every 60 seconds.

{"bid":636.3,"ask":636.4,
"buy":[{"price":636.3,"numberOfOrders":1,"totalQuantity":1, "instrument":"BTC1"},{"price":636.2,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":636.1,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":636,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":635.9,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":635.8,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":635.7,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":635.6,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":635.5,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":635.4,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":635.3,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":635.2,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":635.1,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":635,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":634.9,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":634.8,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":634.7,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":634.6,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":634.5,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":634.4,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":634.3,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"}],
"sell":[{"price":636.4,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":636.5,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":636.6,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":636.7,"numberOfOrders":1,"totalQuantity":4, "instrument":"BTC1"},{"price":636.8,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":636.9,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":637,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":637.1,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":637.2,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":637.3,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":637.4,"numberOfOrders":1,"totalQuantity":2, "instrument":"BTC1"},{"price":637.5,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":637.6,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":637.7,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":637.8,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":637.9,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":638,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":638.1,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":638.2,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":638.3,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},{"price":"NONE","numberOfOrders":1,"totalQuantity":1, "instrument":"BTC1"}]
}

difforderbook

Real time orderbook changes are sent using this topic

{
"buy":{"635":{"price":635,"numberOfOrders":0,"totalQuantity":0, "instrument":"BTC1"},"637":{"price":637,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},"634.9":{"price":634.9,"numberOfOrders":0,"totalQuantity":0, "instrument":"BTC1"},"636.9":{"price":636.9,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},"634.8":{"price":634.8,"numberOfOrders":0,"totalQuantity":0, "instrument":"BTC1"},"636.8":{"price":636.8,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},"634.7":{"price":634.7,"numberOfOrders":0,"totalQuantity":0, "instrument":"BTC1"},"636.7":{"price":636.7,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},"634.6":{"price":634.6,"numberOfOrders":0,"totalQuantity":0, "instrument":"BTC1"},"636.6":{"price":636.6,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},"634.5":{"price":634.5,"numberOfOrders":0,"totalQuantity":0, "instrument":"BTC1"},"636.5":{"price":636.5,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},"634.4":{"price":634.4,"numberOfOrders":0,"totalQuantity":0, "instrument":"BTC1"},"636.4":{"price":636.4,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},"634.3":{"price":634.3,"numberOfOrders":0,"totalQuantity":0, "instrument":"BTC1"},"636.3":{"price":636.3,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},"637.1":{"price":637.1,"numberOfOrders":1,"totalQuantity":1, "instrument":"BTC1"}},
"sell":{"637":{"price":637,"numberOfOrders":0,"totalQuantity":0, "instrument":"BTC1"},"639":{"price":639,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},"636.4":{"price":636.4,"numberOfOrders":0,"totalQuantity":0, "instrument":"BTC1"},"638.4":{"price":638.4,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},"636.5":{"price":636.5,"numberOfOrders":0,"totalQuantity":0, "instrument":"BTC1"},"638.5":{"price":638.5,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},"636.6":{"price":636.6,"numberOfOrders":0,"totalQuantity":0, "instrument":"BTC1"},"638.6":{"price":638.6,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},"636.7":{"price":636.7,"numberOfOrders":0,"totalQuantity":0, "instrument":"BTC1"},"638.7":{"price":638.7,"numberOfOrders":1,"totalQuantity":4, "instrument":"BTC1"},"636.8":{"price":636.8,"numberOfOrders":0,"totalQuantity":0, "instrument":"BTC1"},"638.8":{"price":638.8,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},"636.9":{"price":636.9,"numberOfOrders":0,"totalQuantity":0, "instrument":"BTC1"},"638.9":{"price":638.9,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"},"637.1":{"price":637.1,"numberOfOrders":0,"totalQuantity":0, "instrument":"BTC1"},"639.1":{"price":639.1,"numberOfOrders":1,"totalQuantity":5, "instrument":"BTC1"}},"bid":637.1,"ask":637.2
}

readonly

Whenever exchange enters and exits maintenance mode.

{"readonly":true}

OR

{"readonly":false}

priceband

The current trading band and index price used by coinpit. Trades occur only inside the band with very few exceptions. Stops outside the band are not triggered.

{"price":636.8,"lastProvider":"bitstamp","used":2, "providers":{"gemini":{"price":638.4,"time":1476337867242},"okcoin":{"price":633.5,"time":1476309721150,"expired":true},"bitfinex":{"price":638.03,"time":1476309783712,"expired":true},"coinbase":{"price":634.46,"time":1476309824389,"expired":true},"bitstamp":{"price":635.3,"time":1476337961938}} ,"max":638.8,"min":634.8, "instrument":"BTC1"}

ntp

Unix timestamp on the server. This may be used to adjust for clock skew on clients with inaccurate clocks. This may be used to ensure nonce accuracy.

{"client":1476336962443,"server":1476336962542}