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

60
LINES

< > BotCompany Repo | #1036219 // IFuturesMarket - interface to a single market (e.g. ETHUSDT)

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

Libraryless. Click here for Pure Java version (11467L/65K).

interface IFuturesMarket {
  // all open/close orders are market right now (not limit)
  
  sclass OpenOrCloseOrder {
    // input parameters
    
    settable S clientOrderID; // optional
    
    settable HoldSide holdSide;
    settable double cryptoAmount;
    
    // Limit order if set. Otherwise market order.
    // Limit orders are good-until-cancel.
    // (unimplemented)
    settable double limitPrice = Double.NaN;
    
    // output parameters
    
    // order ID returned by platform
    settable S orderID;
  }
  
  macro ExtendingOpenOrCloseOrder {
    public selfType clientOrderID(S clientOrderID) { super.clientOrderID(clientOrderID); this; }
    public selfType holdSide(HoldSide holdSide) { super.holdSide(holdSide); this; }
    public selfType cryptoAmount(double cryptoAmount) { super.cryptoAmount(cryptoAmount); this; }
    public selfType limitPrice(double limitPrice) { super.limitPrice(limitPrice); this; }
  }
  
  sclass OpenOrder extends OpenOrCloseOrder {
    ExtendingOpenOrCloseOrder
    settable double leverage = 1;
    settable bool isCross;
    
    settable double takeProfitPrice = Double.NaN;
    settable double stopLossPrice = Double.NaN;
  }
  
  sclass CloseOrder extends OpenOrCloseOrder {
    ExtendingOpenOrCloseOrder
  }
  
  // throws exception if order failed
  void openPosition(OpenOrder order);
  
  // throws exception if order failed
  void closePosition(CloseOrder order);
  
  sclass SwappableImplementation is IFuturesMarket {
    public swappable void openPosition(OpenOrder order) {}
    public swappable void closePosition(CloseOrder order) {}
    public swappable double drift() { unimplemented(); }
    public FutureCoinParameters getCoinParameters() { unimplemented(); }
  }
  
  // Get current drift (sum of longs+shorts in crypto units)
  double drift();
  
  FutureCoinParameters getCoinParameters();
}

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1036219
Snippet name: IFuturesMarket - interface to a single market (e.g. ETHUSDT)
Eternal ID of this version: #1036219/19
Text MD5: 5253d999c245cee68a342456c0b8277f
Transpilation MD5: 706bd90dfa4548d8eaf3fff68ef1488e
Author: stefan
Category: javax / trading
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2024-01-04 22:59:49
Source code size: 1929 bytes / 60 lines
Pitched / IR pitched: No / No
Views / Downloads: 1177 / 1309
Version history: 18 change(s)
Referenced in: [show references]