Skip to content

Commit

Permalink
fee currency, rate, cost
Browse files Browse the repository at this point in the history
  • Loading branch information
kroitor committed Sep 23, 2017
1 parent f954338 commit bb376e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
33 changes: 11 additions & 22 deletions ccxt.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,23 +773,16 @@ const Exchange = function (config) {
return this.createOrder (market, 'market', 'sell', amount, undefined, params)
}

this.calculateFeeRate = function (symbol, type, side, amount, price, fee = 'taker', params = {}) {
return {
'base': 0.0,
'quote': this.markets[symbol][fee],
};
this.calculateFeeRate = function (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) {
const market = this.markets[symbol]
return { 'currency': market['quote'], 'rate': market[takerOrMaker] }
}

this.calculateFee = function (symbol, type, side, amount, price, fee = 'taker', params = {}) {
const rate = this.calculateFeeRate (symbol, type, side, amount, price, fee, params);
return {
'rate': rate,
'cost': {
'base': amount * rate['base'],
'quote': amount * price * rate['quote'],
},
};
},
this.calculateFee = function (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) {
let fee = this.calculateFeeRate (symbol, type, side, amount, price, takerOrMaker, params)
fee['cost'] = amount * price * fee['rate']
return fee
}

this.iso8601 = timestamp => new Date (timestamp).toISOString ()
this.parse8601 = Date.parse
Expand Down Expand Up @@ -16340,14 +16333,10 @@ var poloniex = {
'funding': 0.0,
},

calculateFeeRate (symbol, type, side, amount, price, fee = 'taker', params = {}) {
let result = {
'base': 0.0,
'quote': 0.0,
};
calculateFeeRate (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) {
let key = (side == 'sell') ? 'quote' : 'base';
result[key] = this.markets[symbol][fee];
return result;
let market = this.markets[symbol];
return { 'currency': market[key], 'rate': market[takerOrMaker] };
},

async fetchMarkets () {
Expand Down
9 changes: 5 additions & 4 deletions test/test_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ describe ('ccxt base code', () => {
'markets': { 'FOO/BAR': market }
})

Object.keys (fees).forEach (fee => {
Object.keys (fees).forEach (takerOrMaker => {

const result = exchange.calculateFee (market['symbol'], 'limit', 'sell', amount, price, fee, {})
const result = exchange.calculateFee (market['symbol'], 'limit', 'sell', amount, price, takerOrMaker, {})

assert.deepEqual (result, {
'rate': { 'base': 0.0, 'quote': fees[fee], },
'cost': { 'base': 0.0, 'quote': fees[fee] * amount * price, },
'currency': 'BAR',
'rate': fees[takerOrMaker],
'cost': fees[takerOrMaker] * amount * price,
})
})
})
Expand Down

0 comments on commit bb376e7

Please sign in to comment.