Migrate plugins to lib directory
This commit is contained in:
parent
09b29bba56
commit
e7ab8223c2
27 changed files with 869 additions and 858 deletions
44
lib/plugins/exchange/bitstamp/bitstamp.js
Normal file
44
lib/plugins/exchange/bitstamp/bitstamp.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
const common = require('../common/bitstamp')
|
||||
|
||||
const SATOSHI_SHIFT = 8
|
||||
|
||||
function buy (account, cryptoAtoms, fiatCode, cryptoCode) {
|
||||
return trade('buy', account, cryptoAtoms, fiatCode, cryptoCode)
|
||||
}
|
||||
|
||||
function sell (account, cryptoAtoms, fiatCode, cryptoCode) {
|
||||
return trade('sell', account, cryptoAtoms, fiatCode, cryptoCode)
|
||||
}
|
||||
|
||||
function handleErrors (data) {
|
||||
if (!data.reason || !data.reason.__all__) return data
|
||||
|
||||
const err = new Error(data.reason.__all__[0])
|
||||
|
||||
if (data.reason.__all__[0].indexOf('Minimum order size is') === 0) {
|
||||
err.name = 'orderTooSmall'
|
||||
}
|
||||
|
||||
throw err
|
||||
}
|
||||
|
||||
function trade (type, account, cryptoAtoms, fiatCode, cryptoCode) {
|
||||
try {
|
||||
const market = common.buildMarket(fiatCode, cryptoCode)
|
||||
const options = {amount: cryptoAtoms.shift(-SATOSHI_SHIFT).toFixed(8)}
|
||||
|
||||
return common.authRequest(account, '/' + type + '/market/' + market, options)
|
||||
.catch(e => {
|
||||
if (e.response) handleErrors(e.response.data)
|
||||
throw e
|
||||
})
|
||||
.then(handleErrors)
|
||||
} catch (e) {
|
||||
return Promise.reject(e)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
buy,
|
||||
sell
|
||||
}
|
||||
27
lib/plugins/exchange/bitstamp/schema.json
Normal file
27
lib/plugins/exchange/bitstamp/schema.json
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"code": "bitstamp",
|
||||
"display": "Bitstamp",
|
||||
"fields": [
|
||||
{
|
||||
"code": "clientId",
|
||||
"display": "Client ID",
|
||||
"fieldType": "string",
|
||||
"required": true,
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"code": "key",
|
||||
"display": "API key",
|
||||
"fieldType": "string",
|
||||
"required": true,
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"code": "secret",
|
||||
"display": "API secret",
|
||||
"fieldType": "password",
|
||||
"required": true,
|
||||
"value": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue