Skip to content

Commit

Permalink
config fee using
Browse files Browse the repository at this point in the history
  • Loading branch information
julesGoullee authored and askmike committed Aug 20, 2017
1 parent 08edc4c commit 9901fc1
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions config/plugins/paperTrader.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
feeMaker = 0.25
feeTaker = 0.25
feeUsing = 'maker'
slippage = 0.05

[simulationBalance]
Expand Down
2 changes: 2 additions & 0 deletions docs/commandline/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ Go to the config and configure it like this:
// how much fee in % does each trade cost?
feeMaker: 0.5,
feeTaker: 0.6,
// Using taker or maker fee?
feeUsing: 'maker',
// how much slippage should Gekko assume per trade?
slippage: 0.1
}
Expand Down
11 changes: 5 additions & 6 deletions plugins/paperTrader/paperTrader.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ const watchConfig = config.watch;
const PaperTrader = function() {
_.bindAll(this);

this.feeMaker = 1 - (calcConfig.feeMaker + calcConfig.slippage) / 100;
this.feeTaker = 1 - (calcConfig.feeTaker + calcConfig.slippage) / 100;
this.fee = 1 - (calcConfig['fee' + calcConfig.feeUsing.charAt(0).toUpperCase() + calcConfig.feeUsing.slice(1)] + calcConfig.slippage) / 100;

this.currency = watchConfig.currency;
this.asset = watchConfig.asset;
Expand Down Expand Up @@ -53,9 +52,9 @@ PaperTrader.prototype.relayPortfolio = function() {
this.emit('portfolioUpdate', _.clone(this.portfolio));
}

PaperTrader.prototype.extractFee = function(amount, type) {
PaperTrader.prototype.extractFee = function(amount) {
amount *= 1e8;
amount *= type === 'maker' ? this.feeMaker : this.feeTaker;
amount *= this.fee;
amount = Math.floor(amount);
amount /= 1e8;
return amount;
Expand All @@ -76,15 +75,15 @@ PaperTrader.prototype.updatePosition = function(advice) {
// virtually trade all {currency} to {asset}
// at the current price (minus fees)
if(what === 'long') {
this.portfolio.asset += this.extractFee(this.portfolio.currency / price, 'taker');
this.portfolio.asset += this.extractFee(this.portfolio.currency / price);
this.portfolio.currency = 0;
this.trades++;
}

// virtually trade all {currency} to {asset}
// at the current price (minus fees)
else if(what === 'short') {
this.portfolio.currency += this.extractFee(this.portfolio.asset * price, 'maker');
this.portfolio.currency += this.extractFee(this.portfolio.asset * price);
this.portfolio.asset = 0;
this.trades++;
}
Expand Down
1 change: 1 addition & 0 deletions sample-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ config.paperTrader = {
// how much fee in % does each trade cost?
feeMaker: 0.15,
feeTaker: 0.25,
feeUsing: 'maker',
// how much slippage/spread should Gekko assume per trade?
slippage: 0.05,
}
Expand Down
1 change: 1 addition & 0 deletions test/test-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"feeMaker": 0.15,
"feeTaker": 0.25,
"feeUsing": "maker",
"slippage": 0.05
},
"pushover": {
Expand Down

0 comments on commit 9901fc1

Please sign in to comment.