cryptobot-types 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +2 -0
- package/README.md +2 -0
- package/dist/indicators.js +2 -0
- package/dist/mongodb.js +2 -0
- package/dist/okx.js +15 -0
- package/dist/orderHelper.js +2 -0
- package/dist/strategy.js +2 -0
- package/dist/trading.js +2 -0
- package/package.json +16 -0
- package/tsconfig.json +13 -0
- package/types/index.d.ts +6 -0
- package/types/indicators.d.ts +50 -0
- package/types/mongodb.d.ts +42 -0
- package/types/okx.d.ts +160 -0
- package/types/orderHelper.d.ts +41 -0
- package/types/strategy.d.ts +5 -0
- package/types/trading.d.ts +87 -0
package/.gitattributes
ADDED
package/README.md
ADDED
package/dist/mongodb.js
ADDED
package/dist/okx.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isOrderUpdateEvent = exports.isPositionUpdateEvent = exports.isTickerUpdateEvent = void 0;
|
|
4
|
+
const isTickerUpdateEvent = (event) => {
|
|
5
|
+
return event.arg.channel === "tickers";
|
|
6
|
+
};
|
|
7
|
+
exports.isTickerUpdateEvent = isTickerUpdateEvent;
|
|
8
|
+
const isPositionUpdateEvent = (event) => {
|
|
9
|
+
return event.arg.channel === "positions";
|
|
10
|
+
};
|
|
11
|
+
exports.isPositionUpdateEvent = isPositionUpdateEvent;
|
|
12
|
+
const isOrderUpdateEvent = (event) => {
|
|
13
|
+
return event.arg.channel === "orders";
|
|
14
|
+
};
|
|
15
|
+
exports.isOrderUpdateEvent = isOrderUpdateEvent;
|
package/dist/strategy.js
ADDED
package/dist/trading.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cryptobot-types",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "types/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc -b"
|
|
9
|
+
},
|
|
10
|
+
"author": "",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@types/node": "^20.8.0",
|
|
14
|
+
"okx-api": "^1.1.3"
|
|
15
|
+
}
|
|
16
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es6",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"outDir": "dist",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true
|
|
10
|
+
},
|
|
11
|
+
"include": ["types/**/*"],
|
|
12
|
+
"exclude": ["node_modules", "**/*.spec.ts"]
|
|
13
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Candle } from './mongodb'
|
|
2
|
+
|
|
3
|
+
export interface Indicators {
|
|
4
|
+
granularity: number
|
|
5
|
+
ema_8: number
|
|
6
|
+
ema_13: number
|
|
7
|
+
ema_21: number
|
|
8
|
+
ema_55: number
|
|
9
|
+
bollinger_bands: {
|
|
10
|
+
upper: number
|
|
11
|
+
middle: number
|
|
12
|
+
lower: number
|
|
13
|
+
}
|
|
14
|
+
MACD: {
|
|
15
|
+
macd: number
|
|
16
|
+
emaFast: number
|
|
17
|
+
emaSlow: number
|
|
18
|
+
signal: number
|
|
19
|
+
histogram: number
|
|
20
|
+
}
|
|
21
|
+
vol: number
|
|
22
|
+
RSI: number
|
|
23
|
+
ADX: { adx: number; pdi: number; mdi: number }
|
|
24
|
+
ATR: number
|
|
25
|
+
ATR_percent: number
|
|
26
|
+
candle: Candle
|
|
27
|
+
stochRSI: { k: number; d: number }
|
|
28
|
+
HA: {
|
|
29
|
+
o: number
|
|
30
|
+
c: number
|
|
31
|
+
h: number
|
|
32
|
+
l: number
|
|
33
|
+
}
|
|
34
|
+
CCI: number
|
|
35
|
+
ChaikinOS: number
|
|
36
|
+
ROC: number
|
|
37
|
+
PSAR: number
|
|
38
|
+
OBV: undefined | number
|
|
39
|
+
OBV_RSI: number
|
|
40
|
+
OBV_SMA: number
|
|
41
|
+
VWAP: undefined | number
|
|
42
|
+
VWAP_deviation: {
|
|
43
|
+
basis: number
|
|
44
|
+
upperDeviation2: number
|
|
45
|
+
upperDeviation3: number
|
|
46
|
+
lowerDeviation2: number
|
|
47
|
+
lowerDeviation3: number
|
|
48
|
+
}
|
|
49
|
+
avgCandleSize: number
|
|
50
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface GeneratedCandle {
|
|
2
|
+
open: string;
|
|
3
|
+
high: string;
|
|
4
|
+
low: string;
|
|
5
|
+
close: string;
|
|
6
|
+
volume: number;
|
|
7
|
+
start: Date;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface Candle {
|
|
11
|
+
open: number;
|
|
12
|
+
high: number;
|
|
13
|
+
low: number;
|
|
14
|
+
close: number;
|
|
15
|
+
volume: number;
|
|
16
|
+
start: Date;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface GetBacktestOptions {
|
|
20
|
+
_ids?: string[];
|
|
21
|
+
testedAfter?: string;
|
|
22
|
+
rule?: string;
|
|
23
|
+
minProfit?: number;
|
|
24
|
+
start?: {
|
|
25
|
+
$gt: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface TimeAndCloseCandle {
|
|
30
|
+
start: Date;
|
|
31
|
+
close: number;
|
|
32
|
+
volume: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface DatabaseType {
|
|
36
|
+
start: Date;
|
|
37
|
+
open: string;
|
|
38
|
+
high: string;
|
|
39
|
+
low: string;
|
|
40
|
+
close: string;
|
|
41
|
+
volume: string;
|
|
42
|
+
}
|
package/types/okx.d.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { WsDataEvent } from "okx-api";
|
|
2
|
+
|
|
3
|
+
export interface TickerUpdateData {
|
|
4
|
+
instType: string;
|
|
5
|
+
instId: string;
|
|
6
|
+
last: string;
|
|
7
|
+
lastSz: string;
|
|
8
|
+
askPx: string;
|
|
9
|
+
askSz: string;
|
|
10
|
+
bidPx: string;
|
|
11
|
+
bidSz: string;
|
|
12
|
+
open24h: string;
|
|
13
|
+
high24h: string;
|
|
14
|
+
low24h: string;
|
|
15
|
+
sodUtc0: string;
|
|
16
|
+
sodUtc8: string;
|
|
17
|
+
volCcy24h: string;
|
|
18
|
+
vol24h: string;
|
|
19
|
+
ts: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface PositionUpdateData {
|
|
23
|
+
adl: string;
|
|
24
|
+
availPos: string;
|
|
25
|
+
avgPx: string;
|
|
26
|
+
baseBal: string;
|
|
27
|
+
baseBorrowed: string;
|
|
28
|
+
baseInterest: string;
|
|
29
|
+
bizRefId: string;
|
|
30
|
+
bizRefType: string;
|
|
31
|
+
cTime: string;
|
|
32
|
+
ccy: string;
|
|
33
|
+
closeOrderAlgo: string[];
|
|
34
|
+
deltaBS: string;
|
|
35
|
+
deltaPA: string;
|
|
36
|
+
gammaBS: string;
|
|
37
|
+
gammaPA: string;
|
|
38
|
+
imr: string;
|
|
39
|
+
instId: string;
|
|
40
|
+
instType: string;
|
|
41
|
+
interest: string;
|
|
42
|
+
last: string;
|
|
43
|
+
lever: string;
|
|
44
|
+
liab: string;
|
|
45
|
+
liabCcy: string;
|
|
46
|
+
liqPx: string;
|
|
47
|
+
margin: string;
|
|
48
|
+
markPx: string;
|
|
49
|
+
mgnMode: string;
|
|
50
|
+
mgnRatio: string;
|
|
51
|
+
mmr: string;
|
|
52
|
+
notionalUsd: string;
|
|
53
|
+
optVal: string;
|
|
54
|
+
pTime: string;
|
|
55
|
+
pendingCloseOrdLiabVal: string;
|
|
56
|
+
pos: string;
|
|
57
|
+
posCcy: string;
|
|
58
|
+
posId: string;
|
|
59
|
+
posSide: string;
|
|
60
|
+
quoteBal: string;
|
|
61
|
+
quoteBorrowed: string;
|
|
62
|
+
quoteInterest: string;
|
|
63
|
+
spotInUseAmt: string;
|
|
64
|
+
spotInUseCcy: string;
|
|
65
|
+
thetaBS: string;
|
|
66
|
+
thetaPA: string;
|
|
67
|
+
tradeId: string;
|
|
68
|
+
uTime: string;
|
|
69
|
+
upl: string;
|
|
70
|
+
uplRatio: string;
|
|
71
|
+
usdPx: string;
|
|
72
|
+
vegaBS: string;
|
|
73
|
+
vegaPA: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface OrderUpdateData {
|
|
77
|
+
instType: string;
|
|
78
|
+
instId: string;
|
|
79
|
+
tgtCcy: string;
|
|
80
|
+
ccy: string;
|
|
81
|
+
ordId: string;
|
|
82
|
+
clOrdId: string;
|
|
83
|
+
tag: string;
|
|
84
|
+
px: string;
|
|
85
|
+
sz: string;
|
|
86
|
+
notionalUsd: string;
|
|
87
|
+
ordType: string;
|
|
88
|
+
side: string;
|
|
89
|
+
posSide: string;
|
|
90
|
+
tdMode: string;
|
|
91
|
+
fillPx: string;
|
|
92
|
+
tradeId: string;
|
|
93
|
+
fillSz: string;
|
|
94
|
+
fillFee: string;
|
|
95
|
+
fillFeeCcy: string;
|
|
96
|
+
execType: string;
|
|
97
|
+
accFillSize: string;
|
|
98
|
+
fillNotionalUsd: string;
|
|
99
|
+
avgPx: string;
|
|
100
|
+
state: string;
|
|
101
|
+
lever: string;
|
|
102
|
+
tpTriggerPx: string;
|
|
103
|
+
tpTriggerPxType: string;
|
|
104
|
+
tpOrdPx: string;
|
|
105
|
+
slTriggerPx: string;
|
|
106
|
+
slTriggerPxType: string;
|
|
107
|
+
slOrdPx: string;
|
|
108
|
+
feeCcy: string;
|
|
109
|
+
fee: string;
|
|
110
|
+
rebateCcy: string;
|
|
111
|
+
rebate: string;
|
|
112
|
+
pnl: string;
|
|
113
|
+
source: string;
|
|
114
|
+
cancelSource: string;
|
|
115
|
+
amendSource: string;
|
|
116
|
+
category: string;
|
|
117
|
+
uTIme: string;
|
|
118
|
+
cTime: string;
|
|
119
|
+
reqId: string;
|
|
120
|
+
amendResult: string;
|
|
121
|
+
reduceOnly: string;
|
|
122
|
+
quickMgnType: string;
|
|
123
|
+
algoClOrdId: string;
|
|
124
|
+
algoId: string;
|
|
125
|
+
code: string;
|
|
126
|
+
msg: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export type TickerUpdateEvent = Omit<WsDataEvent, "data"> & {
|
|
130
|
+
data: TickerUpdateData[];
|
|
131
|
+
wsKey: string;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export type PositionUpdateEvent = Omit<WsDataEvent, "data"> & {
|
|
135
|
+
data: PositionUpdateData[];
|
|
136
|
+
wsKey: string;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export type OrderUpdateEvent = Omit<WsDataEvent, "data"> & {
|
|
140
|
+
data: OrderUpdateData[];
|
|
141
|
+
wsKey: string;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export const isTickerUpdateEvent = (
|
|
145
|
+
event: WsDataEvent
|
|
146
|
+
): event is TickerUpdateEvent => {
|
|
147
|
+
return event.arg.channel === "tickers";
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export const isPositionUpdateEvent = (
|
|
151
|
+
event: WsDataEvent
|
|
152
|
+
): event is PositionUpdateEvent => {
|
|
153
|
+
return event.arg.channel === "positions";
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export const isOrderUpdateEvent = (
|
|
157
|
+
event: WsDataEvent
|
|
158
|
+
): event is OrderUpdateEvent => {
|
|
159
|
+
return event.arg.channel === "orders";
|
|
160
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
interface BasePosition {
|
|
2
|
+
symbol: string
|
|
3
|
+
type: 'long' | 'short'
|
|
4
|
+
ctSize: number
|
|
5
|
+
margin: number
|
|
6
|
+
leverage: number
|
|
7
|
+
avgEntryPrice: number
|
|
8
|
+
liquidationPrice: number
|
|
9
|
+
fee: number
|
|
10
|
+
orders: (Order | CloseOrder)[]
|
|
11
|
+
amountUSD: number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface Position extends BasePosition {
|
|
15
|
+
unrealizedPnlUSD: number
|
|
16
|
+
unrealizedPnlPcnt: number
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ClosedPosition extends BasePosition {
|
|
20
|
+
realizedPnlUSD: number
|
|
21
|
+
realizedPnlPcnt: number
|
|
22
|
+
identifier: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface BaseOrder {
|
|
26
|
+
ordId: string
|
|
27
|
+
avgPrice: number
|
|
28
|
+
fee: number
|
|
29
|
+
amountUSD: number
|
|
30
|
+
size: number
|
|
31
|
+
time: Date
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface Order extends BaseOrder {
|
|
35
|
+
action: 'open'
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface CloseOrder extends Pick<Order, Exclude<keyof Order, 'action'>> {
|
|
39
|
+
action: 'close'
|
|
40
|
+
bruttoPnlUSD: number
|
|
41
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export type Rule = {
|
|
2
|
+
long_entry: boolean[][];
|
|
3
|
+
long_exit: boolean[][];
|
|
4
|
+
short_entry: boolean[][];
|
|
5
|
+
short_exit: boolean[][];
|
|
6
|
+
noStrictVolume?: boolean;
|
|
7
|
+
saveProfits?: boolean;
|
|
8
|
+
isCorrelationTest?: boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type Exchanges = "binance" | "coinbase" | "dydx" | "kraken" | "okx";
|
|
12
|
+
|
|
13
|
+
export type EntryOrderTypes = "Long Entry" | "Short Entry";
|
|
14
|
+
type ExitOrderTypes = "Long Exit" | "Short Exit";
|
|
15
|
+
export type OrderTypes = EntryOrderTypes | ExitOrderTypes;
|
|
16
|
+
|
|
17
|
+
export interface BaseOrderObject {
|
|
18
|
+
timestamp: Date;
|
|
19
|
+
platform: Exchanges;
|
|
20
|
+
invest: number;
|
|
21
|
+
netInvest: number;
|
|
22
|
+
portfolio: number;
|
|
23
|
+
clOrdId?: string;
|
|
24
|
+
leverage?: number;
|
|
25
|
+
details: Record<string, unknown>;
|
|
26
|
+
spread?: number;
|
|
27
|
+
canExecuteOrder?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface EntryOrderObject extends BaseOrderObject {
|
|
31
|
+
price: number;
|
|
32
|
+
type: EntryOrderTypes;
|
|
33
|
+
fee: number;
|
|
34
|
+
holdDuration: number;
|
|
35
|
+
//trading
|
|
36
|
+
positionSize?: number;
|
|
37
|
+
netPositionSize?: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ExitOrderObject extends Omit<EntryOrderObject, "type"> {
|
|
41
|
+
type: ExitOrderTypes;
|
|
42
|
+
priceChangePercent: number;
|
|
43
|
+
netProfitInPercent: number;
|
|
44
|
+
netProfit: number;
|
|
45
|
+
profit: number;
|
|
46
|
+
highestPrice?: number;
|
|
47
|
+
lowestPrice?: number;
|
|
48
|
+
isLiquidated: boolean;
|
|
49
|
+
//timeInLoss: number;
|
|
50
|
+
//timeInLossInPercent: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type OrderObject = EntryOrderObject | ExitOrderObject;
|
|
54
|
+
|
|
55
|
+
export interface BaseBacktestOptions {
|
|
56
|
+
successRate: number;
|
|
57
|
+
timestamp: Date;
|
|
58
|
+
startCapital: number;
|
|
59
|
+
trades: OrderObject[];
|
|
60
|
+
netProfit: string;
|
|
61
|
+
netProfitInPercent: number;
|
|
62
|
+
avgHoldDuration: number;
|
|
63
|
+
profitInMonth: {
|
|
64
|
+
profit: number;
|
|
65
|
+
netProfit: number;
|
|
66
|
+
netProfitInPercent: number;
|
|
67
|
+
executedOrders: number;
|
|
68
|
+
key: string | number;
|
|
69
|
+
}[];
|
|
70
|
+
gotLiquidated: boolean;
|
|
71
|
+
shortLongRatio: string;
|
|
72
|
+
executedOrders: number;
|
|
73
|
+
lineOfBestFit: number[];
|
|
74
|
+
//avgTimeInLoss: number;
|
|
75
|
+
//avgTimeInLossInPercent: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface BacktestingResult extends BaseBacktestOptions {
|
|
79
|
+
strategyName: string;
|
|
80
|
+
exchange: Exchanges;
|
|
81
|
+
symbol: string;
|
|
82
|
+
start: Date;
|
|
83
|
+
end: Date;
|
|
84
|
+
leverage: number;
|
|
85
|
+
hodlProfitInPercent: number;
|
|
86
|
+
tradesCount: number;
|
|
87
|
+
}
|