Skip to content

Commit

Permalink
add keepalive option
Browse files Browse the repository at this point in the history
  • Loading branch information
you21979 committed Mar 13, 2017
1 parent 8db2218 commit 61b47fc
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 1 deletion.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------

Expand Down
29 changes: 29 additions & 0 deletions example/request_rate_keepalive.js
Original file line number Diff line number Diff line change
@@ -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")})
1 change: 1 addition & 0 deletions lib/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 1 addition & 0 deletions lib/private_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions lib/public_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Yuki Akiyama <you2197901 [at] gmail.com>",
"name": "zaif.jp",
"version": "0.1.12",
"version": "0.1.13",
"private": false,
"dependencies": {
"@you21979/simple-verify" : "0.0.x",
Expand Down

0 comments on commit 61b47fc

Please sign in to comment.