-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb1fa6d
commit 64f669c
Showing
25 changed files
with
38,195 additions
and
589 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/** | ||
* Cryptonote Node.JS Pool | ||
* https://github.com/dvandal/cryptonote-nodejs-pool | ||
* | ||
* Handle communications to APIs | ||
**/ | ||
|
||
// Load required modules | ||
var http = require('http'); | ||
var https = require('https'); | ||
|
||
function jsonHttpRequest (host, port, data, callback, path) { | ||
path = path || '/json_rpc'; | ||
callback = callback || function () {}; | ||
var options = { | ||
hostname: host, | ||
port: port, | ||
path: path, | ||
method: data ? 'POST' : 'GET', | ||
headers: { | ||
'Content-Length': data.length, | ||
'Content-Type': 'application/json', | ||
'Accept': 'application/json' | ||
} | ||
}; | ||
var req = (port === 443 ? https : http) | ||
.request(options, function (res) { | ||
var replyData = ''; | ||
res.setEncoding('utf8'); | ||
res.on('data', function (chunk) { | ||
replyData += chunk; | ||
}); | ||
res.on('end', function () { | ||
var replyJson; | ||
try { | ||
replyJson = replyData ? JSON.parse(replyData) : {}; | ||
} catch (e) { | ||
callback(e, {}); | ||
return; | ||
} | ||
callback(null, replyJson); | ||
}); | ||
}); | ||
|
||
req.on('error', function (e) { | ||
callback(e, {}); | ||
}); | ||
req.end(data); | ||
} | ||
|
||
/** | ||
* Send RPC request | ||
**/ | ||
function rpc (host, port, method, params, callback) { | ||
var data = JSON.stringify({ | ||
id: "0", | ||
jsonrpc: "2.0", | ||
method: method, | ||
params: params | ||
}); | ||
jsonHttpRequest(host, port, data, function (error, replyJson) { | ||
if (error) { | ||
callback(error, {}); | ||
return; | ||
} | ||
callback(replyJson.error, replyJson.result); | ||
}); | ||
} | ||
|
||
/** | ||
* Send RPC requests in batch mode | ||
**/ | ||
function batchRpc (host, port, array, callback) { | ||
var rpcArray = []; | ||
for (var i = 0; i < array.length; i++) { | ||
rpcArray.push({ | ||
id: i.toString(), | ||
jsonrpc: "2.0", | ||
method: array[i][0], | ||
params: array[i][1] | ||
}); | ||
} | ||
var data = JSON.stringify(rpcArray); | ||
jsonHttpRequest(host, port, data, callback); | ||
} | ||
|
||
/** | ||
* Send RPC request to pool API | ||
**/ | ||
function poolRpc (host, port, path, callback) { | ||
jsonHttpRequest(host, port, '', callback, path); | ||
} | ||
|
||
/** | ||
* Exports API interfaces functions | ||
**/ | ||
module.exports = function (daemonConfig, walletConfig, poolApiConfig) { | ||
return { | ||
batchRpcDaemon: function (batchArray, callback) { | ||
batchRpc(daemonConfig.host, daemonConfig.port, batchArray, callback); | ||
}, | ||
rpcDaemon: function (method, params, callback, serverConfig) { | ||
if (serverConfig) { | ||
rpc(serverConfig.host, serverConfig.port, method, params, callback); | ||
} else { | ||
rpc(daemonConfig.host, daemonConfig.port, method, params, callback); | ||
} | ||
}, | ||
rpcWallet: function (method, params, callback) { | ||
rpc(walletConfig.host, walletConfig.port, method, params, callback); | ||
}, | ||
pool: function (path, callback) { | ||
var bindIp = config.api.bindIp ? config.api.bindIp : "0.0.0.0"; | ||
var poolApi = (bindIp !== "0.0.0.0" ? poolApiConfig.bindIp : "127.0.0.1"); | ||
poolRpc(poolApi, poolApiConfig.port, path, callback); | ||
}, | ||
jsonHttpRequest: jsonHttpRequest | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,225 @@ | ||
var request = require('request'); | ||
var nonce = require('nonce'); | ||
require('dotenv').config(); | ||
const key = process.env.tradeOgre_api_key | ||
const secret = process.env.tradeOgre_api_secret | ||
|
||
|
||
|
||
|
||
|
||
console.log('tradeOrge called..1.'+key+secret) | ||
module.exports = function() { | ||
'use strict'; | ||
// tradeOgre(key,secret); | ||
// Module dependencies | ||
|
||
// Constants | ||
var version = '0.1.0', | ||
PUBLIC_API_URL = 'https://tradeogre.com/api/v1', | ||
PRIVATE_API_URL = 'https://api.tradeOgre.com/v2/market', | ||
USER_AGENT = 'nomp/node-open-mining-portal' | ||
|
||
// Constructor | ||
function tradeOgre(key, secret) { | ||
console.log('tradeOrge called..2.'+key+' ' +secret) | ||
// Generate headers signed by this user's key and secret. | ||
// The secret is encapsulated and never exposed | ||
this._getPrivateHeaders = function(parameters) { | ||
var paramString, signature; | ||
|
||
if (!key || !secret) { | ||
throw 'tradeOgre: Error. API key and secret required'; | ||
} | ||
|
||
// Sort parameters alphabetically and convert to `arg1=foo&arg2=bar` | ||
paramString = Object.keys(parameters).sort().map(function(param) { | ||
return encodeURIComponent(param) + '=' + encodeURIComponent(parameters[param]); | ||
}).join('&'); | ||
|
||
signature = crypto.createHmac('sha512', secret).update(paramString).digest('hex'); | ||
|
||
return { | ||
Key: key, | ||
Sign: signature | ||
}; | ||
}; | ||
} | ||
|
||
// If a site uses non-trusted SSL certificates, set this value to false | ||
tradeOgre.STRICT_SSL = true; | ||
|
||
// Helper methods | ||
function joinCurrencies(currencyA, currencyB) { | ||
return currencyA + '-' + currencyB; | ||
} | ||
|
||
// Prototype | ||
tradeOgre.prototype = { | ||
constructor: tradeOgre, | ||
|
||
// Make an API request | ||
_request: function(options, callback) { | ||
if (!('headers' in options)) { | ||
options.headers = {}; | ||
} | ||
|
||
options.headers['User-Agent'] = USER_AGENT; | ||
options.json = true; | ||
options.strictSSL = tradeOgre.STRICT_SSL; | ||
|
||
request(options, function(err, response, body) { | ||
callback(err, body); | ||
}); | ||
|
||
return this; | ||
}, | ||
|
||
// Make a public API request | ||
_public: function(parameters, callback) { | ||
var options = { | ||
method: 'GET', | ||
url: PUBLIC_API_URL, | ||
qs: parameters | ||
}; | ||
console.log('options,: '+options) | ||
return this._request(options, callback); | ||
}, | ||
|
||
// Make a private API request | ||
_private: function(parameters, callback) { | ||
var options; | ||
|
||
parameters.nonce = nonce(); | ||
options = { | ||
method: 'POST', | ||
url: PRIVATE_API_URL, | ||
form: parameters, | ||
headers: this._getPrivateHeaders(parameters) | ||
}; | ||
|
||
return this._request(options, callback); | ||
}, | ||
|
||
|
||
///// | ||
|
||
|
||
// PUBLIC METHODS | ||
|
||
getTicker: function(callback) { | ||
var options = { | ||
method: 'GET', | ||
url: PUBLIC_API_URL + '/markets', | ||
qs: null | ||
}; | ||
|
||
return this._request(options, callback); | ||
}, | ||
|
||
getBuyOrderBook: function(currencyA, currencyB, callback) { | ||
var options = { | ||
method: 'GET', | ||
url: PUBLIC_API_URL + '/orders/' + joinCurrencies(currencyA, currencyB), | ||
qs: null | ||
}; | ||
|
||
return this._request(options, callback); | ||
}, | ||
|
||
getOrderBook: function(currencyA, currencyB, callback) { | ||
var parameters = { | ||
command: 'returnOrderBook', | ||
currencyPair: joinCurrencies(currencyA, currencyB) | ||
}; | ||
|
||
return this._public(parameters, callback); | ||
}, | ||
|
||
getTradeHistory: function(currencyA, currencyB, callback) { | ||
var parameters = { | ||
command: 'returnTradeHistory', | ||
currencyPair: joinCurrencies(currencyA, currencyB) | ||
}; | ||
|
||
return this._public(parameters, callback); | ||
}, | ||
|
||
|
||
///// | ||
|
||
|
||
// PRIVATE METHODS | ||
|
||
myBalances: function(callback) { | ||
var parameters = { | ||
command: 'returnBalances' | ||
}; | ||
|
||
return this._private(parameters, callback); | ||
}, | ||
|
||
myOpenOrders: function(currencyA, currencyB, callback) { | ||
var parameters = { | ||
command: 'returnOpenOrders', | ||
currencyPair: joinCurrencies(currencyA, currencyB) | ||
}; | ||
|
||
return this._private(parameters, callback); | ||
}, | ||
|
||
myTradeHistory: function(currencyA, currencyB, callback) { | ||
var parameters = { | ||
command: 'returnTradeHistory', | ||
currencyPair: joinCurrencies(currencyA, currencyB) | ||
}; | ||
|
||
return this._private(parameters, callback); | ||
}, | ||
|
||
buy: function(currencyA, currencyB, rate, amount, callback) { | ||
var parameters = { | ||
command: 'buy', | ||
currencyPair: joinCurrencies(currencyA, currencyB), | ||
rate: rate, | ||
amount: amount | ||
}; | ||
|
||
return this._private(parameters, callback); | ||
}, | ||
|
||
sell: function(currencyA, currencyB, rate, amount, callback) { | ||
var parameters = { | ||
command: 'sell', | ||
currencyPair: joinCurrencies(currencyA, currencyB), | ||
rate: rate, | ||
amount: amount | ||
}; | ||
|
||
return this._private(parameters, callback); | ||
}, | ||
|
||
cancelOrder: function(currencyA, currencyB, orderNumber, callback) { | ||
var parameters = { | ||
command: 'cancelOrder', | ||
currencyPair: joinCurrencies(currencyA, currencyB), | ||
orderNumber: orderNumber | ||
}; | ||
|
||
return this._private(parameters, callback); | ||
}, | ||
|
||
withdraw: function(currency, amount, address, callback) { | ||
var parameters = { | ||
command: 'withdraw', | ||
currency: currency, | ||
amount: amount, | ||
address: address | ||
}; | ||
|
||
return this._private(parameters, callback); | ||
} | ||
}; | ||
|
||
return tradeOgre; | ||
}(); |
Oops, something went wrong.