Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

48
LINES

< > BotCompany Repo | #1036119 // TradingPosition

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (9905L/55K).

sclass TradingPosition {
  settable S coin;
  settable bool isLong;
  settable int leverage;
  
  // How much we originally invest in USDT
  settable double marginInvestment;
  
  // How much USDT margin we end up with
  settable double margin;
  
  // How much crypto we bet on
  settable double amount;
  
  // Is position still open?
  settable bool ongoing;
  
  settable double openingPrice;
  
  // closing or current price
  settable double closingPrice;
  
  settable double openingFees;
  settable double closingFees;
  
  // Actual price movement during position
  settable TradingCandle candle;
  
  // Signal we acted on (optional)
  settable TradingSignal afterSignal;
  
  double openingFeePercentage() {
    ret doubleRatio(openingFees, margin*leverage);
  }
  
  double priceDifference() {
    ret closingPrice-openingPrice;
  }
  
  double leveragedPriceDifference() {
    ret priceDifference()*leverage;
  }
  
  // PNL = Profit & Loss
  double expectedPNL() {
    ret (isLong() ? 1 : -1)*leveragedPriceDifference()*amount;
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): elmgxqgtpvxh, mqqgnosmbjvj, wnsclhtenguj

No comments. add comment

Snippet ID: #1036119
Snippet name: TradingPosition
Eternal ID of this version: #1036119/4
Text MD5: e92c68ab5083b204028655c81e4bf867
Transpilation MD5: 0e062d3648d6be69186f795b61fddb59
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-09-22 18:32:03
Source code size: 1094 bytes / 48 lines
Pitched / IR pitched: No / No
Views / Downloads: 9 / 36
Version history: 3 change(s)
Referenced in: [show references]