0.0.2 • Published 9 years ago
bitcoinfees-insight v0.0.2
node-bitcoinfees-insight
bitcoinfees from insight
install
npm i bitcoinfees-insightUsage
recommended
- code
var bitcoinfees = require('bitcoinfees-insight');
bitcoinfees.FeesApi.recommended().then(function(res){
console.log(res)
})- result
{ "fastestFee": 40, "halfHourFee": 20, "hourFee": 10 }- mapping estimatefee
"fastestFee": Math.round(nbBlocks=2 * 1.05)
"halfHourFee": Math.round(nbBlocks=2)
"hourFee": Math.round(nbBlocks=3)HTTP Error Handling
simple error control
bitcoinfees.FeesApi.recommended().catch(function(e){
console.log(e.message)
})technical error control
var errors = require('bitcoinfees-insight/errors')
bitcoinfees.FeesApi.recommended()
.catch(errors.StatusCodeError, function (reason) {
// HTTP STATUS ERROR(404 or 500, 502, etc...)
console.log("HTTP StatusCodeError " + reason.statusCode, "HTTP", reason.statusCode)
})
.catch(errors.RequestError, function (reason) {
// REQUEST ERROR(SYSTEMCALL, TIMEOUT)
console.log(reason.message, "SYSCALL", reason.error.code)
})
.catch(function(e){
// OTHER ERROR
console.log(e.message)
})VALUE Error Handling
var bitcoinfees = require('bitcoinfees-insight');
var assert = require('assert');
var clamp = function(value, min, max){
return Math.min(Math.max(min, value), max)
}
bitcoinfees.FeesApi.recommended().then(function(res){
assert(res.hourFee > 0);
return clamp(res.hourFee, 20, 200) // The API obstacle leads to loss
})Change Insight URL
var bitcoinfees = require('bitcoinfees-insight');
bitcoinfees.Constant.API_BASE_URL = "https://www.localbitcoinschain.com/api";
bitcoinfees.FeesApi.recommended()memo
It is better to store it in the database when using it on the server

