Skip to content

Commit 64f669c

Browse files
committed
Major updates and fixes
1 parent fb1fa6d commit 64f669c

25 files changed

+38195
-589
lines changed

libs/api.js

Lines changed: 1585 additions & 8 deletions
Large diffs are not rendered by default.

libs/apiBittrex.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var request = require('request');
22
var nonce = require('nonce');
3+
var PoolLogger = require('./logUtil.js');
34

45
module.exports = function() {
56
'use strict';
@@ -8,12 +9,13 @@ module.exports = function() {
89

910
// Constants
1011
var version = '0.1.0',
11-
PUBLIC_API_URL = 'https://bittrex.com/api/v1/public',
12+
PUBLIC_API_URL = 'https://api.bittrex.com/api/v1.1/public',
1213
PRIVATE_API_URL = 'https://bittrex.com/api/v1/market',
1314
USER_AGENT = 'nomp/node-open-mining-portal'
1415

1516
// Constructor
1617
function Bittrex(key, secret){
18+
console.log('bittrex called...')
1719
// Generate headers signed by this user's key and secret.
1820
// The secret is encapsulated and never exposed
1921
this._getPrivateHeaders = function(parameters){

libs/apiInterfaces.js

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/**
2+
* Cryptonote Node.JS Pool
3+
* https://github.com/dvandal/cryptonote-nodejs-pool
4+
*
5+
* Handle communications to APIs
6+
**/
7+
8+
// Load required modules
9+
var http = require('http');
10+
var https = require('https');
11+
12+
function jsonHttpRequest (host, port, data, callback, path) {
13+
path = path || '/json_rpc';
14+
callback = callback || function () {};
15+
var options = {
16+
hostname: host,
17+
port: port,
18+
path: path,
19+
method: data ? 'POST' : 'GET',
20+
headers: {
21+
'Content-Length': data.length,
22+
'Content-Type': 'application/json',
23+
'Accept': 'application/json'
24+
}
25+
};
26+
var req = (port === 443 ? https : http)
27+
.request(options, function (res) {
28+
var replyData = '';
29+
res.setEncoding('utf8');
30+
res.on('data', function (chunk) {
31+
replyData += chunk;
32+
});
33+
res.on('end', function () {
34+
var replyJson;
35+
try {
36+
replyJson = replyData ? JSON.parse(replyData) : {};
37+
} catch (e) {
38+
callback(e, {});
39+
return;
40+
}
41+
callback(null, replyJson);
42+
});
43+
});
44+
45+
req.on('error', function (e) {
46+
callback(e, {});
47+
});
48+
req.end(data);
49+
}
50+
51+
/**
52+
* Send RPC request
53+
**/
54+
function rpc (host, port, method, params, callback) {
55+
var data = JSON.stringify({
56+
id: "0",
57+
jsonrpc: "2.0",
58+
method: method,
59+
params: params
60+
});
61+
jsonHttpRequest(host, port, data, function (error, replyJson) {
62+
if (error) {
63+
callback(error, {});
64+
return;
65+
}
66+
callback(replyJson.error, replyJson.result);
67+
});
68+
}
69+
70+
/**
71+
* Send RPC requests in batch mode
72+
**/
73+
function batchRpc (host, port, array, callback) {
74+
var rpcArray = [];
75+
for (var i = 0; i < array.length; i++) {
76+
rpcArray.push({
77+
id: i.toString(),
78+
jsonrpc: "2.0",
79+
method: array[i][0],
80+
params: array[i][1]
81+
});
82+
}
83+
var data = JSON.stringify(rpcArray);
84+
jsonHttpRequest(host, port, data, callback);
85+
}
86+
87+
/**
88+
* Send RPC request to pool API
89+
**/
90+
function poolRpc (host, port, path, callback) {
91+
jsonHttpRequest(host, port, '', callback, path);
92+
}
93+
94+
/**
95+
* Exports API interfaces functions
96+
**/
97+
module.exports = function (daemonConfig, walletConfig, poolApiConfig) {
98+
return {
99+
batchRpcDaemon: function (batchArray, callback) {
100+
batchRpc(daemonConfig.host, daemonConfig.port, batchArray, callback);
101+
},
102+
rpcDaemon: function (method, params, callback, serverConfig) {
103+
if (serverConfig) {
104+
rpc(serverConfig.host, serverConfig.port, method, params, callback);
105+
} else {
106+
rpc(daemonConfig.host, daemonConfig.port, method, params, callback);
107+
}
108+
},
109+
rpcWallet: function (method, params, callback) {
110+
rpc(walletConfig.host, walletConfig.port, method, params, callback);
111+
},
112+
pool: function (path, callback) {
113+
var bindIp = config.api.bindIp ? config.api.bindIp : "0.0.0.0";
114+
var poolApi = (bindIp !== "0.0.0.0" ? poolApiConfig.bindIp : "127.0.0.1");
115+
poolRpc(poolApi, poolApiConfig.port, path, callback);
116+
},
117+
jsonHttpRequest: jsonHttpRequest
118+
}
119+
};

libs/apiPoloniex.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = function() {
1414

1515
// Constructor
1616
function Poloniex(key, secret) {
17+
console.log('Polinex called...')
1718
// Generate headers signed by this user's key and secret.
1819
// The secret is encapsulated and never exposed
1920
this._getPrivateHeaders = function(parameters) {

libs/apiTradeOgre.js

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
var request = require('request');
2+
var nonce = require('nonce');
3+
require('dotenv').config();
4+
const key = process.env.tradeOgre_api_key
5+
const secret = process.env.tradeOgre_api_secret
6+
7+
8+
9+
10+
11+
console.log('tradeOrge called..1.'+key+secret)
12+
module.exports = function() {
13+
'use strict';
14+
// tradeOgre(key,secret);
15+
// Module dependencies
16+
17+
// Constants
18+
var version = '0.1.0',
19+
PUBLIC_API_URL = 'https://tradeogre.com/api/v1',
20+
PRIVATE_API_URL = 'https://api.tradeOgre.com/v2/market',
21+
USER_AGENT = 'nomp/node-open-mining-portal'
22+
23+
// Constructor
24+
function tradeOgre(key, secret) {
25+
console.log('tradeOrge called..2.'+key+' ' +secret)
26+
// Generate headers signed by this user's key and secret.
27+
// The secret is encapsulated and never exposed
28+
this._getPrivateHeaders = function(parameters) {
29+
var paramString, signature;
30+
31+
if (!key || !secret) {
32+
throw 'tradeOgre: Error. API key and secret required';
33+
}
34+
35+
// Sort parameters alphabetically and convert to `arg1=foo&arg2=bar`
36+
paramString = Object.keys(parameters).sort().map(function(param) {
37+
return encodeURIComponent(param) + '=' + encodeURIComponent(parameters[param]);
38+
}).join('&');
39+
40+
signature = crypto.createHmac('sha512', secret).update(paramString).digest('hex');
41+
42+
return {
43+
Key: key,
44+
Sign: signature
45+
};
46+
};
47+
}
48+
49+
// If a site uses non-trusted SSL certificates, set this value to false
50+
tradeOgre.STRICT_SSL = true;
51+
52+
// Helper methods
53+
function joinCurrencies(currencyA, currencyB) {
54+
return currencyA + '-' + currencyB;
55+
}
56+
57+
// Prototype
58+
tradeOgre.prototype = {
59+
constructor: tradeOgre,
60+
61+
// Make an API request
62+
_request: function(options, callback) {
63+
if (!('headers' in options)) {
64+
options.headers = {};
65+
}
66+
67+
options.headers['User-Agent'] = USER_AGENT;
68+
options.json = true;
69+
options.strictSSL = tradeOgre.STRICT_SSL;
70+
71+
request(options, function(err, response, body) {
72+
callback(err, body);
73+
});
74+
75+
return this;
76+
},
77+
78+
// Make a public API request
79+
_public: function(parameters, callback) {
80+
var options = {
81+
method: 'GET',
82+
url: PUBLIC_API_URL,
83+
qs: parameters
84+
};
85+
console.log('options,: '+options)
86+
return this._request(options, callback);
87+
},
88+
89+
// Make a private API request
90+
_private: function(parameters, callback) {
91+
var options;
92+
93+
parameters.nonce = nonce();
94+
options = {
95+
method: 'POST',
96+
url: PRIVATE_API_URL,
97+
form: parameters,
98+
headers: this._getPrivateHeaders(parameters)
99+
};
100+
101+
return this._request(options, callback);
102+
},
103+
104+
105+
/////
106+
107+
108+
// PUBLIC METHODS
109+
110+
getTicker: function(callback) {
111+
var options = {
112+
method: 'GET',
113+
url: PUBLIC_API_URL + '/markets',
114+
qs: null
115+
};
116+
117+
return this._request(options, callback);
118+
},
119+
120+
getBuyOrderBook: function(currencyA, currencyB, callback) {
121+
var options = {
122+
method: 'GET',
123+
url: PUBLIC_API_URL + '/orders/' + joinCurrencies(currencyA, currencyB),
124+
qs: null
125+
};
126+
127+
return this._request(options, callback);
128+
},
129+
130+
getOrderBook: function(currencyA, currencyB, callback) {
131+
var parameters = {
132+
command: 'returnOrderBook',
133+
currencyPair: joinCurrencies(currencyA, currencyB)
134+
};
135+
136+
return this._public(parameters, callback);
137+
},
138+
139+
getTradeHistory: function(currencyA, currencyB, callback) {
140+
var parameters = {
141+
command: 'returnTradeHistory',
142+
currencyPair: joinCurrencies(currencyA, currencyB)
143+
};
144+
145+
return this._public(parameters, callback);
146+
},
147+
148+
149+
/////
150+
151+
152+
// PRIVATE METHODS
153+
154+
myBalances: function(callback) {
155+
var parameters = {
156+
command: 'returnBalances'
157+
};
158+
159+
return this._private(parameters, callback);
160+
},
161+
162+
myOpenOrders: function(currencyA, currencyB, callback) {
163+
var parameters = {
164+
command: 'returnOpenOrders',
165+
currencyPair: joinCurrencies(currencyA, currencyB)
166+
};
167+
168+
return this._private(parameters, callback);
169+
},
170+
171+
myTradeHistory: function(currencyA, currencyB, callback) {
172+
var parameters = {
173+
command: 'returnTradeHistory',
174+
currencyPair: joinCurrencies(currencyA, currencyB)
175+
};
176+
177+
return this._private(parameters, callback);
178+
},
179+
180+
buy: function(currencyA, currencyB, rate, amount, callback) {
181+
var parameters = {
182+
command: 'buy',
183+
currencyPair: joinCurrencies(currencyA, currencyB),
184+
rate: rate,
185+
amount: amount
186+
};
187+
188+
return this._private(parameters, callback);
189+
},
190+
191+
sell: function(currencyA, currencyB, rate, amount, callback) {
192+
var parameters = {
193+
command: 'sell',
194+
currencyPair: joinCurrencies(currencyA, currencyB),
195+
rate: rate,
196+
amount: amount
197+
};
198+
199+
return this._private(parameters, callback);
200+
},
201+
202+
cancelOrder: function(currencyA, currencyB, orderNumber, callback) {
203+
var parameters = {
204+
command: 'cancelOrder',
205+
currencyPair: joinCurrencies(currencyA, currencyB),
206+
orderNumber: orderNumber
207+
};
208+
209+
return this._private(parameters, callback);
210+
},
211+
212+
withdraw: function(currency, amount, address, callback) {
213+
var parameters = {
214+
command: 'withdraw',
215+
currency: currency,
216+
amount: amount,
217+
address: address
218+
};
219+
220+
return this._private(parameters, callback);
221+
}
222+
};
223+
224+
return tradeOgre;
225+
}();

0 commit comments

Comments
 (0)