{"size": 812, "ext": "js", "max_stars_repo_path": "packages/augur.js/src/trading/profit-loss/calculate-taker-pl.js", "max_stars_repo_name": "zackster/augur", "max_stars_repo_stars_event_min_datetime": "2015-05-01T17:22:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T06:55:39.000Z", "max_issues_repo_path": "packages/augur.js/src/trading/profit-loss/calculate-taker-pl.js", "max_issues_repo_name": "zackster/augur", "max_issues_repo_issues_event_min_datetime": "2015-05-02T20:38:33.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-15T18:39:08.000Z", "max_forks_repo_path": "packages/augur.js/src/trading/profit-loss/calculate-taker-pl.js", "max_forks_repo_name": "zackster/augur", "max_forks_repo_forks_event_min_datetime": "2015-05-10T06:00:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-22T06:55:30.000Z"}
{"max_stars_count": 148, "max_issues_count": 300, "max_forks_count": 44, "avg_line_length": 35.3043478261, "max_line_length": 152, "alphanum_fraction": 0.6982758621}
"use strict";

var longerPositionPL = require("./longer-position-pl");
var shorterPositionPL = require("./shorter-position-pl");

// Trades where user is the taker:
//  - buy orders: user loses cash, gets shares
//  - sell orders: user loses shares, gets cash
function calculateTakerPL(PL, type, price, shares) {

  // Buy order
  if (type === "buy") {
    // console.log('buy (taker):', PL.position.toFixed(), PL.meanOpenPrice.toFixed(), price.toFixed(), shares.toFixed(), JSON.stringify(PL.tradeQueue));
    return longerPositionPL(PL, shares, price);
  }

  // Sell order
  // console.log('sell (taker):', PL.position.toFixed(), PL.meanOpenPrice.toFixed(), price.toFixed(), shares.toFixed(), JSON.stringify(PL.tradeQueue));
  return shorterPositionPL(PL, shares, price);
}

module.exports = calculateTakerPL;
