Libraryless. Click here for Pure Java version (11467L/65K).
1 | interface IFuturesMarket { |
2 | // all open/close orders are market right now (not limit) |
3 | |
4 | sclass OpenOrCloseOrder { |
5 | // input parameters |
6 | |
7 | settable S clientOrderID; // optional |
8 | |
9 | settable HoldSide holdSide; |
10 | settable double cryptoAmount; |
11 | |
12 | // Limit order if set. Otherwise market order. |
13 | // Limit orders are good-until-cancel. |
14 | // (unimplemented) |
15 | settable double limitPrice = Double.NaN; |
16 | |
17 | // output parameters |
18 | |
19 | // order ID returned by platform |
20 | settable S orderID; |
21 | } |
22 | |
23 | macro ExtendingOpenOrCloseOrder { |
24 | public selfType clientOrderID(S clientOrderID) { super.clientOrderID(clientOrderID); this; } |
25 | public selfType holdSide(HoldSide holdSide) { super.holdSide(holdSide); this; } |
26 | public selfType cryptoAmount(double cryptoAmount) { super.cryptoAmount(cryptoAmount); this; } |
27 | public selfType limitPrice(double limitPrice) { super.limitPrice(limitPrice); this; } |
28 | } |
29 | |
30 | sclass OpenOrder extends OpenOrCloseOrder { |
31 | ExtendingOpenOrCloseOrder |
32 | settable double leverage = 1; |
33 | settable bool isCross; |
34 | |
35 | settable double takeProfitPrice = Double.NaN; |
36 | settable double stopLossPrice = Double.NaN; |
37 | } |
38 | |
39 | sclass CloseOrder extends OpenOrCloseOrder { |
40 | ExtendingOpenOrCloseOrder |
41 | } |
42 | |
43 | // throws exception if order failed |
44 | void openPosition(OpenOrder order); |
45 | |
46 | // throws exception if order failed |
47 | void closePosition(CloseOrder order); |
48 | |
49 | sclass SwappableImplementation is IFuturesMarket { |
50 | public swappable void openPosition(OpenOrder order) {} |
51 | public swappable void closePosition(CloseOrder order) {} |
52 | public swappable double drift() { unimplemented(); } |
53 | public FutureCoinParameters getCoinParameters() { unimplemented(); } |
54 | } |
55 | |
56 | // Get current drift (sum of longs+shorts in crypto units) |
57 | double drift(); |
58 | |
59 | FutureCoinParameters getCoinParameters(); |
60 | } |
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: | 1146 / 1270 |
Version history: | 18 change(s) |
Referenced in: | [show references] |