diff --git a/package.json b/package.json index cd0d011..41b0640 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "babel-node": "babel-node server/server.js", "nodemon": "nodemon --exec npm run babel-node", "start": "node .", - "dev": "NODE_ENV=development DB_HOST=localhost npm run nodemon", + "dev": "DEBUG=gaby-api* NODE_ENV=development DB_HOST=localhost npm run nodemon", "ci-test": "NODE_ENV=test npm test -- --no-color", "test": "node scripts/test.js", "posttest": "npm run lint && nsp check", diff --git a/server/exchanges/.tern-port b/server/exchanges/.tern-port new file mode 100644 index 0000000..027e141 --- /dev/null +++ b/server/exchanges/.tern-port @@ -0,0 +1 @@ +40087 \ No newline at end of file diff --git a/server/exchanges/bittrex.js b/server/exchanges/bittrex.js new file mode 100644 index 0000000..f8493a9 --- /dev/null +++ b/server/exchanges/bittrex.js @@ -0,0 +1,29 @@ +import bittrex from 'node-bittrex-api' +import debug from 'debug' + +module.exports = class BittrexExchange { + constructor (bitrexOpts) { + this.bittrexOps = bitrexOpts + bittrex.options(bitrexOpts) + } + + getBalances (cb) { + bittrex.getbalances(function (data, err) { + if (err) { + cb(err) + } + + cb(null, data.result) + }) + } + + getOrders (cb) { + bittrex.getorderhistory({}, function (data, err) { + if (err) { + cb(err) + } + + return cb(null, data) + }) + } +} diff --git a/server/model-config.json b/server/model-config.json index 83fe975..c8cba64 100644 --- a/server/model-config.json +++ b/server/model-config.json @@ -33,5 +33,9 @@ "balance": { "dataSource": null, "public": true + }, + "order": { + "dataSource": null, + "public": true } } diff --git a/server/models/balance.js b/server/models/balance.js index 24413a2..bce2d94 100644 --- a/server/models/balance.js +++ b/server/models/balance.js @@ -1,11 +1,11 @@ -import bittrex from 'node-bittrex-api' +import BittrexExchange from '../exchanges/bittrex' module.exports = function (Balance) { Balance.getBalances = (cb) => { - const bittrexOpts = Balance.app.get('bittrex') - bittrex.options(bittrexOpts) + const bitrexOpts = Balance.app.get('bittrex') + const exchange = new BittrexExchange(bitrexOpts) - bittrex.getbalances(function (data, err) { + exchange.getBalances((err, data) => { if (err) { cb(err) } diff --git a/server/models/order.js b/server/models/order.js new file mode 100644 index 0000000..ae8e147 --- /dev/null +++ b/server/models/order.js @@ -0,0 +1,21 @@ +import BittrexExchange from '../exchanges/bittrex' + +module.exports = function (Order) { + Order.getOrders = (cb) => { + const bitrexOpts = Order.app.get('bittrex') + const exchange = new BittrexExchange(bitrexOpts) + + exchange.getOrders((err, data) => { + if (err) { + cb(err) + } + + cb(null, data) + }) + } + + Order.remoteMethod('getOrders', { + http: { verb: 'get', path: '/' }, + returns: {type: 'array', root: true} + }) +} diff --git a/server/models/order.json b/server/models/order.json new file mode 100644 index 0000000..116e08f --- /dev/null +++ b/server/models/order.json @@ -0,0 +1,14 @@ +{ + "name": "order", + "plural": "orders", + "base": "Model", + "idInjection": true, + "options": { + "validateUpsert": true + }, + "properties": {}, + "validations": [], + "relations": {}, + "acls": [], + "methods": {} +}