Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Commit

Permalink
Adding model order, refs #4
Browse files Browse the repository at this point in the history
  • Loading branch information
Genar Trias Ortiz committed Dec 5, 2017
1 parent 5c21008 commit 93a1c95
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions server/exchanges/.tern-port
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
40087
29 changes: 29 additions & 0 deletions server/exchanges/bittrex.js
Original file line number Diff line number Diff line change
@@ -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)
})
}
}
4 changes: 4 additions & 0 deletions server/model-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,9 @@
"balance": {
"dataSource": null,
"public": true
},
"order": {
"dataSource": null,
"public": true
}
}
8 changes: 4 additions & 4 deletions server/models/balance.js
Original file line number Diff line number Diff line change
@@ -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)
}
Expand Down
21 changes: 21 additions & 0 deletions server/models/order.js
Original file line number Diff line number Diff line change
@@ -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}
})
}
14 changes: 14 additions & 0 deletions server/models/order.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "order",
"plural": "orders",
"base": "Model",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}

0 comments on commit 93a1c95

Please sign in to comment.