From 61b47fcdb07082778343655b754ebaaae99636a3 Mon Sep 17 00:00:00 2001 From: you21979 Date: Mon, 13 Mar 2017 15:56:12 +0900 Subject: [PATCH] add keepalive option --- README.md | 22 ++++++++++++++++++++++ example/request_rate_keepalive.js | 29 +++++++++++++++++++++++++++++ lib/constant.js | 1 + lib/private_api.js | 1 + lib/public_api.js | 1 + package.json | 2 +- 6 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 example/request_rate_keepalive.js diff --git a/README.md b/README.md index 6049dda..79fb42e 100644 --- a/README.md +++ b/README.md @@ -275,6 +275,28 @@ api.getInfo() }) ``` +Tuning Network Parameter +------------------------ + +* Attention! Global Parameter +* Setting - KeepAlive Connection +* Setting - Timeout Second + +``` +var zaif = require('zaif.jp'); + +var appInitialize = function(){ + zaif.Constant.OPT_KEEPALIVE = true; + zaif.Constant.OPT_TIMEOUT_SEC = 3; +} + +var main = function(){ + appInitialize(); +} + +main() +``` + License ------- diff --git a/example/request_rate_keepalive.js b/example/request_rate_keepalive.js new file mode 100644 index 0000000..90e4fe6 --- /dev/null +++ b/example/request_rate_keepalive.js @@ -0,0 +1,29 @@ +var zaif = require('..'); +var api = zaif.PublicApi; +var Promise = require('bluebird'); + +zaif.Constant.OPT_KEEPALIVE = true; + +var n = 0; +var r = function(v){ + console.log(++n); + return v; +} + +var w = [ + api.lastPrice('btc_jpy').then(r), + api.lastPrice('btc_jpy').then(r), + api.lastPrice('btc_jpy').then(r), + api.lastPrice('btc_jpy').then(r), + api.lastPrice('btc_jpy').then(r), + api.lastPrice('btc_jpy').then(r), + api.lastPrice('btc_jpy').then(r), + api.lastPrice('btc_jpy').then(r), + api.lastPrice('btc_jpy').then(r), + api.lastPrice('btc_jpy').then(r), + api.lastPrice('btc_jpy').then(r), + api.lastPrice('btc_jpy').then(r), + api.lastPrice('btc_jpy').then(r) +]; + +Promise.all(w).then(function(){console.log("OK")}) diff --git a/lib/constant.js b/lib/constant.js index 1fd24b0..731f816 100644 --- a/lib/constant.js +++ b/lib/constant.js @@ -4,3 +4,4 @@ exports.OPT_WEBSOCKET_URL = 'wss://ws.zaif.jp:8888'; exports.OPT_LIMIT_SEC = 0.02; exports.OPT_LIMIT_HOST = 'https://api.zaif.jp'; exports.OPT_TIMEOUT_SEC = 5; +exports.OPT_KEEPALIVE = false; diff --git a/lib/private_api.js b/lib/private_api.js index 0d48b4d..72a494a 100644 --- a/lib/private_api.js +++ b/lib/private_api.js @@ -22,6 +22,7 @@ var createPostOption = function(url, api_key, secret_key, user_agent, nonce, tim return { url: url, method: 'POST', + forever: constant.OPT_KEEPALIVE, form: post, headers: createHeader(api_key, secret_key, user_agent, post), timeout: timeout, diff --git a/lib/public_api.js b/lib/public_api.js index d8edd27..f423d6d 100644 --- a/lib/public_api.js +++ b/lib/public_api.js @@ -14,6 +14,7 @@ var createGetOption = function(url){ return { url: url, method: 'GET', + forever: constant.OPT_KEEPALIVE, timeout: Math.floor(constant.OPT_TIMEOUT_SEC * 1000), transform2xxOnly : true, transform: function(body){ diff --git a/package.json b/package.json index 5a1538d..6542b8e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "author": "Yuki Akiyama ", "name": "zaif.jp", - "version": "0.1.12", + "version": "0.1.13", "private": false, "dependencies": { "@you21979/simple-verify" : "0.0.x",