node-cobinhood
v0.2.8
Published
nodejs cobinhood api client
Downloads
18
Readme
Node-Cobinhood
node-cobinhood is a nodejs api wrapper of cobinhood restful api and websocket. node-cobinhood provides an easier way to access cobinhood exchange.
Getting Started
You should get an api key of cobinhood first. Put your api key in one of example and try it!
Client Instance
With api key, you can create a client with following code.
const Client = require('node-cobinhood')
let client = new Client({ key: `your api key` })
Then you can access cobinhood exchange throgh RESTFUL API or Websocket.
Disable Websocket
If you don't want to connect ws, specify in constructor.
const Client = require('node-cobinhood')
let client = new Client({ key: `your api key`, disableWS: true })
Enums
- order side
- bid
- ask
- order type
- limit
- market
- limit_stop
- market_stop
- ledger type
- exchange
- margin
- funding
- candle timeframe
- 1m
- 5m
- 15m
- 30m
- 1h
- 3h
- 6h
- 12h
- 1D
- 7D
- 14D
- 1M
RESTFUL API
You can access cobinhood exchange with such client method below. RESTFUL API will returns a promise object.
- listOrders()
- listTradingPairs()
- listCurrencies()
- listOrderbookPrecisions(pair)
- pair: trading pair
- listFundingbookPrecisions(currency)
- currency: currency
- placeLimitOrder(pair, side, price, size, source)
- pair: trading pair
- side: "bid" or "ask"
- price: price, string or decimal object
- size: size, string or decimal object
- source: "exchange" or "margin"
- placeMarketOrder(pair, side, size, source)
- pair: trading pair
- side: "bid" or "ask"
- size: size, string or decimal object
- source: "exchange" or "margin"
- placeLimitStopOrder(pair, side, price, size, stopPrice, source)
- pair trading pair
- side: "bid" or "ask"
- price: price string or decimal object
- size: size, string or decimal object
- stopPrice: stop price, string or decimal object
- source: "exchange" or "margin"
- placeMarketStopOrder(pair, side, size, stopPrice, source)
- pair: trading pair
- side: "bid" or "ask"
- size: size, string or decimal object
- stopPrice: stop price, string or decimal object
- source: "exchange" or "margin"
- cancelOrder(id)
- id: order id
- modifyOrder(id, price, size)
- id: order id
- price: price, string or decimal object
- size: size, string or decimal object
- getOrder(id)
- id: order id
- getBalance()
- transferBalance(currency, from, to, amount)
- currency: currency
- from: balance ledger type, for example "exchange", "margin"
- to: balance ledger type, for example "exchange", "margin"
- amount: amount, string or decimal object
- getOrderbook(pair, precision, limit)
- pair: trading pair
- precision: trading pair support precision, for example new Decimal("1e-7") or "1E-7"
- limit: limits number of entries of asks/bids list, beginning from the best price for both sides
- listTrades(pair)
- pair: trading pair
- getTicker(pair)
- pair: trading pair
- getTimeframe(pair, start, end, timeframe)
- pair: trading pair
- start: start time, need Date object
- end: end time, need Date object
- timeframe: candle timeframe, for example "1h", "15m"
- getTradesHistory(pair, limit, page)
- pair: trading pair
- limit: limits number of trades per page
- page: pagination
- getTradesOfOrder(id)
- id: order id
- listPositions()
- getPosition(pair)
- pair: trading pair
- closePosition(pair)
- pair: trading pair
- claimPosition(pair, size)
- pair: trading pair
- size: size, must be positive, string or decimal object
- getFundingbook(currency, precision, limit)
- currency: currency
- precision: currency support precision, for example new Decimal("1e-7") or "1E-7"
- limit: limits number of entries of asks/bids list, beginning from the best price for both sides
- getLoanTicker(currency)
- currency: currency
- listFundings()
- getFunding(id)
- id: funding id
- placeLimitFunding(currency, side, interestRate, period, size)
- currency: currency
- side: "bid" or "ask"
- interestRate: daily interest rate(%), string or decimal object
- period: bid / ask days (2 ~ 30)
- size: size, string or decimal object
- cancelFunding(id)
- id: funding id
- listLoans()
- getLoan(id)
- id: loan id
- closeLoan(id)
- id: loan id
Websocket
Upon client created, websocket is connecting, so you should call client close if you don't need it. Client provides some websocket events. You can listen events to know the situation.
Events
- open
- When websocket connected, it will be fired.
- close
- When websocket closed, it will be fired.
- error
- When websocket error, it will be fired.
- reconnecting
- When websocket reconnecting, it will be fired.
- reconnected
- When websocket reconnected, it will be fired.
Subscribes
You can subscribe websocket update with such client method below. Subscription function will returns a promise object.
- subscribeOrder(fn)
- fn: callback function
- subscribeTicker(pair, fn)
- pair: trading pair, for example "COB-ETH"
- fn: callback function
- subscribePublicTrade(pair, fn)
- pair: trading pair, for example "COB-ETH"
- fn: callback function
- subscribeOrderbook(pair, precision, fn)
- pair: trading pair, for example "COB-ETH"
- precision: trading pair support precision, for example new Decimal("1e-7") or "1E-7"
- fn: callback function
- subscribeCandle(pair, timeframe, fn)
- pair: trading pair, for example "COB-ETH"
- timeframe: candle timeframe, for example "1h", "15m"
- fn: callback function
- subscribeFundingbook(currency, precision, fn)
- currency: currency, for example "USDT"
- precision: currency support precision, for example new Decimal("1e-7") or "1E-7"
- fn: callback function
- subscribeLoanTicker(currency, fn)
- currency: currency, for example "USDT"
- fn: callback function
- subscribePublicLoan(currency, fn)
- currency: currency, for example "USDT"
- fn: callback function
- subscribeAuthLoan(currency, fn)
- currency: currency, for example "USDT"
- fn: callback function
- subscribeFunding(fn)
- fn: callback function
Trading
You can also trade with websocket. The api is almost same with restful version but response is same with websocket update.
- placeLimitOrderWS(pair, side, price, size, source)
- pair: trading pair
- side: "bid" or "ask"
- price: price, string or decimal object
- size: size, string or decimal object
- source: "exchange" or "margin"
- placeMarketOrderWS(pair, side, size, source)
- pair: trading pair
- side: "bid" or "ask"
- size: size, string or decimal object
- source: "exchange" or "margin"
- placeLimitStopOrderWS(pair, side, price, size, stopPrice, source)
- pair trading pair
- side: "bid" or "ask"
- price: price string or decimal object
- size: size, string or decimal object
- stopPrice: stop price, string or decimal object
- source: "exchange" or "margin"
- placeMarketStopOrderWS(pair, side, size, stopPrice, source)
- pair: trading pair
- side: "bid" or "ask"
- size: size, string or decimal object
- stopPrice: stop price, string or decimal object
- source: "exchange" or "margin"
- cancelOrderWS(id)
- id: order id
- modifyOrderWS(id, price, size)
- id: order id
- price: price, string or decimal object
- size: size, string or decimal object