@gbozee/ultimate 0.0.2-150 → 0.0.2-151
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/dist/index.cjs +1331 -1758
- package/dist/index.d.ts +187 -158
- package/dist/index.js +1331 -1758
- package/dist/mcp-server.cjs +1330 -1757
- package/dist/mcp-server.js +1330 -1757
- package/package.json +1 -1
package/dist/mcp-server.js
CHANGED
|
@@ -16579,8 +16579,8 @@ var require_combined_stream = __commonJS((exports, module) => {
|
|
|
16579
16579
|
stream2.pipe(this, { end: false });
|
|
16580
16580
|
return;
|
|
16581
16581
|
}
|
|
16582
|
-
var
|
|
16583
|
-
this.write(
|
|
16582
|
+
var value = stream2;
|
|
16583
|
+
this.write(value);
|
|
16584
16584
|
this._getNext();
|
|
16585
16585
|
};
|
|
16586
16586
|
CombinedStream.prototype._handleErrors = function(stream2) {
|
|
@@ -25793,8 +25793,8 @@ var require_get = __commonJS((exports, module) => {
|
|
|
25793
25793
|
var desc = !!hasProtoAccessor && gOPD && gOPD(Object.prototype, "__proto__");
|
|
25794
25794
|
var $Object = Object;
|
|
25795
25795
|
var $getPrototypeOf = $Object.getPrototypeOf;
|
|
25796
|
-
module.exports = desc && typeof desc.get === "function" ? callBind([desc.get]) : typeof $getPrototypeOf === "function" ? function getDunder(
|
|
25797
|
-
return $getPrototypeOf(
|
|
25796
|
+
module.exports = desc && typeof desc.get === "function" ? callBind([desc.get]) : typeof $getPrototypeOf === "function" ? function getDunder(value) {
|
|
25797
|
+
return $getPrototypeOf(value == null ? value : $Object(value));
|
|
25798
25798
|
} : false;
|
|
25799
25799
|
});
|
|
25800
25800
|
|
|
@@ -25966,26 +25966,26 @@ var require_get_intrinsic = __commonJS((exports, module) => {
|
|
|
25966
25966
|
}
|
|
25967
25967
|
var errorProto;
|
|
25968
25968
|
var doEval = function doEval(name2) {
|
|
25969
|
-
var
|
|
25969
|
+
var value;
|
|
25970
25970
|
if (name2 === "%AsyncFunction%") {
|
|
25971
|
-
|
|
25971
|
+
value = getEvalledConstructor("async function () {}");
|
|
25972
25972
|
} else if (name2 === "%GeneratorFunction%") {
|
|
25973
|
-
|
|
25973
|
+
value = getEvalledConstructor("function* () {}");
|
|
25974
25974
|
} else if (name2 === "%AsyncGeneratorFunction%") {
|
|
25975
|
-
|
|
25975
|
+
value = getEvalledConstructor("async function* () {}");
|
|
25976
25976
|
} else if (name2 === "%AsyncGenerator%") {
|
|
25977
25977
|
var fn = doEval("%AsyncGeneratorFunction%");
|
|
25978
25978
|
if (fn) {
|
|
25979
|
-
|
|
25979
|
+
value = fn.prototype;
|
|
25980
25980
|
}
|
|
25981
25981
|
} else if (name2 === "%AsyncIteratorPrototype%") {
|
|
25982
25982
|
var gen = doEval("%AsyncGenerator%");
|
|
25983
25983
|
if (gen && getProto) {
|
|
25984
|
-
|
|
25984
|
+
value = getProto(gen.prototype);
|
|
25985
25985
|
}
|
|
25986
25986
|
}
|
|
25987
|
-
INTRINSICS[name2] =
|
|
25988
|
-
return
|
|
25987
|
+
INTRINSICS[name2] = value;
|
|
25988
|
+
return value;
|
|
25989
25989
|
};
|
|
25990
25990
|
var LEGACY_ALIASES = {
|
|
25991
25991
|
__proto__: null,
|
|
@@ -26072,17 +26072,17 @@ var require_get_intrinsic = __commonJS((exports, module) => {
|
|
|
26072
26072
|
intrinsicName = "%" + alias[0] + "%";
|
|
26073
26073
|
}
|
|
26074
26074
|
if (hasOwn(INTRINSICS, intrinsicName)) {
|
|
26075
|
-
var
|
|
26076
|
-
if (
|
|
26077
|
-
|
|
26075
|
+
var value = INTRINSICS[intrinsicName];
|
|
26076
|
+
if (value === needsEval) {
|
|
26077
|
+
value = doEval(intrinsicName);
|
|
26078
26078
|
}
|
|
26079
|
-
if (typeof
|
|
26079
|
+
if (typeof value === "undefined" && !allowMissing) {
|
|
26080
26080
|
throw new $TypeError("intrinsic " + name2 + " exists, but is not available. Please file an issue!");
|
|
26081
26081
|
}
|
|
26082
26082
|
return {
|
|
26083
26083
|
alias,
|
|
26084
26084
|
name: intrinsicName,
|
|
26085
|
-
value
|
|
26085
|
+
value
|
|
26086
26086
|
};
|
|
26087
26087
|
}
|
|
26088
26088
|
throw new $SyntaxError("intrinsic " + name2 + " does not exist!");
|
|
@@ -26101,7 +26101,7 @@ var require_get_intrinsic = __commonJS((exports, module) => {
|
|
|
26101
26101
|
var intrinsicBaseName = parts.length > 0 ? parts[0] : "";
|
|
26102
26102
|
var intrinsic = getBaseIntrinsic("%" + intrinsicBaseName + "%", allowMissing);
|
|
26103
26103
|
var intrinsicRealName = intrinsic.name;
|
|
26104
|
-
var
|
|
26104
|
+
var value = intrinsic.value;
|
|
26105
26105
|
var skipFurtherCaching = false;
|
|
26106
26106
|
var alias = intrinsic.alias;
|
|
26107
26107
|
if (alias) {
|
|
@@ -26121,32 +26121,32 @@ var require_get_intrinsic = __commonJS((exports, module) => {
|
|
|
26121
26121
|
intrinsicBaseName += "." + part;
|
|
26122
26122
|
intrinsicRealName = "%" + intrinsicBaseName + "%";
|
|
26123
26123
|
if (hasOwn(INTRINSICS, intrinsicRealName)) {
|
|
26124
|
-
|
|
26125
|
-
} else if (
|
|
26126
|
-
if (!(part in
|
|
26124
|
+
value = INTRINSICS[intrinsicRealName];
|
|
26125
|
+
} else if (value != null) {
|
|
26126
|
+
if (!(part in value)) {
|
|
26127
26127
|
if (!allowMissing) {
|
|
26128
26128
|
throw new $TypeError("base intrinsic for " + name2 + " exists, but the property is not available.");
|
|
26129
26129
|
}
|
|
26130
26130
|
return;
|
|
26131
26131
|
}
|
|
26132
26132
|
if ($gOPD && i2 + 1 >= parts.length) {
|
|
26133
|
-
var desc = $gOPD(
|
|
26133
|
+
var desc = $gOPD(value, part);
|
|
26134
26134
|
isOwn = !!desc;
|
|
26135
26135
|
if (isOwn && "get" in desc && !("originalValue" in desc.get)) {
|
|
26136
|
-
|
|
26136
|
+
value = desc.get;
|
|
26137
26137
|
} else {
|
|
26138
|
-
|
|
26138
|
+
value = value[part];
|
|
26139
26139
|
}
|
|
26140
26140
|
} else {
|
|
26141
|
-
isOwn = hasOwn(
|
|
26142
|
-
|
|
26141
|
+
isOwn = hasOwn(value, part);
|
|
26142
|
+
value = value[part];
|
|
26143
26143
|
}
|
|
26144
26144
|
if (isOwn && !skipFurtherCaching) {
|
|
26145
|
-
INTRINSICS[intrinsicRealName] =
|
|
26145
|
+
INTRINSICS[intrinsicRealName] = value;
|
|
26146
26146
|
}
|
|
26147
26147
|
}
|
|
26148
26148
|
}
|
|
26149
|
-
return
|
|
26149
|
+
return value;
|
|
26150
26150
|
};
|
|
26151
26151
|
});
|
|
26152
26152
|
|
|
@@ -26166,7 +26166,7 @@ var require_es_set_tostringtag = __commonJS((exports, module) => {
|
|
|
26166
26166
|
var hasOwn = require_hasown();
|
|
26167
26167
|
var $TypeError = require_type();
|
|
26168
26168
|
var toStringTag = hasToStringTag ? Symbol.toStringTag : null;
|
|
26169
|
-
module.exports = function setToStringTag(object2,
|
|
26169
|
+
module.exports = function setToStringTag(object2, value) {
|
|
26170
26170
|
var overrideIfSet = arguments.length > 2 && !!arguments[2] && arguments[2].force;
|
|
26171
26171
|
var nonConfigurable = arguments.length > 2 && !!arguments[2] && arguments[2].nonConfigurable;
|
|
26172
26172
|
if (typeof overrideIfSet !== "undefined" && typeof overrideIfSet !== "boolean" || typeof nonConfigurable !== "undefined" && typeof nonConfigurable !== "boolean") {
|
|
@@ -26177,11 +26177,11 @@ var require_es_set_tostringtag = __commonJS((exports, module) => {
|
|
|
26177
26177
|
$defineProperty(object2, toStringTag, {
|
|
26178
26178
|
configurable: !nonConfigurable,
|
|
26179
26179
|
enumerable: false,
|
|
26180
|
-
value
|
|
26180
|
+
value,
|
|
26181
26181
|
writable: false
|
|
26182
26182
|
});
|
|
26183
26183
|
} else {
|
|
26184
|
-
object2[toStringTag] =
|
|
26184
|
+
object2[toStringTag] = value;
|
|
26185
26185
|
}
|
|
26186
26186
|
}
|
|
26187
26187
|
};
|
|
@@ -26229,77 +26229,77 @@ var require_form_data = __commonJS((exports, module) => {
|
|
|
26229
26229
|
FormData2.LINE_BREAK = `\r
|
|
26230
26230
|
`;
|
|
26231
26231
|
FormData2.DEFAULT_CONTENT_TYPE = "application/octet-stream";
|
|
26232
|
-
FormData2.prototype.append = function(field,
|
|
26232
|
+
FormData2.prototype.append = function(field, value, options) {
|
|
26233
26233
|
options = options || {};
|
|
26234
26234
|
if (typeof options == "string") {
|
|
26235
26235
|
options = { filename: options };
|
|
26236
26236
|
}
|
|
26237
26237
|
var append = CombinedStream.prototype.append.bind(this);
|
|
26238
|
-
if (typeof
|
|
26239
|
-
|
|
26238
|
+
if (typeof value == "number") {
|
|
26239
|
+
value = "" + value;
|
|
26240
26240
|
}
|
|
26241
|
-
if (Array.isArray(
|
|
26241
|
+
if (Array.isArray(value)) {
|
|
26242
26242
|
this._error(new Error("Arrays are not supported."));
|
|
26243
26243
|
return;
|
|
26244
26244
|
}
|
|
26245
|
-
var header = this._multiPartHeader(field,
|
|
26245
|
+
var header = this._multiPartHeader(field, value, options);
|
|
26246
26246
|
var footer = this._multiPartFooter();
|
|
26247
26247
|
append(header);
|
|
26248
|
-
append(
|
|
26248
|
+
append(value);
|
|
26249
26249
|
append(footer);
|
|
26250
|
-
this._trackLength(header,
|
|
26250
|
+
this._trackLength(header, value, options);
|
|
26251
26251
|
};
|
|
26252
|
-
FormData2.prototype._trackLength = function(header,
|
|
26252
|
+
FormData2.prototype._trackLength = function(header, value, options) {
|
|
26253
26253
|
var valueLength = 0;
|
|
26254
26254
|
if (options.knownLength != null) {
|
|
26255
26255
|
valueLength += +options.knownLength;
|
|
26256
|
-
} else if (Buffer.isBuffer(
|
|
26257
|
-
valueLength =
|
|
26258
|
-
} else if (typeof
|
|
26259
|
-
valueLength = Buffer.byteLength(
|
|
26256
|
+
} else if (Buffer.isBuffer(value)) {
|
|
26257
|
+
valueLength = value.length;
|
|
26258
|
+
} else if (typeof value === "string") {
|
|
26259
|
+
valueLength = Buffer.byteLength(value);
|
|
26260
26260
|
}
|
|
26261
26261
|
this._valueLength += valueLength;
|
|
26262
26262
|
this._overheadLength += Buffer.byteLength(header) + FormData2.LINE_BREAK.length;
|
|
26263
|
-
if (!
|
|
26263
|
+
if (!value || !value.path && !(value.readable && Object.prototype.hasOwnProperty.call(value, "httpVersion")) && !(value instanceof Stream)) {
|
|
26264
26264
|
return;
|
|
26265
26265
|
}
|
|
26266
26266
|
if (!options.knownLength) {
|
|
26267
|
-
this._valuesToMeasure.push(
|
|
26267
|
+
this._valuesToMeasure.push(value);
|
|
26268
26268
|
}
|
|
26269
26269
|
};
|
|
26270
|
-
FormData2.prototype._lengthRetriever = function(
|
|
26271
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
26272
|
-
if (
|
|
26273
|
-
callback(null,
|
|
26270
|
+
FormData2.prototype._lengthRetriever = function(value, callback) {
|
|
26271
|
+
if (Object.prototype.hasOwnProperty.call(value, "fd")) {
|
|
26272
|
+
if (value.end != null && value.end != Infinity && value.start != null) {
|
|
26273
|
+
callback(null, value.end + 1 - (value.start ? value.start : 0));
|
|
26274
26274
|
} else {
|
|
26275
|
-
fs.stat(
|
|
26275
|
+
fs.stat(value.path, function(err, stat) {
|
|
26276
26276
|
var fileSize;
|
|
26277
26277
|
if (err) {
|
|
26278
26278
|
callback(err);
|
|
26279
26279
|
return;
|
|
26280
26280
|
}
|
|
26281
|
-
fileSize = stat.size - (
|
|
26281
|
+
fileSize = stat.size - (value.start ? value.start : 0);
|
|
26282
26282
|
callback(null, fileSize);
|
|
26283
26283
|
});
|
|
26284
26284
|
}
|
|
26285
|
-
} else if (Object.prototype.hasOwnProperty.call(
|
|
26286
|
-
callback(null, +
|
|
26287
|
-
} else if (Object.prototype.hasOwnProperty.call(
|
|
26288
|
-
|
|
26289
|
-
|
|
26285
|
+
} else if (Object.prototype.hasOwnProperty.call(value, "httpVersion")) {
|
|
26286
|
+
callback(null, +value.headers["content-length"]);
|
|
26287
|
+
} else if (Object.prototype.hasOwnProperty.call(value, "httpModule")) {
|
|
26288
|
+
value.on("response", function(response) {
|
|
26289
|
+
value.pause();
|
|
26290
26290
|
callback(null, +response.headers["content-length"]);
|
|
26291
26291
|
});
|
|
26292
|
-
|
|
26292
|
+
value.resume();
|
|
26293
26293
|
} else {
|
|
26294
26294
|
callback("Unknown stream");
|
|
26295
26295
|
}
|
|
26296
26296
|
};
|
|
26297
|
-
FormData2.prototype._multiPartHeader = function(field,
|
|
26297
|
+
FormData2.prototype._multiPartHeader = function(field, value, options) {
|
|
26298
26298
|
if (typeof options.header == "string") {
|
|
26299
26299
|
return options.header;
|
|
26300
26300
|
}
|
|
26301
|
-
var contentDisposition = this._getContentDisposition(
|
|
26302
|
-
var contentType = this._getContentType(
|
|
26301
|
+
var contentDisposition = this._getContentDisposition(value, options);
|
|
26302
|
+
var contentType = this._getContentType(value, options);
|
|
26303
26303
|
var contents = "";
|
|
26304
26304
|
var headers = {
|
|
26305
26305
|
"Content-Disposition": ["form-data", 'name="' + field + '"'].concat(contentDisposition || []),
|
|
@@ -26325,35 +26325,35 @@ var require_form_data = __commonJS((exports, module) => {
|
|
|
26325
26325
|
}
|
|
26326
26326
|
return "--" + this.getBoundary() + FormData2.LINE_BREAK + contents + FormData2.LINE_BREAK;
|
|
26327
26327
|
};
|
|
26328
|
-
FormData2.prototype._getContentDisposition = function(
|
|
26328
|
+
FormData2.prototype._getContentDisposition = function(value, options) {
|
|
26329
26329
|
var filename, contentDisposition;
|
|
26330
26330
|
if (typeof options.filepath === "string") {
|
|
26331
26331
|
filename = path.normalize(options.filepath).replace(/\\/g, "/");
|
|
26332
|
-
} else if (options.filename ||
|
|
26333
|
-
filename = path.basename(options.filename ||
|
|
26334
|
-
} else if (
|
|
26335
|
-
filename = path.basename(
|
|
26332
|
+
} else if (options.filename || value.name || value.path) {
|
|
26333
|
+
filename = path.basename(options.filename || value.name || value.path);
|
|
26334
|
+
} else if (value.readable && Object.prototype.hasOwnProperty.call(value, "httpVersion")) {
|
|
26335
|
+
filename = path.basename(value.client._httpMessage.path || "");
|
|
26336
26336
|
}
|
|
26337
26337
|
if (filename) {
|
|
26338
26338
|
contentDisposition = 'filename="' + filename + '"';
|
|
26339
26339
|
}
|
|
26340
26340
|
return contentDisposition;
|
|
26341
26341
|
};
|
|
26342
|
-
FormData2.prototype._getContentType = function(
|
|
26342
|
+
FormData2.prototype._getContentType = function(value, options) {
|
|
26343
26343
|
var contentType = options.contentType;
|
|
26344
|
-
if (!contentType &&
|
|
26345
|
-
contentType = mime.lookup(
|
|
26344
|
+
if (!contentType && value.name) {
|
|
26345
|
+
contentType = mime.lookup(value.name);
|
|
26346
26346
|
}
|
|
26347
|
-
if (!contentType &&
|
|
26348
|
-
contentType = mime.lookup(
|
|
26347
|
+
if (!contentType && value.path) {
|
|
26348
|
+
contentType = mime.lookup(value.path);
|
|
26349
26349
|
}
|
|
26350
|
-
if (!contentType &&
|
|
26351
|
-
contentType =
|
|
26350
|
+
if (!contentType && value.readable && Object.prototype.hasOwnProperty.call(value, "httpVersion")) {
|
|
26351
|
+
contentType = value.headers["content-type"];
|
|
26352
26352
|
}
|
|
26353
26353
|
if (!contentType && (options.filepath || options.filename)) {
|
|
26354
26354
|
contentType = mime.lookup(options.filepath || options.filename);
|
|
26355
26355
|
}
|
|
26356
|
-
if (!contentType && typeof
|
|
26356
|
+
if (!contentType && typeof value == "object") {
|
|
26357
26357
|
contentType = FormData2.DEFAULT_CONTENT_TYPE;
|
|
26358
26358
|
}
|
|
26359
26359
|
return contentType;
|
|
@@ -26726,9 +26726,9 @@ var require_follow_redirects = __commonJS((exports, module) => {
|
|
|
26726
26726
|
this._ending = true;
|
|
26727
26727
|
}
|
|
26728
26728
|
};
|
|
26729
|
-
RedirectableRequest.prototype.setHeader = function(name2,
|
|
26730
|
-
this._options.headers[name2] =
|
|
26731
|
-
this._currentRequest.setHeader(name2,
|
|
26729
|
+
RedirectableRequest.prototype.setHeader = function(name2, value) {
|
|
26730
|
+
this._options.headers[name2] = value;
|
|
26731
|
+
this._currentRequest.setHeader(name2, value);
|
|
26732
26732
|
};
|
|
26733
26733
|
RedirectableRequest.prototype.removeHeader = function(name2) {
|
|
26734
26734
|
delete this._options.headers[name2];
|
|
@@ -27048,17 +27048,17 @@ var require_follow_redirects = __commonJS((exports, module) => {
|
|
|
27048
27048
|
var dot = subdomain.length - domain.length - 1;
|
|
27049
27049
|
return dot > 0 && subdomain[dot] === "." && subdomain.endsWith(domain);
|
|
27050
27050
|
}
|
|
27051
|
-
function isString2(
|
|
27052
|
-
return typeof
|
|
27051
|
+
function isString2(value) {
|
|
27052
|
+
return typeof value === "string" || value instanceof String;
|
|
27053
27053
|
}
|
|
27054
|
-
function isFunction(
|
|
27055
|
-
return typeof
|
|
27054
|
+
function isFunction(value) {
|
|
27055
|
+
return typeof value === "function";
|
|
27056
27056
|
}
|
|
27057
|
-
function isBuffer(
|
|
27058
|
-
return typeof
|
|
27057
|
+
function isBuffer(value) {
|
|
27058
|
+
return typeof value === "object" && "length" in value;
|
|
27059
27059
|
}
|
|
27060
|
-
function isURL2(
|
|
27061
|
-
return URL2 &&
|
|
27060
|
+
function isURL2(value) {
|
|
27061
|
+
return URL2 && value instanceof URL2;
|
|
27062
27062
|
}
|
|
27063
27063
|
module.exports = wrap3({ http: http2, https: https2 });
|
|
27064
27064
|
module.exports.wrap = wrap3;
|
|
@@ -27254,14 +27254,14 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
27254
27254
|
} while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
|
|
27255
27255
|
return destObj;
|
|
27256
27256
|
};
|
|
27257
|
-
var endsWith = (str, searchString,
|
|
27257
|
+
var endsWith = (str, searchString, position) => {
|
|
27258
27258
|
str = String(str);
|
|
27259
|
-
if (
|
|
27260
|
-
|
|
27259
|
+
if (position === undefined || position > str.length) {
|
|
27260
|
+
position = str.length;
|
|
27261
27261
|
}
|
|
27262
|
-
|
|
27263
|
-
const lastIndex = str.indexOf(searchString,
|
|
27264
|
-
return lastIndex !== -1 && lastIndex ===
|
|
27262
|
+
position -= searchString.length;
|
|
27263
|
+
const lastIndex = str.indexOf(searchString, position);
|
|
27264
|
+
return lastIndex !== -1 && lastIndex === position;
|
|
27265
27265
|
};
|
|
27266
27266
|
var toArray = (thing) => {
|
|
27267
27267
|
if (!thing)
|
|
@@ -27323,8 +27323,8 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
27323
27323
|
if (isFunction(obj) && ["arguments", "caller", "callee"].indexOf(name2) !== -1) {
|
|
27324
27324
|
return false;
|
|
27325
27325
|
}
|
|
27326
|
-
const
|
|
27327
|
-
if (!isFunction(
|
|
27326
|
+
const value = obj[name2];
|
|
27327
|
+
if (!isFunction(value))
|
|
27328
27328
|
return;
|
|
27329
27329
|
descriptor.enumerable = false;
|
|
27330
27330
|
if ("writable" in descriptor) {
|
|
@@ -27341,8 +27341,8 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
27341
27341
|
var toObjectSet = (arrayOrString, delimiter) => {
|
|
27342
27342
|
const obj = {};
|
|
27343
27343
|
const define2 = (arr) => {
|
|
27344
|
-
arr.forEach((
|
|
27345
|
-
obj[
|
|
27344
|
+
arr.forEach((value) => {
|
|
27345
|
+
obj[value] = true;
|
|
27346
27346
|
});
|
|
27347
27347
|
};
|
|
27348
27348
|
isArray3(arrayOrString) ? define2(arrayOrString) : define2(String(arrayOrString).split(delimiter));
|
|
@@ -27350,8 +27350,8 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
27350
27350
|
};
|
|
27351
27351
|
var noop2 = () => {
|
|
27352
27352
|
};
|
|
27353
|
-
var toFiniteNumber = (
|
|
27354
|
-
return
|
|
27353
|
+
var toFiniteNumber = (value, defaultValue) => {
|
|
27354
|
+
return value != null && Number.isFinite(value = +value) ? value : defaultValue;
|
|
27355
27355
|
};
|
|
27356
27356
|
function isSpecCompliantForm(thing) {
|
|
27357
27357
|
return !!(thing && isFunction(thing.append) && thing[Symbol.toStringTag] === "FormData" && thing[Symbol.iterator]);
|
|
@@ -27366,8 +27366,8 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
27366
27366
|
if (!("toJSON" in source)) {
|
|
27367
27367
|
stack[i2] = source;
|
|
27368
27368
|
const target = isArray3(source) ? [] : {};
|
|
27369
|
-
forEach2(source, (
|
|
27370
|
-
const reducedValue = visit(
|
|
27369
|
+
forEach2(source, (value, key) => {
|
|
27370
|
+
const reducedValue = visit(value, i2 + 1);
|
|
27371
27371
|
!isUndefined3(reducedValue) && (target[key] = reducedValue);
|
|
27372
27372
|
});
|
|
27373
27373
|
stack[i2] = undefined;
|
|
@@ -27562,27 +27562,27 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
27562
27562
|
if (!utils$1.isFunction(visitor)) {
|
|
27563
27563
|
throw new TypeError("visitor must be a function");
|
|
27564
27564
|
}
|
|
27565
|
-
function convertValue(
|
|
27566
|
-
if (
|
|
27565
|
+
function convertValue(value) {
|
|
27566
|
+
if (value === null)
|
|
27567
27567
|
return "";
|
|
27568
|
-
if (utils$1.isDate(
|
|
27569
|
-
return
|
|
27568
|
+
if (utils$1.isDate(value)) {
|
|
27569
|
+
return value.toISOString();
|
|
27570
27570
|
}
|
|
27571
|
-
if (!useBlob && utils$1.isBlob(
|
|
27571
|
+
if (!useBlob && utils$1.isBlob(value)) {
|
|
27572
27572
|
throw new AxiosError("Blob is not supported. Use a Buffer instead.");
|
|
27573
27573
|
}
|
|
27574
|
-
if (utils$1.isArrayBuffer(
|
|
27575
|
-
return useBlob && typeof Blob === "function" ? new Blob([
|
|
27574
|
+
if (utils$1.isArrayBuffer(value) || utils$1.isTypedArray(value)) {
|
|
27575
|
+
return useBlob && typeof Blob === "function" ? new Blob([value]) : Buffer.from(value);
|
|
27576
27576
|
}
|
|
27577
|
-
return
|
|
27577
|
+
return value;
|
|
27578
27578
|
}
|
|
27579
|
-
function defaultVisitor(
|
|
27580
|
-
let arr =
|
|
27581
|
-
if (
|
|
27579
|
+
function defaultVisitor(value, key, path) {
|
|
27580
|
+
let arr = value;
|
|
27581
|
+
if (value && !path && typeof value === "object") {
|
|
27582
27582
|
if (utils$1.endsWith(key, "{}")) {
|
|
27583
27583
|
key = metaTokens ? key : key.slice(0, -2);
|
|
27584
|
-
|
|
27585
|
-
} else if (utils$1.isArray(
|
|
27584
|
+
value = JSON.stringify(value);
|
|
27585
|
+
} else if (utils$1.isArray(value) && isFlatArray(value) || (utils$1.isFileList(value) || utils$1.endsWith(key, "[]")) && (arr = utils$1.toArray(value))) {
|
|
27586
27586
|
key = removeBrackets(key);
|
|
27587
27587
|
arr.forEach(function each(el, index) {
|
|
27588
27588
|
!(utils$1.isUndefined(el) || el === null) && formData.append(indexes === true ? renderKey([key], index, dots) : indexes === null ? key : key + "[]", convertValue(el));
|
|
@@ -27590,10 +27590,10 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
27590
27590
|
return false;
|
|
27591
27591
|
}
|
|
27592
27592
|
}
|
|
27593
|
-
if (isVisitable(
|
|
27593
|
+
if (isVisitable(value)) {
|
|
27594
27594
|
return true;
|
|
27595
27595
|
}
|
|
27596
|
-
formData.append(renderKey(path, key, dots), convertValue(
|
|
27596
|
+
formData.append(renderKey(path, key, dots), convertValue(value));
|
|
27597
27597
|
return false;
|
|
27598
27598
|
}
|
|
27599
27599
|
const stack = [];
|
|
@@ -27602,14 +27602,14 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
27602
27602
|
convertValue,
|
|
27603
27603
|
isVisitable
|
|
27604
27604
|
});
|
|
27605
|
-
function build(
|
|
27606
|
-
if (utils$1.isUndefined(
|
|
27605
|
+
function build(value, path) {
|
|
27606
|
+
if (utils$1.isUndefined(value))
|
|
27607
27607
|
return;
|
|
27608
|
-
if (stack.indexOf(
|
|
27608
|
+
if (stack.indexOf(value) !== -1) {
|
|
27609
27609
|
throw Error("Circular reference detected in " + path.join("."));
|
|
27610
27610
|
}
|
|
27611
|
-
stack.push(
|
|
27612
|
-
utils$1.forEach(
|
|
27611
|
+
stack.push(value);
|
|
27612
|
+
utils$1.forEach(value, function each(el, key) {
|
|
27613
27613
|
const result = !(utils$1.isUndefined(el) || el === null) && visitor.call(formData, el, utils$1.isString(key) ? key.trim() : key, path, exposedHelpers);
|
|
27614
27614
|
if (result === true) {
|
|
27615
27615
|
build(el, path ? path.concat(key) : [key]);
|
|
@@ -27642,12 +27642,12 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
27642
27642
|
params && toFormData(params, this, options);
|
|
27643
27643
|
}
|
|
27644
27644
|
var prototype = AxiosURLSearchParams.prototype;
|
|
27645
|
-
prototype.append = function append(name2,
|
|
27646
|
-
this._pairs.push([name2,
|
|
27645
|
+
prototype.append = function append(name2, value) {
|
|
27646
|
+
this._pairs.push([name2, value]);
|
|
27647
27647
|
};
|
|
27648
27648
|
prototype.toString = function toString(encoder2) {
|
|
27649
|
-
const _encode = encoder2 ? function(
|
|
27650
|
-
return encoder2.call(this,
|
|
27649
|
+
const _encode = encoder2 ? function(value) {
|
|
27650
|
+
return encoder2.call(this, value, encode$1);
|
|
27651
27651
|
} : encode$1;
|
|
27652
27652
|
return this._pairs.map(function each(pair) {
|
|
27653
27653
|
return _encode(pair[0]) + "=" + _encode(pair[1]);
|
|
@@ -27770,9 +27770,9 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
27770
27770
|
};
|
|
27771
27771
|
function toURLEncodedForm(data, options) {
|
|
27772
27772
|
return toFormData(data, new platform.classes.URLSearchParams, Object.assign({
|
|
27773
|
-
visitor: function(
|
|
27774
|
-
if (platform.isNode && utils$1.isBuffer(
|
|
27775
|
-
this.append(key,
|
|
27773
|
+
visitor: function(value, key, path, helpers) {
|
|
27774
|
+
if (platform.isNode && utils$1.isBuffer(value)) {
|
|
27775
|
+
this.append(key, value.toString("base64"));
|
|
27776
27776
|
return false;
|
|
27777
27777
|
}
|
|
27778
27778
|
return helpers.defaultVisitor.apply(this, arguments);
|
|
@@ -27797,7 +27797,7 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
27797
27797
|
return obj;
|
|
27798
27798
|
}
|
|
27799
27799
|
function formDataToJSON(formData) {
|
|
27800
|
-
function buildPath(path,
|
|
27800
|
+
function buildPath(path, value, target, index) {
|
|
27801
27801
|
let name2 = path[index++];
|
|
27802
27802
|
if (name2 === "__proto__")
|
|
27803
27803
|
return true;
|
|
@@ -27806,16 +27806,16 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
27806
27806
|
name2 = !name2 && utils$1.isArray(target) ? target.length : name2;
|
|
27807
27807
|
if (isLast) {
|
|
27808
27808
|
if (utils$1.hasOwnProp(target, name2)) {
|
|
27809
|
-
target[name2] = [target[name2],
|
|
27809
|
+
target[name2] = [target[name2], value];
|
|
27810
27810
|
} else {
|
|
27811
|
-
target[name2] =
|
|
27811
|
+
target[name2] = value;
|
|
27812
27812
|
}
|
|
27813
27813
|
return !isNumericKey;
|
|
27814
27814
|
}
|
|
27815
27815
|
if (!target[name2] || !utils$1.isObject(target[name2])) {
|
|
27816
27816
|
target[name2] = [];
|
|
27817
27817
|
}
|
|
27818
|
-
const result = buildPath(path,
|
|
27818
|
+
const result = buildPath(path, value, target[name2], index);
|
|
27819
27819
|
if (result && utils$1.isArray(target[name2])) {
|
|
27820
27820
|
target[name2] = arrayToObject(target[name2]);
|
|
27821
27821
|
}
|
|
@@ -27823,8 +27823,8 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
27823
27823
|
}
|
|
27824
27824
|
if (utils$1.isFormData(formData) && utils$1.isFunction(formData.entries)) {
|
|
27825
27825
|
const obj = {};
|
|
27826
|
-
utils$1.forEachEntry(formData, (name2,
|
|
27827
|
-
buildPath(parsePropPath(name2),
|
|
27826
|
+
utils$1.forEachEntry(formData, (name2, value) => {
|
|
27827
|
+
buildPath(parsePropPath(name2), value, obj, 0);
|
|
27828
27828
|
});
|
|
27829
27829
|
return obj;
|
|
27830
27830
|
}
|
|
@@ -27977,11 +27977,11 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
27977
27977
|
function normalizeHeader(header) {
|
|
27978
27978
|
return header && String(header).trim().toLowerCase();
|
|
27979
27979
|
}
|
|
27980
|
-
function normalizeValue(
|
|
27981
|
-
if (
|
|
27982
|
-
return
|
|
27980
|
+
function normalizeValue(value) {
|
|
27981
|
+
if (value === false || value == null) {
|
|
27982
|
+
return value;
|
|
27983
27983
|
}
|
|
27984
|
-
return utils$1.isArray(
|
|
27984
|
+
return utils$1.isArray(value) ? value.map(normalizeValue) : String(value);
|
|
27985
27985
|
}
|
|
27986
27986
|
function parseTokens(str) {
|
|
27987
27987
|
const tokens = Object.create(null);
|
|
@@ -27993,20 +27993,20 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
27993
27993
|
return tokens;
|
|
27994
27994
|
}
|
|
27995
27995
|
var isValidHeaderName = (str) => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str.trim());
|
|
27996
|
-
function matchHeaderValue(context3,
|
|
27996
|
+
function matchHeaderValue(context3, value, header, filter, isHeaderNameFilter) {
|
|
27997
27997
|
if (utils$1.isFunction(filter)) {
|
|
27998
|
-
return filter.call(this,
|
|
27998
|
+
return filter.call(this, value, header);
|
|
27999
27999
|
}
|
|
28000
28000
|
if (isHeaderNameFilter) {
|
|
28001
|
-
|
|
28001
|
+
value = header;
|
|
28002
28002
|
}
|
|
28003
|
-
if (!utils$1.isString(
|
|
28003
|
+
if (!utils$1.isString(value))
|
|
28004
28004
|
return;
|
|
28005
28005
|
if (utils$1.isString(filter)) {
|
|
28006
|
-
return
|
|
28006
|
+
return value.indexOf(filter) !== -1;
|
|
28007
28007
|
}
|
|
28008
28008
|
if (utils$1.isRegExp(filter)) {
|
|
28009
|
-
return filter.test(
|
|
28009
|
+
return filter.test(value);
|
|
28010
28010
|
}
|
|
28011
28011
|
}
|
|
28012
28012
|
function formatHeader(header) {
|
|
@@ -28048,8 +28048,8 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
28048
28048
|
} else if (utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
|
|
28049
28049
|
setHeaders(parseHeaders(header), valueOrRewrite);
|
|
28050
28050
|
} else if (utils$1.isHeaders(header)) {
|
|
28051
|
-
for (const [key,
|
|
28052
|
-
setHeader(
|
|
28051
|
+
for (const [key, value] of header.entries()) {
|
|
28052
|
+
setHeader(value, key, rewrite);
|
|
28053
28053
|
}
|
|
28054
28054
|
} else {
|
|
28055
28055
|
header != null && setHeader(valueOrRewrite, header, rewrite);
|
|
@@ -28061,18 +28061,18 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
28061
28061
|
if (header) {
|
|
28062
28062
|
const key = utils$1.findKey(this, header);
|
|
28063
28063
|
if (key) {
|
|
28064
|
-
const
|
|
28064
|
+
const value = this[key];
|
|
28065
28065
|
if (!parser) {
|
|
28066
|
-
return
|
|
28066
|
+
return value;
|
|
28067
28067
|
}
|
|
28068
28068
|
if (parser === true) {
|
|
28069
|
-
return parseTokens(
|
|
28069
|
+
return parseTokens(value);
|
|
28070
28070
|
}
|
|
28071
28071
|
if (utils$1.isFunction(parser)) {
|
|
28072
|
-
return parser.call(this,
|
|
28072
|
+
return parser.call(this, value, key);
|
|
28073
28073
|
}
|
|
28074
28074
|
if (utils$1.isRegExp(parser)) {
|
|
28075
|
-
return parser.exec(
|
|
28075
|
+
return parser.exec(value);
|
|
28076
28076
|
}
|
|
28077
28077
|
throw new TypeError("parser must be boolean|regexp|function");
|
|
28078
28078
|
}
|
|
@@ -28122,10 +28122,10 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
28122
28122
|
normalize(format) {
|
|
28123
28123
|
const self2 = this;
|
|
28124
28124
|
const headers = {};
|
|
28125
|
-
utils$1.forEach(this, (
|
|
28125
|
+
utils$1.forEach(this, (value, header) => {
|
|
28126
28126
|
const key = utils$1.findKey(headers, header);
|
|
28127
28127
|
if (key) {
|
|
28128
|
-
self2[key] = normalizeValue(
|
|
28128
|
+
self2[key] = normalizeValue(value);
|
|
28129
28129
|
delete self2[header];
|
|
28130
28130
|
return;
|
|
28131
28131
|
}
|
|
@@ -28133,7 +28133,7 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
28133
28133
|
if (normalized !== header) {
|
|
28134
28134
|
delete self2[header];
|
|
28135
28135
|
}
|
|
28136
|
-
self2[normalized] = normalizeValue(
|
|
28136
|
+
self2[normalized] = normalizeValue(value);
|
|
28137
28137
|
headers[normalized] = true;
|
|
28138
28138
|
});
|
|
28139
28139
|
return this;
|
|
@@ -28143,8 +28143,8 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
28143
28143
|
}
|
|
28144
28144
|
toJSON(asStrings) {
|
|
28145
28145
|
const obj = Object.create(null);
|
|
28146
|
-
utils$1.forEach(this, (
|
|
28147
|
-
|
|
28146
|
+
utils$1.forEach(this, (value, header) => {
|
|
28147
|
+
value != null && value !== false && (obj[header] = asStrings && utils$1.isArray(value) ? value.join(", ") : value);
|
|
28148
28148
|
});
|
|
28149
28149
|
return obj;
|
|
28150
28150
|
}
|
|
@@ -28152,7 +28152,7 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
28152
28152
|
return Object.entries(this.toJSON())[Symbol.iterator]();
|
|
28153
28153
|
}
|
|
28154
28154
|
toString() {
|
|
28155
|
-
return Object.entries(this.toJSON()).map(([header,
|
|
28155
|
+
return Object.entries(this.toJSON()).map(([header, value]) => header + ": " + value).join(`
|
|
28156
28156
|
`);
|
|
28157
28157
|
}
|
|
28158
28158
|
get [Symbol.toStringTag]() {
|
|
@@ -28184,10 +28184,10 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
28184
28184
|
}
|
|
28185
28185
|
}
|
|
28186
28186
|
AxiosHeaders.accessor(["Content-Type", "Content-Length", "Accept", "Accept-Encoding", "User-Agent", "Authorization"]);
|
|
28187
|
-
utils$1.reduceDescriptors(AxiosHeaders.prototype, ({ value
|
|
28187
|
+
utils$1.reduceDescriptors(AxiosHeaders.prototype, ({ value }, key) => {
|
|
28188
28188
|
let mapped = key[0].toUpperCase() + key.slice(1);
|
|
28189
28189
|
return {
|
|
28190
|
-
get: () =>
|
|
28190
|
+
get: () => value,
|
|
28191
28191
|
set(headerValue) {
|
|
28192
28192
|
this[mapped] = headerValue;
|
|
28193
28193
|
}
|
|
@@ -28206,8 +28206,8 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
28206
28206
|
headers.normalize();
|
|
28207
28207
|
return data;
|
|
28208
28208
|
}
|
|
28209
|
-
function isCancel(
|
|
28210
|
-
return !!(
|
|
28209
|
+
function isCancel(value) {
|
|
28210
|
+
return !!(value && value.__CANCEL__);
|
|
28211
28211
|
}
|
|
28212
28212
|
function CanceledError(message2, config2, request) {
|
|
28213
28213
|
AxiosError.call(this, message2 == null ? "canceled" : message2, AxiosError.ERR_CANCELED, config2, request);
|
|
@@ -28403,28 +28403,28 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
28403
28403
|
var CRLF_BYTES_COUNT = 2;
|
|
28404
28404
|
|
|
28405
28405
|
class FormDataPart {
|
|
28406
|
-
constructor(name2,
|
|
28406
|
+
constructor(name2, value) {
|
|
28407
28407
|
const { escapeName } = this.constructor;
|
|
28408
|
-
const isStringValue = utils$1.isString(
|
|
28409
|
-
let headers = `Content-Disposition: form-data; name="${escapeName(name2)}"${!isStringValue &&
|
|
28408
|
+
const isStringValue = utils$1.isString(value);
|
|
28409
|
+
let headers = `Content-Disposition: form-data; name="${escapeName(name2)}"${!isStringValue && value.name ? `; filename="${escapeName(value.name)}"` : ""}${CRLF}`;
|
|
28410
28410
|
if (isStringValue) {
|
|
28411
|
-
|
|
28411
|
+
value = textEncoder.encode(String(value).replace(/\r?\n|\r\n?/g, CRLF));
|
|
28412
28412
|
} else {
|
|
28413
|
-
headers += `Content-Type: ${
|
|
28413
|
+
headers += `Content-Type: ${value.type || "application/octet-stream"}${CRLF}`;
|
|
28414
28414
|
}
|
|
28415
28415
|
this.headers = textEncoder.encode(headers + CRLF);
|
|
28416
|
-
this.contentLength = isStringValue ?
|
|
28416
|
+
this.contentLength = isStringValue ? value.byteLength : value.size;
|
|
28417
28417
|
this.size = this.headers.byteLength + this.contentLength + CRLF_BYTES_COUNT;
|
|
28418
28418
|
this.name = name2;
|
|
28419
|
-
this.value =
|
|
28419
|
+
this.value = value;
|
|
28420
28420
|
}
|
|
28421
28421
|
async* encode() {
|
|
28422
28422
|
yield this.headers;
|
|
28423
|
-
const { value
|
|
28424
|
-
if (utils$1.isTypedArray(
|
|
28425
|
-
yield
|
|
28423
|
+
const { value } = this;
|
|
28424
|
+
if (utils$1.isTypedArray(value)) {
|
|
28425
|
+
yield value;
|
|
28426
28426
|
} else {
|
|
28427
|
-
yield* readBlob$1(
|
|
28427
|
+
yield* readBlob$1(value);
|
|
28428
28428
|
}
|
|
28429
28429
|
yield CRLF_BYTES;
|
|
28430
28430
|
}
|
|
@@ -28451,8 +28451,8 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
28451
28451
|
const boundaryBytes = textEncoder.encode("--" + boundary + CRLF);
|
|
28452
28452
|
const footerBytes = textEncoder.encode("--" + boundary + "--" + CRLF + CRLF);
|
|
28453
28453
|
let contentLength = footerBytes.byteLength;
|
|
28454
|
-
const parts = Array.from(form.entries()).map(([name2,
|
|
28455
|
-
const part = new FormDataPart(name2,
|
|
28454
|
+
const parts = Array.from(form.entries()).map(([name2, value]) => {
|
|
28455
|
+
const part = new FormDataPart(name2, value);
|
|
28456
28456
|
contentLength += part.size;
|
|
28457
28457
|
return part;
|
|
28458
28458
|
});
|
|
@@ -28497,9 +28497,9 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
28497
28497
|
var callbackify = (fn, reducer) => {
|
|
28498
28498
|
return utils$1.isAsyncFn(fn) ? function(...args) {
|
|
28499
28499
|
const cb = args.pop();
|
|
28500
|
-
fn.apply(this, args).then((
|
|
28500
|
+
fn.apply(this, args).then((value) => {
|
|
28501
28501
|
try {
|
|
28502
|
-
reducer ? cb(null, ...reducer(
|
|
28502
|
+
reducer ? cb(null, ...reducer(value)) : cb(null, value);
|
|
28503
28503
|
} catch (err) {
|
|
28504
28504
|
cb(err);
|
|
28505
28505
|
}
|
|
@@ -28669,15 +28669,15 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
28669
28669
|
return new Promise((resolve, reject) => {
|
|
28670
28670
|
let onDone;
|
|
28671
28671
|
let isDone;
|
|
28672
|
-
const done = (
|
|
28672
|
+
const done = (value, isRejected) => {
|
|
28673
28673
|
if (isDone)
|
|
28674
28674
|
return;
|
|
28675
28675
|
isDone = true;
|
|
28676
|
-
onDone && onDone(
|
|
28676
|
+
onDone && onDone(value, isRejected);
|
|
28677
28677
|
};
|
|
28678
|
-
const _resolve = (
|
|
28679
|
-
done(
|
|
28680
|
-
resolve(
|
|
28678
|
+
const _resolve = (value) => {
|
|
28679
|
+
done(value);
|
|
28680
|
+
resolve(value);
|
|
28681
28681
|
};
|
|
28682
28682
|
const _reject = (reason) => {
|
|
28683
28683
|
done(reason, true);
|
|
@@ -28705,7 +28705,7 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
28705
28705
|
let rejected = false;
|
|
28706
28706
|
let req;
|
|
28707
28707
|
if (lookup) {
|
|
28708
|
-
const _lookup = callbackify$1(lookup, (
|
|
28708
|
+
const _lookup = callbackify$1(lookup, (value) => utils$1.isArray(value) ? value : [value]);
|
|
28709
28709
|
lookup = (hostname, opt, cb) => {
|
|
28710
28710
|
_lookup(hostname, opt, (err, arg0, arg1) => {
|
|
28711
28711
|
if (err) {
|
|
@@ -28726,7 +28726,7 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
28726
28726
|
}
|
|
28727
28727
|
emitter.removeAllListeners();
|
|
28728
28728
|
};
|
|
28729
|
-
onDone((
|
|
28729
|
+
onDone((value, isRejected) => {
|
|
28730
28730
|
isDone = true;
|
|
28731
28731
|
if (isRejected) {
|
|
28732
28732
|
rejected = true;
|
|
@@ -29061,8 +29061,8 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
29061
29061
|
return origin2.protocol === url2.protocol && origin2.host === url2.host && (isMSIE || origin2.port === url2.port);
|
|
29062
29062
|
})(new URL(platform.origin), platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent)) : () => true;
|
|
29063
29063
|
var cookies = platform.hasStandardBrowserEnv ? {
|
|
29064
|
-
write(name2,
|
|
29065
|
-
const cookie = [name2 + "=" + encodeURIComponent(
|
|
29064
|
+
write(name2, value, expires, path, domain, secure) {
|
|
29065
|
+
const cookie = [name2 + "=" + encodeURIComponent(value)];
|
|
29066
29066
|
utils$1.isNumber(expires) && cookie.push("expires=" + new Date(expires).toGMTString());
|
|
29067
29067
|
utils$1.isString(path) && cookie.push("path=" + path);
|
|
29068
29068
|
utils$1.isString(domain) && cookie.push("domain=" + domain);
|
|
@@ -29224,8 +29224,8 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
29224
29224
|
config: config2,
|
|
29225
29225
|
request
|
|
29226
29226
|
};
|
|
29227
|
-
settle(function _resolve(
|
|
29228
|
-
resolve(
|
|
29227
|
+
settle(function _resolve(value) {
|
|
29228
|
+
resolve(value);
|
|
29229
29229
|
done();
|
|
29230
29230
|
}, function _reject(err) {
|
|
29231
29231
|
reject(err);
|
|
@@ -29370,11 +29370,11 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
29370
29370
|
const reader = stream3.getReader();
|
|
29371
29371
|
try {
|
|
29372
29372
|
for (;; ) {
|
|
29373
|
-
const { done, value
|
|
29373
|
+
const { done, value } = await reader.read();
|
|
29374
29374
|
if (done) {
|
|
29375
29375
|
break;
|
|
29376
29376
|
}
|
|
29377
|
-
yield
|
|
29377
|
+
yield value;
|
|
29378
29378
|
}
|
|
29379
29379
|
} finally {
|
|
29380
29380
|
await reader.cancel();
|
|
@@ -29393,18 +29393,18 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
29393
29393
|
return new ReadableStream({
|
|
29394
29394
|
async pull(controller) {
|
|
29395
29395
|
try {
|
|
29396
|
-
const { done: done2, value
|
|
29396
|
+
const { done: done2, value } = await iterator.next();
|
|
29397
29397
|
if (done2) {
|
|
29398
29398
|
_onFinish();
|
|
29399
29399
|
controller.close();
|
|
29400
29400
|
return;
|
|
29401
29401
|
}
|
|
29402
|
-
let len =
|
|
29402
|
+
let len = value.byteLength;
|
|
29403
29403
|
if (onProgress) {
|
|
29404
29404
|
let loadedBytes = bytes += len;
|
|
29405
29405
|
onProgress(loadedBytes);
|
|
29406
29406
|
}
|
|
29407
|
-
controller.enqueue(new Uint8Array(
|
|
29407
|
+
controller.enqueue(new Uint8Array(value));
|
|
29408
29408
|
} catch (err) {
|
|
29409
29409
|
_onFinish(err);
|
|
29410
29410
|
throw err;
|
|
@@ -29573,13 +29573,13 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
29573
29573
|
xhr: xhrAdapter,
|
|
29574
29574
|
fetch: fetchAdapter
|
|
29575
29575
|
};
|
|
29576
|
-
utils$1.forEach(knownAdapters, (fn,
|
|
29576
|
+
utils$1.forEach(knownAdapters, (fn, value) => {
|
|
29577
29577
|
if (fn) {
|
|
29578
29578
|
try {
|
|
29579
|
-
Object.defineProperty(fn, "name", { value
|
|
29579
|
+
Object.defineProperty(fn, "name", { value });
|
|
29580
29580
|
} catch (e2) {
|
|
29581
29581
|
}
|
|
29582
|
-
Object.defineProperty(fn, "adapterName", { value
|
|
29582
|
+
Object.defineProperty(fn, "adapterName", { value });
|
|
29583
29583
|
}
|
|
29584
29584
|
});
|
|
29585
29585
|
var renderReason = (reason) => `- ${reason}`;
|
|
@@ -29660,7 +29660,7 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
29660
29660
|
function formatMessage(opt, desc) {
|
|
29661
29661
|
return "[Axios v" + VERSION3 + "] Transitional option '" + opt + "'" + desc + (message2 ? ". " + message2 : "");
|
|
29662
29662
|
}
|
|
29663
|
-
return (
|
|
29663
|
+
return (value, opt, opts) => {
|
|
29664
29664
|
if (validator2 === false) {
|
|
29665
29665
|
throw new AxiosError(formatMessage(opt, " has been removed" + (version ? " in " + version : "")), AxiosError.ERR_DEPRECATED);
|
|
29666
29666
|
}
|
|
@@ -29668,11 +29668,11 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
29668
29668
|
deprecatedWarnings[opt] = true;
|
|
29669
29669
|
console.warn(formatMessage(opt, " has been deprecated since v" + version + " and will be removed in the near future"));
|
|
29670
29670
|
}
|
|
29671
|
-
return validator2 ? validator2(
|
|
29671
|
+
return validator2 ? validator2(value, opt, opts) : true;
|
|
29672
29672
|
};
|
|
29673
29673
|
};
|
|
29674
29674
|
validators$1.spelling = function spelling(correctSpelling) {
|
|
29675
|
-
return (
|
|
29675
|
+
return (value, opt) => {
|
|
29676
29676
|
console.warn(`${opt} is likely a misspelling of ${correctSpelling}`);
|
|
29677
29677
|
return true;
|
|
29678
29678
|
};
|
|
@@ -29687,8 +29687,8 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
29687
29687
|
const opt = keys[i2];
|
|
29688
29688
|
const validator2 = schema[opt];
|
|
29689
29689
|
if (validator2) {
|
|
29690
|
-
const
|
|
29691
|
-
const result =
|
|
29690
|
+
const value = options[opt];
|
|
29691
|
+
const result = value === undefined || validator2(value, opt, options);
|
|
29692
29692
|
if (result !== true) {
|
|
29693
29693
|
throw new AxiosError("option " + opt + " must be " + result, AxiosError.ERR_BAD_OPTION_VALUE);
|
|
29694
29694
|
}
|
|
@@ -30021,8 +30021,8 @@ var require_axios = __commonJS((exports, module) => {
|
|
|
30021
30021
|
NotExtended: 510,
|
|
30022
30022
|
NetworkAuthenticationRequired: 511
|
|
30023
30023
|
};
|
|
30024
|
-
Object.entries(HttpStatusCode).forEach(([key,
|
|
30025
|
-
HttpStatusCode[
|
|
30024
|
+
Object.entries(HttpStatusCode).forEach(([key, value]) => {
|
|
30025
|
+
HttpStatusCode[value] = key;
|
|
30026
30026
|
});
|
|
30027
30027
|
var HttpStatusCode$1 = HttpStatusCode;
|
|
30028
30028
|
function createInstance(defaultConfig) {
|
|
@@ -30768,23 +30768,23 @@ var require_beautifier = __commonJS((exports) => {
|
|
|
30768
30768
|
}
|
|
30769
30769
|
const newItem = {};
|
|
30770
30770
|
for (const key2 in data) {
|
|
30771
|
-
const
|
|
30772
|
-
const valueType = typeof
|
|
30771
|
+
const value = data[key2];
|
|
30772
|
+
const valueType = typeof value;
|
|
30773
30773
|
let newKey = knownBeautification[key2] || key2;
|
|
30774
30774
|
if (Array.isArray(newKey)) {
|
|
30775
30775
|
newKey = newKey[0];
|
|
30776
30776
|
}
|
|
30777
|
-
if (!Array.isArray(
|
|
30778
|
-
if (valueType === "object" &&
|
|
30779
|
-
newItem[newKey] = this.beautify(
|
|
30777
|
+
if (!Array.isArray(value)) {
|
|
30778
|
+
if (valueType === "object" && value !== null) {
|
|
30779
|
+
newItem[newKey] = this.beautify(value, knownBeautification[key2]);
|
|
30780
30780
|
} else {
|
|
30781
|
-
newItem[newKey] = this.beautifyValueWithKey(newKey,
|
|
30781
|
+
newItem[newKey] = this.beautifyValueWithKey(newKey, value);
|
|
30782
30782
|
}
|
|
30783
30783
|
continue;
|
|
30784
30784
|
}
|
|
30785
30785
|
const newArray = [];
|
|
30786
30786
|
if (Array.isArray(this.beautificationMap[newKey])) {
|
|
30787
|
-
for (const elementValue of
|
|
30787
|
+
for (const elementValue of value) {
|
|
30788
30788
|
const mappedBeautification = this.beautificationMap[knownBeautification[key2]];
|
|
30789
30789
|
const childMapping = mappedBeautification[0];
|
|
30790
30790
|
if (typeof childMapping === "object" && childMapping !== null) {
|
|
@@ -30881,22 +30881,22 @@ var require_nanoid = __commonJS((exports, module) => {
|
|
|
30881
30881
|
// node_modules/binance/lib/util/browser-support.js
|
|
30882
30882
|
var require_browser_support = __commonJS((exports) => {
|
|
30883
30883
|
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
30884
|
-
function adopt(
|
|
30885
|
-
return
|
|
30886
|
-
resolve(
|
|
30884
|
+
function adopt(value) {
|
|
30885
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
30886
|
+
resolve(value);
|
|
30887
30887
|
});
|
|
30888
30888
|
}
|
|
30889
30889
|
return new (P || (P = Promise))(function(resolve, reject) {
|
|
30890
|
-
function fulfilled(
|
|
30890
|
+
function fulfilled(value) {
|
|
30891
30891
|
try {
|
|
30892
|
-
step(generator.next(
|
|
30892
|
+
step(generator.next(value));
|
|
30893
30893
|
} catch (e2) {
|
|
30894
30894
|
reject(e2);
|
|
30895
30895
|
}
|
|
30896
30896
|
}
|
|
30897
|
-
function rejected(
|
|
30897
|
+
function rejected(value) {
|
|
30898
30898
|
try {
|
|
30899
|
-
step(generator["throw"](
|
|
30899
|
+
step(generator["throw"](value));
|
|
30900
30900
|
} catch (e2) {
|
|
30901
30901
|
reject(e2);
|
|
30902
30902
|
}
|
|
@@ -30973,22 +30973,22 @@ var require_node_support = __commonJS((exports) => {
|
|
|
30973
30973
|
return result;
|
|
30974
30974
|
};
|
|
30975
30975
|
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
30976
|
-
function adopt(
|
|
30977
|
-
return
|
|
30978
|
-
resolve(
|
|
30976
|
+
function adopt(value) {
|
|
30977
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
30978
|
+
resolve(value);
|
|
30979
30979
|
});
|
|
30980
30980
|
}
|
|
30981
30981
|
return new (P || (P = Promise))(function(resolve, reject) {
|
|
30982
|
-
function fulfilled(
|
|
30982
|
+
function fulfilled(value) {
|
|
30983
30983
|
try {
|
|
30984
|
-
step(generator.next(
|
|
30984
|
+
step(generator.next(value));
|
|
30985
30985
|
} catch (e2) {
|
|
30986
30986
|
reject(e2);
|
|
30987
30987
|
}
|
|
30988
30988
|
}
|
|
30989
|
-
function rejected(
|
|
30989
|
+
function rejected(value) {
|
|
30990
30990
|
try {
|
|
30991
|
-
step(generator["throw"](
|
|
30991
|
+
step(generator["throw"](value));
|
|
30992
30992
|
} catch (e2) {
|
|
30993
30993
|
reject(e2);
|
|
30994
30994
|
}
|
|
@@ -31020,22 +31020,22 @@ var require_node_support = __commonJS((exports) => {
|
|
|
31020
31020
|
// node_modules/binance/lib/util/requestUtils.js
|
|
31021
31021
|
var require_requestUtils = __commonJS((exports) => {
|
|
31022
31022
|
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
31023
|
-
function adopt(
|
|
31024
|
-
return
|
|
31025
|
-
resolve(
|
|
31023
|
+
function adopt(value) {
|
|
31024
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
31025
|
+
resolve(value);
|
|
31026
31026
|
});
|
|
31027
31027
|
}
|
|
31028
31028
|
return new (P || (P = Promise))(function(resolve, reject) {
|
|
31029
|
-
function fulfilled(
|
|
31029
|
+
function fulfilled(value) {
|
|
31030
31030
|
try {
|
|
31031
|
-
step(generator.next(
|
|
31031
|
+
step(generator.next(value));
|
|
31032
31032
|
} catch (e2) {
|
|
31033
31033
|
reject(e2);
|
|
31034
31034
|
}
|
|
31035
31035
|
}
|
|
31036
|
-
function rejected(
|
|
31036
|
+
function rejected(value) {
|
|
31037
31037
|
try {
|
|
31038
|
-
step(generator["throw"](
|
|
31038
|
+
step(generator["throw"](value));
|
|
31039
31039
|
} catch (e2) {
|
|
31040
31040
|
reject(e2);
|
|
31041
31041
|
}
|
|
@@ -31081,11 +31081,11 @@ var require_requestUtils = __commonJS((exports) => {
|
|
|
31081
31081
|
function serialiseParams(params = {}, strict_validation = false, encodeValues = false, filterUndefinedParams = false) {
|
|
31082
31082
|
const paramKeys = !filterUndefinedParams ? Object.keys(params) : Object.keys(params).filter((key) => typeof params[key] !== "undefined");
|
|
31083
31083
|
return paramKeys.map((key) => {
|
|
31084
|
-
const
|
|
31085
|
-
if (strict_validation === true && typeof
|
|
31084
|
+
const value = params[key];
|
|
31085
|
+
if (strict_validation === true && typeof value === "undefined") {
|
|
31086
31086
|
throw new Error("Failed to sign API request due to undefined parameter");
|
|
31087
31087
|
}
|
|
31088
|
-
const encodedValue = encodeValues ? encodeURIComponent(
|
|
31088
|
+
const encodedValue = encodeValues ? encodeURIComponent(value) : value;
|
|
31089
31089
|
return `${key}=${encodedValue}`;
|
|
31090
31090
|
}).join("&");
|
|
31091
31091
|
}
|
|
@@ -31224,22 +31224,22 @@ var require_requestUtils = __commonJS((exports) => {
|
|
|
31224
31224
|
// node_modules/binance/lib/util/BaseRestClient.js
|
|
31225
31225
|
var require_BaseRestClient = __commonJS((exports) => {
|
|
31226
31226
|
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
31227
|
-
function adopt(
|
|
31228
|
-
return
|
|
31229
|
-
resolve(
|
|
31227
|
+
function adopt(value) {
|
|
31228
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
31229
|
+
resolve(value);
|
|
31230
31230
|
});
|
|
31231
31231
|
}
|
|
31232
31232
|
return new (P || (P = Promise))(function(resolve, reject) {
|
|
31233
|
-
function fulfilled(
|
|
31233
|
+
function fulfilled(value) {
|
|
31234
31234
|
try {
|
|
31235
|
-
step(generator.next(
|
|
31235
|
+
step(generator.next(value));
|
|
31236
31236
|
} catch (e2) {
|
|
31237
31237
|
reject(e2);
|
|
31238
31238
|
}
|
|
31239
31239
|
}
|
|
31240
|
-
function rejected(
|
|
31240
|
+
function rejected(value) {
|
|
31241
31241
|
try {
|
|
31242
|
-
step(generator["throw"](
|
|
31242
|
+
step(generator["throw"](value));
|
|
31243
31243
|
} catch (e2) {
|
|
31244
31244
|
reject(e2);
|
|
31245
31245
|
}
|
|
@@ -31311,8 +31311,8 @@ var require_BaseRestClient = __commonJS((exports) => {
|
|
|
31311
31311
|
getTimeOffset() {
|
|
31312
31312
|
return this.timeOffset;
|
|
31313
31313
|
}
|
|
31314
|
-
setTimeOffset(
|
|
31315
|
-
this.timeOffset =
|
|
31314
|
+
setTimeOffset(value) {
|
|
31315
|
+
this.timeOffset = value;
|
|
31316
31316
|
}
|
|
31317
31317
|
get(endpoint, params) {
|
|
31318
31318
|
return this._call("GET", endpoint, params);
|
|
@@ -31406,18 +31406,18 @@ var require_BaseRestClient = __commonJS((exports) => {
|
|
|
31406
31406
|
const delta = {};
|
|
31407
31407
|
for (const headerKey in this.apiLimitTrackers) {
|
|
31408
31408
|
const headerValue = responseHeaders[headerKey];
|
|
31409
|
-
const
|
|
31410
|
-
if (headerValue !== undefined && !isNaN(
|
|
31411
|
-
this.apiLimitTrackers[headerKey] =
|
|
31409
|
+
const value = parseInt(headerValue);
|
|
31410
|
+
if (headerValue !== undefined && !isNaN(value)) {
|
|
31411
|
+
this.apiLimitTrackers[headerKey] = value;
|
|
31412
31412
|
delta[headerKey] = {
|
|
31413
31413
|
updated: true,
|
|
31414
|
-
valueParsed:
|
|
31414
|
+
valueParsed: value,
|
|
31415
31415
|
valueRaw: headerValue
|
|
31416
31416
|
};
|
|
31417
31417
|
} else {
|
|
31418
31418
|
delta[headerKey] = {
|
|
31419
31419
|
updated: false,
|
|
31420
|
-
valueParsed:
|
|
31420
|
+
valueParsed: value,
|
|
31421
31421
|
valueRaw: headerValue
|
|
31422
31422
|
};
|
|
31423
31423
|
}
|
|
@@ -31458,22 +31458,22 @@ var require_BaseRestClient = __commonJS((exports) => {
|
|
|
31458
31458
|
// node_modules/binance/lib/coinm-client.js
|
|
31459
31459
|
var require_coinm_client = __commonJS((exports) => {
|
|
31460
31460
|
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
31461
|
-
function adopt(
|
|
31462
|
-
return
|
|
31463
|
-
resolve(
|
|
31461
|
+
function adopt(value) {
|
|
31462
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
31463
|
+
resolve(value);
|
|
31464
31464
|
});
|
|
31465
31465
|
}
|
|
31466
31466
|
return new (P || (P = Promise))(function(resolve, reject) {
|
|
31467
|
-
function fulfilled(
|
|
31467
|
+
function fulfilled(value) {
|
|
31468
31468
|
try {
|
|
31469
|
-
step(generator.next(
|
|
31469
|
+
step(generator.next(value));
|
|
31470
31470
|
} catch (e2) {
|
|
31471
31471
|
reject(e2);
|
|
31472
31472
|
}
|
|
31473
31473
|
}
|
|
31474
|
-
function rejected(
|
|
31474
|
+
function rejected(value) {
|
|
31475
31475
|
try {
|
|
31476
|
-
step(generator["throw"](
|
|
31476
|
+
step(generator["throw"](value));
|
|
31477
31477
|
} catch (e2) {
|
|
31478
31478
|
reject(e2);
|
|
31479
31479
|
}
|
|
@@ -31825,22 +31825,22 @@ var require_logger = __commonJS((exports) => {
|
|
|
31825
31825
|
// node_modules/binance/lib/main-client.js
|
|
31826
31826
|
var require_main_client = __commonJS((exports) => {
|
|
31827
31827
|
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
31828
|
-
function adopt(
|
|
31829
|
-
return
|
|
31830
|
-
resolve(
|
|
31828
|
+
function adopt(value) {
|
|
31829
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
31830
|
+
resolve(value);
|
|
31831
31831
|
});
|
|
31832
31832
|
}
|
|
31833
31833
|
return new (P || (P = Promise))(function(resolve, reject) {
|
|
31834
|
-
function fulfilled(
|
|
31834
|
+
function fulfilled(value) {
|
|
31835
31835
|
try {
|
|
31836
|
-
step(generator.next(
|
|
31836
|
+
step(generator.next(value));
|
|
31837
31837
|
} catch (e2) {
|
|
31838
31838
|
reject(e2);
|
|
31839
31839
|
}
|
|
31840
31840
|
}
|
|
31841
|
-
function rejected(
|
|
31841
|
+
function rejected(value) {
|
|
31842
31842
|
try {
|
|
31843
|
-
step(generator["throw"](
|
|
31843
|
+
step(generator["throw"](value));
|
|
31844
31844
|
} catch (e2) {
|
|
31845
31845
|
reject(e2);
|
|
31846
31846
|
}
|
|
@@ -33371,22 +33371,22 @@ var require_main_client = __commonJS((exports) => {
|
|
|
33371
33371
|
// node_modules/binance/lib/portfolio-client.js
|
|
33372
33372
|
var require_portfolio_client = __commonJS((exports) => {
|
|
33373
33373
|
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
33374
|
-
function adopt(
|
|
33375
|
-
return
|
|
33376
|
-
resolve(
|
|
33374
|
+
function adopt(value) {
|
|
33375
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
33376
|
+
resolve(value);
|
|
33377
33377
|
});
|
|
33378
33378
|
}
|
|
33379
33379
|
return new (P || (P = Promise))(function(resolve, reject) {
|
|
33380
|
-
function fulfilled(
|
|
33380
|
+
function fulfilled(value) {
|
|
33381
33381
|
try {
|
|
33382
|
-
step(generator.next(
|
|
33382
|
+
step(generator.next(value));
|
|
33383
33383
|
} catch (e2) {
|
|
33384
33384
|
reject(e2);
|
|
33385
33385
|
}
|
|
33386
33386
|
}
|
|
33387
|
-
function rejected(
|
|
33387
|
+
function rejected(value) {
|
|
33388
33388
|
try {
|
|
33389
|
-
step(generator["throw"](
|
|
33389
|
+
step(generator["throw"](value));
|
|
33390
33390
|
} catch (e2) {
|
|
33391
33391
|
reject(e2);
|
|
33392
33392
|
}
|
|
@@ -33845,22 +33845,22 @@ var require_websockets = __commonJS((exports) => {
|
|
|
33845
33845
|
// node_modules/binance/lib/usdm-client.js
|
|
33846
33846
|
var require_usdm_client = __commonJS((exports) => {
|
|
33847
33847
|
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
33848
|
-
function adopt(
|
|
33849
|
-
return
|
|
33850
|
-
resolve(
|
|
33848
|
+
function adopt(value) {
|
|
33849
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
33850
|
+
resolve(value);
|
|
33851
33851
|
});
|
|
33852
33852
|
}
|
|
33853
33853
|
return new (P || (P = Promise))(function(resolve, reject) {
|
|
33854
|
-
function fulfilled(
|
|
33854
|
+
function fulfilled(value) {
|
|
33855
33855
|
try {
|
|
33856
|
-
step(generator.next(
|
|
33856
|
+
step(generator.next(value));
|
|
33857
33857
|
} catch (e2) {
|
|
33858
33858
|
reject(e2);
|
|
33859
33859
|
}
|
|
33860
33860
|
}
|
|
33861
|
-
function rejected(
|
|
33861
|
+
function rejected(value) {
|
|
33862
33862
|
try {
|
|
33863
|
-
step(generator["throw"](
|
|
33863
|
+
step(generator["throw"](value));
|
|
33864
33864
|
} catch (e2) {
|
|
33865
33865
|
reject(e2);
|
|
33866
33866
|
}
|
|
@@ -34775,35 +34775,35 @@ var require_permessage_deflate = __commonJS((exports, module) => {
|
|
|
34775
34775
|
normalizeParams(configurations) {
|
|
34776
34776
|
configurations.forEach((params) => {
|
|
34777
34777
|
Object.keys(params).forEach((key) => {
|
|
34778
|
-
let
|
|
34779
|
-
if (
|
|
34778
|
+
let value = params[key];
|
|
34779
|
+
if (value.length > 1) {
|
|
34780
34780
|
throw new Error(`Parameter "${key}" must have only a single value`);
|
|
34781
34781
|
}
|
|
34782
|
-
|
|
34782
|
+
value = value[0];
|
|
34783
34783
|
if (key === "client_max_window_bits") {
|
|
34784
|
-
if (
|
|
34785
|
-
const num = +
|
|
34784
|
+
if (value !== true) {
|
|
34785
|
+
const num = +value;
|
|
34786
34786
|
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
34787
|
-
throw new TypeError(`Invalid value for parameter "${key}": ${
|
|
34787
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
34788
34788
|
}
|
|
34789
|
-
|
|
34789
|
+
value = num;
|
|
34790
34790
|
} else if (!this._isServer) {
|
|
34791
|
-
throw new TypeError(`Invalid value for parameter "${key}": ${
|
|
34791
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
34792
34792
|
}
|
|
34793
34793
|
} else if (key === "server_max_window_bits") {
|
|
34794
|
-
const num = +
|
|
34794
|
+
const num = +value;
|
|
34795
34795
|
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
34796
|
-
throw new TypeError(`Invalid value for parameter "${key}": ${
|
|
34796
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
34797
34797
|
}
|
|
34798
|
-
|
|
34798
|
+
value = num;
|
|
34799
34799
|
} else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
|
|
34800
|
-
if (
|
|
34801
|
-
throw new TypeError(`Invalid value for parameter "${key}": ${
|
|
34800
|
+
if (value !== true) {
|
|
34801
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
34802
34802
|
}
|
|
34803
34803
|
} else {
|
|
34804
34804
|
throw new Error(`Unknown parameter "${key}"`);
|
|
34805
34805
|
}
|
|
34806
|
-
params[key] =
|
|
34806
|
+
params[key] = value;
|
|
34807
34807
|
});
|
|
34808
34808
|
});
|
|
34809
34809
|
return configurations;
|
|
@@ -35086,8 +35086,8 @@ var require_validation = __commonJS((exports, module) => {
|
|
|
35086
35086
|
}
|
|
35087
35087
|
return true;
|
|
35088
35088
|
}
|
|
35089
|
-
function isBlob(
|
|
35090
|
-
return hasBlob && typeof
|
|
35089
|
+
function isBlob(value) {
|
|
35090
|
+
return hasBlob && typeof value === "object" && typeof value.arrayBuffer === "function" && typeof value.type === "string" && typeof value.stream === "function" && (value[Symbol.toStringTag] === "Blob" || value[Symbol.toStringTag] === "File");
|
|
35091
35091
|
}
|
|
35092
35092
|
module.exports = {
|
|
35093
35093
|
isBlob,
|
|
@@ -36105,12 +36105,12 @@ var require_extension = __commonJS((exports, module) => {
|
|
|
36105
36105
|
}
|
|
36106
36106
|
if (end === -1)
|
|
36107
36107
|
end = i2;
|
|
36108
|
-
let
|
|
36108
|
+
let value = header.slice(start, end);
|
|
36109
36109
|
if (mustUnescape) {
|
|
36110
|
-
|
|
36110
|
+
value = value.replace(/\\/g, "");
|
|
36111
36111
|
mustUnescape = false;
|
|
36112
36112
|
}
|
|
36113
|
-
push(params, paramName,
|
|
36113
|
+
push(params, paramName, value);
|
|
36114
36114
|
if (code === 44) {
|
|
36115
36115
|
push(offers, extensionName, params);
|
|
36116
36116
|
params = Object.create(null);
|
|
@@ -36633,8 +36633,8 @@ var require_websocket = __commonJS((exports, module) => {
|
|
|
36633
36633
|
const headers = options && options.headers;
|
|
36634
36634
|
options = { ...options, headers: {} };
|
|
36635
36635
|
if (headers) {
|
|
36636
|
-
for (const [key2,
|
|
36637
|
-
options.headers[key2.toLowerCase()] =
|
|
36636
|
+
for (const [key2, value] of Object.entries(headers)) {
|
|
36637
|
+
options.headers[key2.toLowerCase()] = value;
|
|
36638
36638
|
}
|
|
36639
36639
|
}
|
|
36640
36640
|
} else if (websocket.listenerCount("redirect") === 0) {
|
|
@@ -37296,10 +37296,10 @@ var require_websocket_server = __commonJS((exports, module) => {
|
|
|
37296
37296
|
}
|
|
37297
37297
|
if (extensions[PerMessageDeflate.extensionName]) {
|
|
37298
37298
|
const params = extensions[PerMessageDeflate.extensionName].params;
|
|
37299
|
-
const
|
|
37299
|
+
const value = extension.format({
|
|
37300
37300
|
[PerMessageDeflate.extensionName]: [params]
|
|
37301
37301
|
});
|
|
37302
|
-
headers.push(`Sec-WebSocket-Extensions: ${
|
|
37302
|
+
headers.push(`Sec-WebSocket-Extensions: ${value}`);
|
|
37303
37303
|
ws._extensions = extensions;
|
|
37304
37304
|
}
|
|
37305
37305
|
this.emit("headers", headers, req);
|
|
@@ -37426,22 +37426,22 @@ var require_websocket_client = __commonJS((exports) => {
|
|
|
37426
37426
|
return result;
|
|
37427
37427
|
};
|
|
37428
37428
|
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
37429
|
-
function adopt(
|
|
37430
|
-
return
|
|
37431
|
-
resolve(
|
|
37429
|
+
function adopt(value) {
|
|
37430
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
37431
|
+
resolve(value);
|
|
37432
37432
|
});
|
|
37433
37433
|
}
|
|
37434
37434
|
return new (P || (P = Promise))(function(resolve, reject) {
|
|
37435
|
-
function fulfilled(
|
|
37435
|
+
function fulfilled(value) {
|
|
37436
37436
|
try {
|
|
37437
|
-
step(generator.next(
|
|
37437
|
+
step(generator.next(value));
|
|
37438
37438
|
} catch (e2) {
|
|
37439
37439
|
reject(e2);
|
|
37440
37440
|
}
|
|
37441
37441
|
}
|
|
37442
|
-
function rejected(
|
|
37442
|
+
function rejected(value) {
|
|
37443
37443
|
try {
|
|
37444
|
-
step(generator["throw"](
|
|
37444
|
+
step(generator["throw"](value));
|
|
37445
37445
|
} catch (e2) {
|
|
37446
37446
|
reject(e2);
|
|
37447
37447
|
}
|
|
@@ -37933,10 +37933,10 @@ var require_websocket_client = __commonJS((exports) => {
|
|
|
37933
37933
|
});
|
|
37934
37934
|
this.tryWsSend(wsKey, wsMessage);
|
|
37935
37935
|
}
|
|
37936
|
-
requestSetProperty(wsKey, property,
|
|
37936
|
+
requestSetProperty(wsKey, property, value, requestId) {
|
|
37937
37937
|
const wsMessage = JSON.stringify({
|
|
37938
37938
|
method: "SET_PROPERTY",
|
|
37939
|
-
params: [property,
|
|
37939
|
+
params: [property, value],
|
|
37940
37940
|
id: requestId
|
|
37941
37941
|
});
|
|
37942
37942
|
this.tryWsSend(wsKey, wsMessage);
|
|
@@ -59280,267 +59280,8 @@ class AppDatabase {
|
|
|
59280
59280
|
}
|
|
59281
59281
|
}
|
|
59282
59282
|
|
|
59283
|
-
// src/
|
|
59284
|
-
|
|
59285
|
-
let stop_percent = Math.abs(entry - stop) / entry;
|
|
59286
|
-
let size = budget / stop_percent / entry;
|
|
59287
|
-
return size;
|
|
59288
|
-
}
|
|
59289
|
-
function determine_risk(entry, stop, quantity) {
|
|
59290
|
-
let stop_percent = Math.abs(entry - stop) / entry;
|
|
59291
|
-
let risk = quantity * stop_percent * entry;
|
|
59292
|
-
return risk;
|
|
59293
|
-
}
|
|
59294
|
-
function determine_close_price(entry, pnl, quantity, kind, single = false, leverage = 1) {
|
|
59295
|
-
const dollar_value = entry / leverage;
|
|
59296
|
-
const position = dollar_value * quantity;
|
|
59297
|
-
if (position) {
|
|
59298
|
-
let percent = pnl / position;
|
|
59299
|
-
let difference = position * percent / quantity;
|
|
59300
|
-
let result;
|
|
59301
|
-
if (kind === "long") {
|
|
59302
|
-
result = difference + entry;
|
|
59303
|
-
} else {
|
|
59304
|
-
result = entry - difference;
|
|
59305
|
-
}
|
|
59306
|
-
if (single) {
|
|
59307
|
-
return result;
|
|
59308
|
-
}
|
|
59309
|
-
return result;
|
|
59310
|
-
}
|
|
59311
|
-
return 0;
|
|
59312
|
-
}
|
|
59313
|
-
function determine_amount_to_sell(entry, quantity, sell_price, pnl, kind, places = "%.3f") {
|
|
59314
|
-
const _pnl = determine_pnl(entry, sell_price, quantity, kind);
|
|
59315
|
-
const ratio = pnl / to_f(Math.abs(_pnl), places);
|
|
59316
|
-
quantity = quantity * ratio;
|
|
59317
|
-
return to_f(quantity, places);
|
|
59318
|
-
}
|
|
59319
|
-
function determine_pnl(entry, close_price, quantity, kind, contract_size, places = "%.2f") {
|
|
59320
|
-
if (contract_size) {
|
|
59321
|
-
const direction = kind === "long" ? 1 : -1;
|
|
59322
|
-
return quantity * contract_size * direction * (1 / entry - 1 / close_price);
|
|
59323
|
-
}
|
|
59324
|
-
let difference = entry - close_price;
|
|
59325
|
-
if (kind === "long") {
|
|
59326
|
-
difference = close_price - entry;
|
|
59327
|
-
}
|
|
59328
|
-
return to_f(difference * quantity, places);
|
|
59329
|
-
}
|
|
59330
|
-
function position(entry, quantity, kind, leverage = 1) {
|
|
59331
|
-
const direction = { long: 1, short: -1 };
|
|
59332
|
-
return parseFloat((direction[kind] * quantity * (entry / leverage)).toFixed(3));
|
|
59333
|
-
}
|
|
59334
|
-
function to_f(value, places) {
|
|
59335
|
-
if (value) {
|
|
59336
|
-
let pp = parseInt(places.replace("%.", "").replace("f", ""));
|
|
59337
|
-
return parseFloat(value.toFixed(pp));
|
|
59338
|
-
}
|
|
59339
|
-
return value;
|
|
59340
|
-
}
|
|
59341
|
-
var value = {
|
|
59342
|
-
determine_risk,
|
|
59343
|
-
determine_position_size,
|
|
59344
|
-
determine_close_price,
|
|
59345
|
-
determine_pnl,
|
|
59346
|
-
position,
|
|
59347
|
-
determine_amount_to_sell,
|
|
59348
|
-
to_f
|
|
59349
|
-
};
|
|
59350
|
-
var pnl_default = value;
|
|
59351
|
-
|
|
59352
|
-
// src/helpers/trade_utils.ts
|
|
59353
|
-
function to_f2(value2, places = "%.1f") {
|
|
59354
|
-
let v = typeof value2 === "string" ? parseFloat(value2) : value2;
|
|
59355
|
-
const formattedValue = places.replace("%.", "").replace("f", "");
|
|
59356
|
-
return parseFloat(v.toFixed(parseInt(formattedValue)));
|
|
59357
|
-
}
|
|
59358
|
-
function determine_amount_to_sell2(entry, quantity, sell_price, pnl, kind, places = "%.3f") {
|
|
59359
|
-
const _pnl = determine_pnl2(entry, sell_price, quantity, kind);
|
|
59360
|
-
const ratio = pnl / to_f2(Math.abs(_pnl), places);
|
|
59361
|
-
quantity = quantity * ratio;
|
|
59362
|
-
return to_f2(quantity, places);
|
|
59363
|
-
}
|
|
59364
|
-
function determine_position_size2({
|
|
59365
|
-
entry,
|
|
59366
|
-
stop,
|
|
59367
|
-
budget,
|
|
59368
|
-
percent,
|
|
59369
|
-
min_size,
|
|
59370
|
-
notional_value,
|
|
59371
|
-
as_coin = true,
|
|
59372
|
-
places = "%.3f"
|
|
59373
|
-
}) {
|
|
59374
|
-
let stop_percent = stop ? Math.abs(entry - stop) / entry : percent;
|
|
59375
|
-
if (stop_percent && budget) {
|
|
59376
|
-
let size = budget / stop_percent;
|
|
59377
|
-
let notion_value = size * entry;
|
|
59378
|
-
if (notional_value && notional_value > notion_value) {
|
|
59379
|
-
size = notional_value / entry;
|
|
59380
|
-
}
|
|
59381
|
-
if (as_coin) {
|
|
59382
|
-
size = size / entry;
|
|
59383
|
-
if (min_size && min_size === 1) {
|
|
59384
|
-
return to_f2(Math.round(size), places);
|
|
59385
|
-
}
|
|
59386
|
-
}
|
|
59387
|
-
return to_f2(size, places);
|
|
59388
|
-
}
|
|
59389
|
-
return;
|
|
59390
|
-
}
|
|
59391
|
-
function determine_average_entry_and_size(orders, places = "%.3f", price_places = "%.1f") {
|
|
59392
|
-
const sum_values = orders.reduce((sum, order) => sum + order.price * order.quantity, 0);
|
|
59393
|
-
const total_quantity = orders.reduce((sum, order) => sum + order.quantity, 0);
|
|
59394
|
-
const avg_price = total_quantity ? to_f2(sum_values / total_quantity, price_places) : 0;
|
|
59395
|
-
return {
|
|
59396
|
-
entry: avg_price,
|
|
59397
|
-
price: avg_price,
|
|
59398
|
-
quantity: to_f2(total_quantity, places)
|
|
59399
|
-
};
|
|
59400
|
-
}
|
|
59401
|
-
var createArray = (start, stop, step) => {
|
|
59402
|
-
const result = [];
|
|
59403
|
-
let current = start;
|
|
59404
|
-
while (current <= stop) {
|
|
59405
|
-
result.push(current);
|
|
59406
|
-
current += step;
|
|
59407
|
-
}
|
|
59408
|
-
return result;
|
|
59409
|
-
};
|
|
59410
|
-
var groupIntoPairsWithSumLessThan = (arr, targetSum, key = "quantity", firstSize = 0) => {
|
|
59411
|
-
if (firstSize) {
|
|
59412
|
-
const totalSize = arr.reduce((sum, order) => sum + order[key], 0);
|
|
59413
|
-
const remainingSize = totalSize - firstSize;
|
|
59414
|
-
let newSum = 0;
|
|
59415
|
-
let newArray = [];
|
|
59416
|
-
let lastIndex = 0;
|
|
59417
|
-
for (let i2 = 0;i2 < arr.length; i2++) {
|
|
59418
|
-
if (newSum < remainingSize) {
|
|
59419
|
-
newSum += arr[i2][key];
|
|
59420
|
-
newArray.push(arr[i2]);
|
|
59421
|
-
lastIndex = i2;
|
|
59422
|
-
}
|
|
59423
|
-
}
|
|
59424
|
-
const lastGroup = arr.slice(lastIndex + 1);
|
|
59425
|
-
const previousPair = groupInPairs(newArray, key, targetSum);
|
|
59426
|
-
if (lastGroup.length > 0) {
|
|
59427
|
-
previousPair.push(lastGroup);
|
|
59428
|
-
}
|
|
59429
|
-
return previousPair;
|
|
59430
|
-
}
|
|
59431
|
-
return groupInPairs(arr, key, targetSum);
|
|
59432
|
-
};
|
|
59433
|
-
function groupInPairs(_arr, key, targetSum) {
|
|
59434
|
-
const result = [];
|
|
59435
|
-
let currentSum = 0;
|
|
59436
|
-
let currentGroup = [];
|
|
59437
|
-
for (let i2 = 0;i2 < _arr.length; i2++) {
|
|
59438
|
-
currentSum += _arr[i2][key];
|
|
59439
|
-
currentGroup.push(_arr[i2]);
|
|
59440
|
-
if (currentSum >= targetSum) {
|
|
59441
|
-
result.push(currentGroup);
|
|
59442
|
-
currentGroup = [];
|
|
59443
|
-
currentSum = 0;
|
|
59444
|
-
}
|
|
59445
|
-
}
|
|
59446
|
-
return result;
|
|
59447
|
-
}
|
|
59448
|
-
var computeTotalAverageForEachTrade = (trades, config2) => {
|
|
59449
|
-
let _take_profit = config2.take_profit;
|
|
59450
|
-
let kind = config2.kind;
|
|
59451
|
-
let entryToUse = kind === "short" ? Math.min(config2.entry, config2.stop) : Math.max(config2.entry, config2.stop);
|
|
59452
|
-
let _currentEntry = config2.currentEntry || entryToUse;
|
|
59453
|
-
let less = trades.filter((p) => kind === "long" ? p.entry <= _currentEntry : p.entry >= _currentEntry);
|
|
59454
|
-
let rrr = trades.map((r2, i2) => {
|
|
59455
|
-
let considered = [];
|
|
59456
|
-
if (kind === "long") {
|
|
59457
|
-
considered = trades.filter((p) => p.entry > _currentEntry);
|
|
59458
|
-
} else {
|
|
59459
|
-
considered = trades.filter((p) => p.entry < _currentEntry);
|
|
59460
|
-
}
|
|
59461
|
-
const x_pnl = 0;
|
|
59462
|
-
const remaining = less.filter((o) => {
|
|
59463
|
-
if (kind === "long") {
|
|
59464
|
-
return o.entry >= r2.entry;
|
|
59465
|
-
}
|
|
59466
|
-
return o.entry <= r2.entry;
|
|
59467
|
-
});
|
|
59468
|
-
if (remaining.length === 0) {
|
|
59469
|
-
return { ...r2, pnl: x_pnl };
|
|
59470
|
-
}
|
|
59471
|
-
const start = kind === "long" ? Math.max(...remaining.map((o) => o.entry)) : Math.min(...remaining.map((o) => o.entry));
|
|
59472
|
-
considered = considered.map((o) => ({ ...o, entry: start }));
|
|
59473
|
-
considered = considered.concat(remaining);
|
|
59474
|
-
let avg_entry = determine_average_entry_and_size([
|
|
59475
|
-
...considered.map((o) => ({
|
|
59476
|
-
price: o.entry,
|
|
59477
|
-
quantity: o.quantity
|
|
59478
|
-
})),
|
|
59479
|
-
{
|
|
59480
|
-
price: _currentEntry,
|
|
59481
|
-
quantity: config2.currentQty || 0
|
|
59482
|
-
}
|
|
59483
|
-
], config2.decimal_places, config2.price_places);
|
|
59484
|
-
let _pnl = r2.pnl;
|
|
59485
|
-
let sell_price = r2.sell_price;
|
|
59486
|
-
let entry_pnl = r2.pnl;
|
|
59487
|
-
if (_take_profit) {
|
|
59488
|
-
_pnl = pnl_default.determine_pnl(avg_entry.price, _take_profit, avg_entry.quantity, kind);
|
|
59489
|
-
sell_price = _take_profit;
|
|
59490
|
-
entry_pnl = pnl_default.determine_pnl(r2.entry, _take_profit, avg_entry.quantity, kind);
|
|
59491
|
-
}
|
|
59492
|
-
const loss = pnl_default.determine_pnl(avg_entry.price, r2.stop, avg_entry.quantity, kind);
|
|
59493
|
-
let new_stop = r2.new_stop;
|
|
59494
|
-
const entry_loss = pnl_default.determine_pnl(r2.entry, new_stop, avg_entry.quantity, kind);
|
|
59495
|
-
let min_profit = 0;
|
|
59496
|
-
let min_entry_profit = 0;
|
|
59497
|
-
if (config2.min_profit) {
|
|
59498
|
-
min_profit = pnl_default.determine_close_price(avg_entry.price, config2.min_profit, avg_entry.quantity, kind);
|
|
59499
|
-
min_entry_profit = pnl_default.determine_close_price(r2.entry, config2.min_profit, avg_entry.quantity, kind);
|
|
59500
|
-
}
|
|
59501
|
-
let x_fee = r2.fee;
|
|
59502
|
-
if (config2.fee) {
|
|
59503
|
-
x_fee = config2.fee * r2.stop * avg_entry.quantity;
|
|
59504
|
-
}
|
|
59505
|
-
let tp_close = pnl_default.determine_close_price(r2.entry, Math.abs(entry_loss) * (config2.rr || 1) + x_fee, avg_entry.quantity, kind);
|
|
59506
|
-
return {
|
|
59507
|
-
...r2,
|
|
59508
|
-
x_fee: to_f2(x_fee, "%.2f"),
|
|
59509
|
-
avg_entry: avg_entry.price,
|
|
59510
|
-
avg_size: avg_entry.quantity,
|
|
59511
|
-
entry_pnl: to_f2(entry_pnl, "%.2f"),
|
|
59512
|
-
entry_loss: to_f2(entry_loss, "%.2f"),
|
|
59513
|
-
min_entry_pnl: to_f2(min_entry_profit, "%.2f"),
|
|
59514
|
-
pnl: _pnl,
|
|
59515
|
-
neg_pnl: to_f2(loss, "%.2f"),
|
|
59516
|
-
sell_price,
|
|
59517
|
-
close_p: to_f2(tp_close, "%.2f"),
|
|
59518
|
-
min_pnl: to_f2(min_profit, "%.2f"),
|
|
59519
|
-
new_stop
|
|
59520
|
-
};
|
|
59521
|
-
});
|
|
59522
|
-
return rrr;
|
|
59523
|
-
};
|
|
59524
|
-
function createGapPairs(arr, gap, item) {
|
|
59525
|
-
if (arr.length === 0) {
|
|
59526
|
-
return [];
|
|
59527
|
-
}
|
|
59528
|
-
const result = [];
|
|
59529
|
-
const firstElement = arr[0];
|
|
59530
|
-
for (let i2 = arr.length - 1;i2 >= 0; i2--) {
|
|
59531
|
-
const current = arr[i2];
|
|
59532
|
-
const gapIndex = i2 - gap;
|
|
59533
|
-
const pairedElement = gapIndex < 0 ? firstElement : arr[gapIndex];
|
|
59534
|
-
if (current !== pairedElement) {
|
|
59535
|
-
result.push([current, pairedElement]);
|
|
59536
|
-
}
|
|
59537
|
-
}
|
|
59538
|
-
if (item) {
|
|
59539
|
-
let r2 = result.find((o) => o[0] === item);
|
|
59540
|
-
return r2 ? [r2] : [];
|
|
59541
|
-
}
|
|
59542
|
-
return result;
|
|
59543
|
-
}
|
|
59283
|
+
// src/exchanges/binance/index.ts
|
|
59284
|
+
var import_binance = __toESM(require_lib2(), 1);
|
|
59544
59285
|
|
|
59545
59286
|
// src/helpers/optimizations.ts
|
|
59546
59287
|
function calculateTheoreticalKelly({
|
|
@@ -59577,7 +59318,7 @@ function calculateTheoreticalKelly({
|
|
|
59577
59318
|
kelly_fraction *= vol_adjustment;
|
|
59578
59319
|
}
|
|
59579
59320
|
kelly_fraction = Math.max(0.005, Math.min(kelly_fraction, 0.5));
|
|
59580
|
-
return
|
|
59321
|
+
return to_f(kelly_fraction, "%.4f");
|
|
59581
59322
|
}
|
|
59582
59323
|
function calculateZoneProbabilities({
|
|
59583
59324
|
current_entry,
|
|
@@ -59686,7 +59427,7 @@ function calculateTheoreticalKellyFixed({
|
|
|
59686
59427
|
kelly_fraction *= vol_adjustment;
|
|
59687
59428
|
}
|
|
59688
59429
|
kelly_fraction = Math.max(0.005, Math.min(kelly_fraction, 0.5));
|
|
59689
|
-
return
|
|
59430
|
+
return to_f(kelly_fraction, "%.4f");
|
|
59690
59431
|
}
|
|
59691
59432
|
function calculatePositionBasedKelly({
|
|
59692
59433
|
current_entry,
|
|
@@ -59720,11 +59461,11 @@ function calculatePositionBasedKelly({
|
|
|
59720
59461
|
const base_kelly = 0.02;
|
|
59721
59462
|
const max_kelly = 0.2;
|
|
59722
59463
|
const kelly_fraction = base_kelly + adjusted_score * (max_kelly - base_kelly);
|
|
59723
|
-
return
|
|
59464
|
+
return to_f(kelly_fraction, "%.4f");
|
|
59724
59465
|
}
|
|
59725
59466
|
|
|
59726
59467
|
// src/helpers/trade_signal.ts
|
|
59727
|
-
function
|
|
59468
|
+
function determine_close_price({
|
|
59728
59469
|
entry,
|
|
59729
59470
|
pnl,
|
|
59730
59471
|
quantity,
|
|
@@ -59732,16 +59473,16 @@ function determine_close_price2({
|
|
|
59732
59473
|
kind = "long"
|
|
59733
59474
|
}) {
|
|
59734
59475
|
const dollar_value = entry / leverage;
|
|
59735
|
-
const
|
|
59736
|
-
if (
|
|
59737
|
-
const percent = pnl /
|
|
59738
|
-
const difference =
|
|
59476
|
+
const position = dollar_value * quantity;
|
|
59477
|
+
if (position) {
|
|
59478
|
+
const percent = pnl / position;
|
|
59479
|
+
const difference = position * percent / quantity;
|
|
59739
59480
|
const result = kind === "long" ? difference + entry : entry - difference;
|
|
59740
59481
|
return result;
|
|
59741
59482
|
}
|
|
59742
59483
|
return 0;
|
|
59743
59484
|
}
|
|
59744
|
-
function
|
|
59485
|
+
function determine_pnl(entry, close_price, quantity, kind = "long", contract_size) {
|
|
59745
59486
|
if (contract_size) {
|
|
59746
59487
|
const direction = kind === "long" ? 1 : -1;
|
|
59747
59488
|
return quantity * contract_size * direction * (1 / entry - 1 / close_price);
|
|
@@ -59760,7 +59501,7 @@ function* _get_zones({
|
|
|
59760
59501
|
let focus_low = last * Math.pow(1 + percent_change, -1);
|
|
59761
59502
|
if (focus_high > current_price) {
|
|
59762
59503
|
while (focus_high > current_price) {
|
|
59763
|
-
yield
|
|
59504
|
+
yield to_f(last, places);
|
|
59764
59505
|
focus_high = last;
|
|
59765
59506
|
last = focus_high * Math.pow(1 + percent_change, -1);
|
|
59766
59507
|
focus_low = last * Math.pow(1 + percent_change, -1);
|
|
@@ -59768,14 +59509,14 @@ function* _get_zones({
|
|
|
59768
59509
|
} else {
|
|
59769
59510
|
if (focus_high <= current_price) {
|
|
59770
59511
|
while (focus_high <= current_price) {
|
|
59771
|
-
yield
|
|
59512
|
+
yield to_f(focus_high, places);
|
|
59772
59513
|
focus_low = focus_high;
|
|
59773
59514
|
last = focus_low * (1 + percent_change);
|
|
59774
59515
|
focus_high = last * (1 + percent_change);
|
|
59775
59516
|
}
|
|
59776
59517
|
} else {
|
|
59777
59518
|
while (focus_low <= current_price) {
|
|
59778
|
-
yield
|
|
59519
|
+
yield to_f(focus_high, places);
|
|
59779
59520
|
focus_low = focus_high;
|
|
59780
59521
|
last = focus_low * (1 + percent_change);
|
|
59781
59522
|
focus_high = last * (1 + percent_change);
|
|
@@ -60054,7 +59795,7 @@ class Signal {
|
|
|
60054
59795
|
} else {
|
|
60055
59796
|
i2["risk_sell"] = Math.min(...potentials.slice(0, max_index));
|
|
60056
59797
|
}
|
|
60057
|
-
i2["pnl"] = this.to_df(
|
|
59798
|
+
i2["pnl"] = this.to_df(determine_pnl(i2["entry"], i2["risk_sell"], i2["quantity"], kind));
|
|
60058
59799
|
}
|
|
60059
59800
|
}
|
|
60060
59801
|
}
|
|
@@ -60118,13 +59859,13 @@ class Signal {
|
|
|
60118
59859
|
let remaining_zones = margin_zones.filter((x) => JSON.stringify(x) != JSON.stringify(margin_range));
|
|
60119
59860
|
if (margin_range) {
|
|
60120
59861
|
const difference = Math.abs(margin_range[0] - margin_range[1]);
|
|
60121
|
-
const spread =
|
|
59862
|
+
const spread = to_f(difference / this.risk_reward, this.price_places);
|
|
60122
59863
|
let entries;
|
|
60123
59864
|
const percent_change = this.percent_change / this.risk_reward;
|
|
60124
59865
|
if (kind === "long") {
|
|
60125
|
-
entries = Array.from({ length: Math.floor(this.risk_reward) + 1 }, (_, x) =>
|
|
59866
|
+
entries = Array.from({ length: Math.floor(this.risk_reward) + 1 }, (_, x) => to_f(margin_range[1] - spread * x, this.price_places));
|
|
60126
59867
|
} else {
|
|
60127
|
-
entries = Array.from({ length: Math.floor(this.risk_reward) + 1 }, (_, x) =>
|
|
59868
|
+
entries = Array.from({ length: Math.floor(this.risk_reward) + 1 }, (_, x) => to_f(margin_range[1] * Math.pow(1 + percent_change, x), this.price_places));
|
|
60128
59869
|
}
|
|
60129
59870
|
if (Math.min(...entries) < this.to_f(current_price) && this.to_f(current_price) < Math.max(...entries)) {
|
|
60130
59871
|
return entries.sort((a, b) => a - b);
|
|
@@ -60136,14 +59877,14 @@ class Signal {
|
|
|
60136
59877
|
if (new_range) {
|
|
60137
59878
|
while (entries2.length < this.risk_reward + 1) {
|
|
60138
59879
|
if (kind === "long") {
|
|
60139
|
-
let
|
|
60140
|
-
if (
|
|
60141
|
-
entries2.push(
|
|
59880
|
+
let value = this.to_f(new_range[1] - spread * x);
|
|
59881
|
+
if (value <= current_price) {
|
|
59882
|
+
entries2.push(value);
|
|
60142
59883
|
}
|
|
60143
59884
|
} else {
|
|
60144
|
-
let
|
|
60145
|
-
if (
|
|
60146
|
-
entries2.push(
|
|
59885
|
+
let value = this.to_f(new_range[1] * Math.pow(1 + percent_change, x));
|
|
59886
|
+
if (value >= current_price) {
|
|
59887
|
+
entries2.push(value);
|
|
60147
59888
|
}
|
|
60148
59889
|
}
|
|
60149
59890
|
x += 1;
|
|
@@ -60157,14 +59898,14 @@ class Signal {
|
|
|
60157
59898
|
let x = 0;
|
|
60158
59899
|
while (entries2.length < this.risk_reward + 1) {
|
|
60159
59900
|
if (kind === "long") {
|
|
60160
|
-
let
|
|
60161
|
-
if (
|
|
60162
|
-
entries2.push(
|
|
59901
|
+
let value = this.to_f(next_focus - spread * x);
|
|
59902
|
+
if (value <= this.to_f(current_price)) {
|
|
59903
|
+
entries2.push(value);
|
|
60163
59904
|
}
|
|
60164
59905
|
} else {
|
|
60165
|
-
let
|
|
60166
|
-
if (
|
|
60167
|
-
entries2.push(
|
|
59906
|
+
let value = this.to_f(next_focus * Math.pow(1 + percent_change, x));
|
|
59907
|
+
if (value >= this.to_f(current_price)) {
|
|
59908
|
+
entries2.push(value);
|
|
60168
59909
|
}
|
|
60169
59910
|
}
|
|
60170
59911
|
x += 1;
|
|
@@ -60175,8 +59916,8 @@ class Signal {
|
|
|
60175
59916
|
}
|
|
60176
59917
|
return [];
|
|
60177
59918
|
}
|
|
60178
|
-
to_f(
|
|
60179
|
-
return
|
|
59919
|
+
to_f(value, places) {
|
|
59920
|
+
return to_f(value, places || this.price_places);
|
|
60180
59921
|
}
|
|
60181
59922
|
get_margin_zones({
|
|
60182
59923
|
current_price,
|
|
@@ -60394,7 +60135,7 @@ class Signal {
|
|
|
60394
60135
|
}) {
|
|
60395
60136
|
const considered = arr.map((x, i2) => i2).filter((i2) => i2 > index);
|
|
60396
60137
|
const with_quantity = considered.map((x) => {
|
|
60397
|
-
const q =
|
|
60138
|
+
const q = determine_position_size({
|
|
60398
60139
|
entry: arr[x],
|
|
60399
60140
|
stop: arr[x - 1],
|
|
60400
60141
|
budget: risk,
|
|
@@ -60428,7 +60169,7 @@ class Signal {
|
|
|
60428
60169
|
const incurred_fees = fees.reduce((a, b) => a + b, 0) + previous_risks.reduce((a, b) => a + b, 0);
|
|
60429
60170
|
if (index === 0) {
|
|
60430
60171
|
}
|
|
60431
|
-
let quantity =
|
|
60172
|
+
let quantity = determine_position_size({
|
|
60432
60173
|
entry,
|
|
60433
60174
|
stop,
|
|
60434
60175
|
budget: risk,
|
|
@@ -60440,7 +60181,7 @@ class Signal {
|
|
|
60440
60181
|
}
|
|
60441
60182
|
if (this.increase_size) {
|
|
60442
60183
|
quantity = quantity * multiplier;
|
|
60443
|
-
const new_risk =
|
|
60184
|
+
const new_risk = determine_pnl(entry, stop, quantity, kind);
|
|
60444
60185
|
risk = Math.abs(new_risk);
|
|
60445
60186
|
}
|
|
60446
60187
|
const fee = this.to_df(this.fee * quantity * entry);
|
|
@@ -60449,12 +60190,12 @@ class Signal {
|
|
|
60449
60190
|
if (this.minimum_pnl) {
|
|
60450
60191
|
pnl = this.minimum_pnl + fee;
|
|
60451
60192
|
}
|
|
60452
|
-
let sell_price =
|
|
60193
|
+
let sell_price = determine_close_price({ entry, pnl, quantity, kind });
|
|
60453
60194
|
if (take_profit && !this.minimum_pnl) {
|
|
60454
60195
|
sell_price = take_profit;
|
|
60455
|
-
pnl = this.to_df(
|
|
60196
|
+
pnl = this.to_df(determine_pnl(entry, sell_price, quantity, kind));
|
|
60456
60197
|
pnl = pnl + fee;
|
|
60457
|
-
sell_price =
|
|
60198
|
+
sell_price = determine_close_price({ entry, pnl, quantity, kind });
|
|
60458
60199
|
}
|
|
60459
60200
|
let risk_sell = sell_price;
|
|
60460
60201
|
return {
|
|
@@ -60472,10 +60213,271 @@ class Signal {
|
|
|
60472
60213
|
};
|
|
60473
60214
|
}
|
|
60474
60215
|
to_df(currentPrice, places = "%.3f") {
|
|
60475
|
-
return
|
|
60216
|
+
return to_f(currentPrice, places);
|
|
60217
|
+
}
|
|
60218
|
+
}
|
|
60219
|
+
|
|
60220
|
+
// src/helpers/pnl.ts
|
|
60221
|
+
function determine_position_size2(entry, stop, budget) {
|
|
60222
|
+
let stop_percent = Math.abs(entry - stop) / entry;
|
|
60223
|
+
let size = budget / stop_percent / entry;
|
|
60224
|
+
return size;
|
|
60225
|
+
}
|
|
60226
|
+
function determine_risk(entry, stop, quantity) {
|
|
60227
|
+
let stop_percent = Math.abs(entry - stop) / entry;
|
|
60228
|
+
let risk = quantity * stop_percent * entry;
|
|
60229
|
+
return risk;
|
|
60230
|
+
}
|
|
60231
|
+
function determine_close_price2(entry, pnl, quantity, kind, single = false, leverage = 1) {
|
|
60232
|
+
const dollar_value = entry / leverage;
|
|
60233
|
+
const position = dollar_value * quantity;
|
|
60234
|
+
if (position) {
|
|
60235
|
+
let percent = pnl / position;
|
|
60236
|
+
let difference = position * percent / quantity;
|
|
60237
|
+
let result;
|
|
60238
|
+
if (kind === "long") {
|
|
60239
|
+
result = difference + entry;
|
|
60240
|
+
} else {
|
|
60241
|
+
result = entry - difference;
|
|
60242
|
+
}
|
|
60243
|
+
if (single) {
|
|
60244
|
+
return result;
|
|
60245
|
+
}
|
|
60246
|
+
return result;
|
|
60247
|
+
}
|
|
60248
|
+
return 0;
|
|
60249
|
+
}
|
|
60250
|
+
function determine_amount_to_sell(entry, quantity, sell_price, pnl, kind, places = "%.3f") {
|
|
60251
|
+
const _pnl = determine_pnl2(entry, sell_price, quantity, kind);
|
|
60252
|
+
const ratio = pnl / to_f2(Math.abs(_pnl), places);
|
|
60253
|
+
quantity = quantity * ratio;
|
|
60254
|
+
return to_f2(quantity, places);
|
|
60255
|
+
}
|
|
60256
|
+
function determine_pnl2(entry, close_price, quantity, kind, contract_size, places = "%.2f") {
|
|
60257
|
+
if (contract_size) {
|
|
60258
|
+
const direction = kind === "long" ? 1 : -1;
|
|
60259
|
+
return quantity * contract_size * direction * (1 / entry - 1 / close_price);
|
|
60260
|
+
}
|
|
60261
|
+
let difference = entry - close_price;
|
|
60262
|
+
if (kind === "long") {
|
|
60263
|
+
difference = close_price - entry;
|
|
60264
|
+
}
|
|
60265
|
+
return to_f2(difference * quantity, places);
|
|
60266
|
+
}
|
|
60267
|
+
function position(entry, quantity, kind, leverage = 1) {
|
|
60268
|
+
const direction = { long: 1, short: -1 };
|
|
60269
|
+
return parseFloat((direction[kind] * quantity * (entry / leverage)).toFixed(3));
|
|
60270
|
+
}
|
|
60271
|
+
function to_f2(value, places) {
|
|
60272
|
+
if (value) {
|
|
60273
|
+
let pp = parseInt(places.replace("%.", "").replace("f", ""));
|
|
60274
|
+
return parseFloat(value.toFixed(pp));
|
|
60476
60275
|
}
|
|
60276
|
+
return value;
|
|
60477
60277
|
}
|
|
60278
|
+
var value = {
|
|
60279
|
+
determine_risk,
|
|
60280
|
+
determine_position_size: determine_position_size2,
|
|
60281
|
+
determine_close_price: determine_close_price2,
|
|
60282
|
+
determine_pnl: determine_pnl2,
|
|
60283
|
+
position,
|
|
60284
|
+
determine_amount_to_sell,
|
|
60285
|
+
to_f: to_f2
|
|
60286
|
+
};
|
|
60287
|
+
var pnl_default = value;
|
|
60478
60288
|
|
|
60289
|
+
// src/helpers/trade_utils.ts
|
|
60290
|
+
function to_f(value2, places = "%.1f") {
|
|
60291
|
+
let v = typeof value2 === "string" ? parseFloat(value2) : value2;
|
|
60292
|
+
const formattedValue = places.replace("%.", "").replace("f", "");
|
|
60293
|
+
return parseFloat(v.toFixed(parseInt(formattedValue)));
|
|
60294
|
+
}
|
|
60295
|
+
function determine_amount_to_sell2(entry, quantity, sell_price, pnl, kind, places = "%.3f") {
|
|
60296
|
+
const _pnl = determine_pnl(entry, sell_price, quantity, kind);
|
|
60297
|
+
const ratio = pnl / to_f(Math.abs(_pnl), places);
|
|
60298
|
+
quantity = quantity * ratio;
|
|
60299
|
+
return to_f(quantity, places);
|
|
60300
|
+
}
|
|
60301
|
+
function determine_position_size({
|
|
60302
|
+
entry,
|
|
60303
|
+
stop,
|
|
60304
|
+
budget,
|
|
60305
|
+
percent,
|
|
60306
|
+
min_size,
|
|
60307
|
+
notional_value,
|
|
60308
|
+
as_coin = true,
|
|
60309
|
+
places = "%.3f"
|
|
60310
|
+
}) {
|
|
60311
|
+
let stop_percent = stop ? Math.abs(entry - stop) / entry : percent;
|
|
60312
|
+
if (stop_percent && budget) {
|
|
60313
|
+
let size = budget / stop_percent;
|
|
60314
|
+
let notion_value = size * entry;
|
|
60315
|
+
if (notional_value && notional_value > notion_value) {
|
|
60316
|
+
size = notional_value / entry;
|
|
60317
|
+
}
|
|
60318
|
+
if (as_coin) {
|
|
60319
|
+
size = size / entry;
|
|
60320
|
+
if (min_size && min_size === 1) {
|
|
60321
|
+
return to_f(Math.round(size), places);
|
|
60322
|
+
}
|
|
60323
|
+
}
|
|
60324
|
+
return to_f(size, places);
|
|
60325
|
+
}
|
|
60326
|
+
return;
|
|
60327
|
+
}
|
|
60328
|
+
function determine_average_entry_and_size(orders, places = "%.3f", price_places = "%.1f") {
|
|
60329
|
+
const sum_values = orders.reduce((sum, order) => sum + order.price * order.quantity, 0);
|
|
60330
|
+
const total_quantity = orders.reduce((sum, order) => sum + order.quantity, 0);
|
|
60331
|
+
const avg_price = total_quantity ? to_f(sum_values / total_quantity, price_places) : 0;
|
|
60332
|
+
return {
|
|
60333
|
+
entry: avg_price,
|
|
60334
|
+
price: avg_price,
|
|
60335
|
+
quantity: to_f(total_quantity, places)
|
|
60336
|
+
};
|
|
60337
|
+
}
|
|
60338
|
+
var createArray = (start, stop, step) => {
|
|
60339
|
+
const result = [];
|
|
60340
|
+
let current = start;
|
|
60341
|
+
while (current <= stop) {
|
|
60342
|
+
result.push(current);
|
|
60343
|
+
current += step;
|
|
60344
|
+
}
|
|
60345
|
+
return result;
|
|
60346
|
+
};
|
|
60347
|
+
var groupIntoPairsWithSumLessThan = (arr, targetSum, key = "quantity", firstSize = 0) => {
|
|
60348
|
+
if (firstSize) {
|
|
60349
|
+
const totalSize = arr.reduce((sum, order) => sum + order[key], 0);
|
|
60350
|
+
const remainingSize = totalSize - firstSize;
|
|
60351
|
+
let newSum = 0;
|
|
60352
|
+
let newArray = [];
|
|
60353
|
+
let lastIndex = 0;
|
|
60354
|
+
for (let i2 = 0;i2 < arr.length; i2++) {
|
|
60355
|
+
if (newSum < remainingSize) {
|
|
60356
|
+
newSum += arr[i2][key];
|
|
60357
|
+
newArray.push(arr[i2]);
|
|
60358
|
+
lastIndex = i2;
|
|
60359
|
+
}
|
|
60360
|
+
}
|
|
60361
|
+
const lastGroup = arr.slice(lastIndex + 1);
|
|
60362
|
+
const previousPair = groupInPairs(newArray, key, targetSum);
|
|
60363
|
+
if (lastGroup.length > 0) {
|
|
60364
|
+
previousPair.push(lastGroup);
|
|
60365
|
+
}
|
|
60366
|
+
return previousPair;
|
|
60367
|
+
}
|
|
60368
|
+
return groupInPairs(arr, key, targetSum);
|
|
60369
|
+
};
|
|
60370
|
+
function groupInPairs(_arr, key, targetSum) {
|
|
60371
|
+
const result = [];
|
|
60372
|
+
let currentSum = 0;
|
|
60373
|
+
let currentGroup = [];
|
|
60374
|
+
for (let i2 = 0;i2 < _arr.length; i2++) {
|
|
60375
|
+
currentSum += _arr[i2][key];
|
|
60376
|
+
currentGroup.push(_arr[i2]);
|
|
60377
|
+
if (currentSum >= targetSum) {
|
|
60378
|
+
result.push(currentGroup);
|
|
60379
|
+
currentGroup = [];
|
|
60380
|
+
currentSum = 0;
|
|
60381
|
+
}
|
|
60382
|
+
}
|
|
60383
|
+
return result;
|
|
60384
|
+
}
|
|
60385
|
+
var computeTotalAverageForEachTrade = (trades, config2) => {
|
|
60386
|
+
let _take_profit = config2.take_profit;
|
|
60387
|
+
let kind = config2.kind;
|
|
60388
|
+
let entryToUse = kind === "short" ? Math.min(config2.entry, config2.stop) : Math.max(config2.entry, config2.stop);
|
|
60389
|
+
let _currentEntry = config2.currentEntry || entryToUse;
|
|
60390
|
+
let less = trades.filter((p) => kind === "long" ? p.entry <= _currentEntry : p.entry >= _currentEntry);
|
|
60391
|
+
let rrr = trades.map((r2, i2) => {
|
|
60392
|
+
let considered = [];
|
|
60393
|
+
if (kind === "long") {
|
|
60394
|
+
considered = trades.filter((p) => p.entry > _currentEntry);
|
|
60395
|
+
} else {
|
|
60396
|
+
considered = trades.filter((p) => p.entry < _currentEntry);
|
|
60397
|
+
}
|
|
60398
|
+
const x_pnl = 0;
|
|
60399
|
+
const remaining = less.filter((o) => {
|
|
60400
|
+
if (kind === "long") {
|
|
60401
|
+
return o.entry >= r2.entry;
|
|
60402
|
+
}
|
|
60403
|
+
return o.entry <= r2.entry;
|
|
60404
|
+
});
|
|
60405
|
+
if (remaining.length === 0) {
|
|
60406
|
+
return { ...r2, pnl: x_pnl };
|
|
60407
|
+
}
|
|
60408
|
+
const start = kind === "long" ? Math.max(...remaining.map((o) => o.entry)) : Math.min(...remaining.map((o) => o.entry));
|
|
60409
|
+
considered = considered.map((o) => ({ ...o, entry: start }));
|
|
60410
|
+
considered = considered.concat(remaining);
|
|
60411
|
+
let avg_entry = determine_average_entry_and_size([
|
|
60412
|
+
...considered.map((o) => ({
|
|
60413
|
+
price: o.entry,
|
|
60414
|
+
quantity: o.quantity
|
|
60415
|
+
})),
|
|
60416
|
+
{
|
|
60417
|
+
price: _currentEntry,
|
|
60418
|
+
quantity: config2.currentQty || 0
|
|
60419
|
+
}
|
|
60420
|
+
], config2.decimal_places, config2.price_places);
|
|
60421
|
+
let _pnl = r2.pnl;
|
|
60422
|
+
let sell_price = r2.sell_price;
|
|
60423
|
+
let entry_pnl = r2.pnl;
|
|
60424
|
+
if (_take_profit) {
|
|
60425
|
+
_pnl = pnl_default.determine_pnl(avg_entry.price, _take_profit, avg_entry.quantity, kind);
|
|
60426
|
+
sell_price = _take_profit;
|
|
60427
|
+
entry_pnl = pnl_default.determine_pnl(r2.entry, _take_profit, avg_entry.quantity, kind);
|
|
60428
|
+
}
|
|
60429
|
+
const loss = pnl_default.determine_pnl(avg_entry.price, r2.stop, avg_entry.quantity, kind);
|
|
60430
|
+
let new_stop = r2.new_stop;
|
|
60431
|
+
const entry_loss = pnl_default.determine_pnl(r2.entry, new_stop, avg_entry.quantity, kind);
|
|
60432
|
+
let min_profit = 0;
|
|
60433
|
+
let min_entry_profit = 0;
|
|
60434
|
+
if (config2.min_profit) {
|
|
60435
|
+
min_profit = pnl_default.determine_close_price(avg_entry.price, config2.min_profit, avg_entry.quantity, kind);
|
|
60436
|
+
min_entry_profit = pnl_default.determine_close_price(r2.entry, config2.min_profit, avg_entry.quantity, kind);
|
|
60437
|
+
}
|
|
60438
|
+
let x_fee = r2.fee;
|
|
60439
|
+
if (config2.fee) {
|
|
60440
|
+
x_fee = config2.fee * r2.stop * avg_entry.quantity;
|
|
60441
|
+
}
|
|
60442
|
+
let tp_close = pnl_default.determine_close_price(r2.entry, Math.abs(entry_loss) * (config2.rr || 1) + x_fee, avg_entry.quantity, kind);
|
|
60443
|
+
return {
|
|
60444
|
+
...r2,
|
|
60445
|
+
x_fee: to_f(x_fee, "%.2f"),
|
|
60446
|
+
avg_entry: avg_entry.price,
|
|
60447
|
+
avg_size: avg_entry.quantity,
|
|
60448
|
+
entry_pnl: to_f(entry_pnl, "%.2f"),
|
|
60449
|
+
entry_loss: to_f(entry_loss, "%.2f"),
|
|
60450
|
+
min_entry_pnl: to_f(min_entry_profit, "%.2f"),
|
|
60451
|
+
pnl: _pnl,
|
|
60452
|
+
neg_pnl: to_f(loss, "%.2f"),
|
|
60453
|
+
sell_price,
|
|
60454
|
+
close_p: to_f(tp_close, "%.2f"),
|
|
60455
|
+
min_pnl: to_f(min_profit, "%.2f"),
|
|
60456
|
+
new_stop
|
|
60457
|
+
};
|
|
60458
|
+
});
|
|
60459
|
+
return rrr;
|
|
60460
|
+
};
|
|
60461
|
+
function createGapPairs(arr, gap, item) {
|
|
60462
|
+
if (arr.length === 0) {
|
|
60463
|
+
return [];
|
|
60464
|
+
}
|
|
60465
|
+
const result = [];
|
|
60466
|
+
const firstElement = arr[0];
|
|
60467
|
+
for (let i2 = arr.length - 1;i2 >= 0; i2--) {
|
|
60468
|
+
const current = arr[i2];
|
|
60469
|
+
const gapIndex = i2 - gap;
|
|
60470
|
+
const pairedElement = gapIndex < 0 ? firstElement : arr[gapIndex];
|
|
60471
|
+
if (current !== pairedElement) {
|
|
60472
|
+
result.push([current, pairedElement]);
|
|
60473
|
+
}
|
|
60474
|
+
}
|
|
60475
|
+
if (item) {
|
|
60476
|
+
let r2 = result.find((o) => o[0] === item);
|
|
60477
|
+
return r2 ? [r2] : [];
|
|
60478
|
+
}
|
|
60479
|
+
return result;
|
|
60480
|
+
}
|
|
60479
60481
|
// src/helpers/shared.ts
|
|
60480
60482
|
function getMaxQuantity(x, app_config) {
|
|
60481
60483
|
let max_quantity = app_config.max_quantity;
|
|
@@ -60584,8 +60586,8 @@ function get_app_config_and_max_size(config2, payload) {
|
|
|
60584
60586
|
stop: payload.stop,
|
|
60585
60587
|
risk_per_trade: config2.risk,
|
|
60586
60588
|
risk_reward: config2.risk_reward || 199,
|
|
60587
|
-
support:
|
|
60588
|
-
resistance:
|
|
60589
|
+
support: to_f(config2.support, config2.price_places),
|
|
60590
|
+
resistance: to_f(config2.resistance, config2.price_places),
|
|
60589
60591
|
focus: payload.entry,
|
|
60590
60592
|
fee: 0,
|
|
60591
60593
|
percent_change: config2.stop_percent / 100,
|
|
@@ -60804,8 +60806,8 @@ function getOptimumStopAndRisk(app_config, params) {
|
|
|
60804
60806
|
}
|
|
60805
60807
|
}
|
|
60806
60808
|
return {
|
|
60807
|
-
optimal_stop:
|
|
60808
|
-
optimal_risk:
|
|
60809
|
+
optimal_stop: to_f(optimal_stop, app_config.price_places),
|
|
60810
|
+
optimal_risk: to_f(final_risk, app_config.price_places),
|
|
60809
60811
|
avg_size: final_result?.[0]?.avg_size || 0,
|
|
60810
60812
|
avg_entry: final_result?.[0]?.avg_entry || 0,
|
|
60811
60813
|
result: final_result,
|
|
@@ -60853,7 +60855,7 @@ function determine_amount_to_buy(payload) {
|
|
|
60853
60855
|
existingOrders
|
|
60854
60856
|
} = payload;
|
|
60855
60857
|
const totalQuantity = orders.reduce((sum, order) => sum + (order.quantity || 0), 0);
|
|
60856
|
-
let runningTotal =
|
|
60858
|
+
let runningTotal = to_f(totalQuantity, decimal_places);
|
|
60857
60859
|
let sortedOrders = [...orders].sort((a, b) => (a.entry || 0) - (b.entry || 0));
|
|
60858
60860
|
if (kind === "short") {
|
|
60859
60861
|
sortedOrders.reverse();
|
|
@@ -60865,7 +60867,7 @@ function determine_amount_to_buy(payload) {
|
|
|
60865
60867
|
cumulative_quantity: runningTotal
|
|
60866
60868
|
});
|
|
60867
60869
|
runningTotal -= order.quantity;
|
|
60868
|
-
runningTotal =
|
|
60870
|
+
runningTotal = to_f(runningTotal, decimal_places);
|
|
60869
60871
|
}
|
|
60870
60872
|
let filteredOrders = withCumulative.filter((order) => (order.cumulative_quantity || 0) > position2?.quantity).map((order) => ({
|
|
60871
60873
|
...order,
|
|
@@ -61128,10 +61130,10 @@ function determineOptimumRisk(config2, payload, params) {
|
|
|
61128
61130
|
};
|
|
61129
61131
|
const final_result = buildAppConfig(config2, final_payload);
|
|
61130
61132
|
return {
|
|
61131
|
-
optimal_risk:
|
|
61132
|
-
achieved_neg_pnl:
|
|
61133
|
-
target_neg_pnl:
|
|
61134
|
-
difference:
|
|
61133
|
+
optimal_risk: to_f(best_risk, "%.2f"),
|
|
61134
|
+
achieved_neg_pnl: to_f(best_neg_pnl, "%.2f"),
|
|
61135
|
+
target_neg_pnl: to_f(highest_risk, "%.2f"),
|
|
61136
|
+
difference: to_f(best_diff, "%.2f"),
|
|
61135
61137
|
iterations,
|
|
61136
61138
|
converged: best_diff <= tolerance,
|
|
61137
61139
|
last_value: final_result.last_value,
|
|
@@ -61196,9 +61198,9 @@ function computeProfitDetail(payload) {
|
|
|
61196
61198
|
full_ratio = 1
|
|
61197
61199
|
} = payload;
|
|
61198
61200
|
let reward_factor = strategy?.reward_factor || 1;
|
|
61199
|
-
const profit_percent =
|
|
61201
|
+
const profit_percent = to_f(pnl * 100 / (focus_position.avg_price * focus_position.avg_qty), "%.4f");
|
|
61200
61202
|
const diff = pnl / focus_position.quantity;
|
|
61201
|
-
const sell_price =
|
|
61203
|
+
const sell_price = to_f(focus_position.kind === "long" ? focus_position.entry + diff : focus_position.entry - diff, price_places);
|
|
61202
61204
|
let loss = 0;
|
|
61203
61205
|
let full_loss = 0;
|
|
61204
61206
|
let expected_loss = 0;
|
|
@@ -61207,23 +61209,23 @@ function computeProfitDetail(payload) {
|
|
|
61207
61209
|
if (reduce_position) {
|
|
61208
61210
|
loss = Math.abs(reduce_position.entry - sell_price) * reduce_position.quantity;
|
|
61209
61211
|
const ratio = pnl / loss;
|
|
61210
|
-
quantity =
|
|
61211
|
-
expected_loss =
|
|
61212
|
+
quantity = to_f(reduce_position.quantity * ratio, decimal_places);
|
|
61213
|
+
expected_loss = to_f(Math.abs(reduce_position.entry - sell_price) * quantity, "%.2f");
|
|
61212
61214
|
full_loss = Math.abs(reduce_position.avg_price - sell_price) * reduce_position.avg_qty * full_ratio;
|
|
61213
61215
|
}
|
|
61214
61216
|
if (reverse_position) {
|
|
61215
61217
|
expected_loss = Math.abs(reverse_position.avg_price - sell_price) * reverse_position.avg_qty;
|
|
61216
|
-
new_pnl =
|
|
61218
|
+
new_pnl = to_f(pnl - expected_loss, "%.2f");
|
|
61217
61219
|
}
|
|
61218
61220
|
return {
|
|
61219
61221
|
pnl: new_pnl,
|
|
61220
|
-
loss:
|
|
61221
|
-
full_loss:
|
|
61222
|
+
loss: to_f(expected_loss, "%.2f"),
|
|
61223
|
+
full_loss: to_f(full_loss, "%.2f"),
|
|
61222
61224
|
original_pnl: pnl,
|
|
61223
61225
|
reward_factor,
|
|
61224
61226
|
profit_percent,
|
|
61225
61227
|
kind: focus_position.kind,
|
|
61226
|
-
sell_price:
|
|
61228
|
+
sell_price: to_f(sell_price, price_places),
|
|
61227
61229
|
quantity: quantity * full_ratio,
|
|
61228
61230
|
price_places,
|
|
61229
61231
|
decimal_places
|
|
@@ -61258,18 +61260,18 @@ function generateGapTp(payload) {
|
|
|
61258
61260
|
const gapLoss = gap * max_quantity;
|
|
61259
61261
|
const longPercent = gapLoss * factor / (short.entry * short.quantity);
|
|
61260
61262
|
const shortPercent = gapLoss * factor / (long.entry * long.quantity);
|
|
61261
|
-
const longTp =
|
|
61262
|
-
const shortTp =
|
|
61263
|
-
const shortToReduce =
|
|
61264
|
-
const longToReduce =
|
|
61265
|
-
const actualShortReduce =
|
|
61266
|
-
const actualLongReduce =
|
|
61263
|
+
const longTp = to_f((1 + longPercent) * long.entry, price_places);
|
|
61264
|
+
const shortTp = to_f((1 + shortPercent) ** -1 * short.entry, price_places);
|
|
61265
|
+
const shortToReduce = to_f(Math.abs(longTp - long.entry) * long.quantity, "%.1f");
|
|
61266
|
+
const longToReduce = to_f(Math.abs(shortTp - short.entry) * short.quantity, "%.1f");
|
|
61267
|
+
const actualShortReduce = to_f(shortToReduce * sell_factor, "%.1f");
|
|
61268
|
+
const actualLongReduce = to_f(longToReduce * sell_factor, "%.1f");
|
|
61267
61269
|
const short_quantity_to_sell = determine_amount_to_sell2(short.entry, short.quantity, longTp, actualShortReduce, "short", decimal_places);
|
|
61268
61270
|
const long_quantity_to_sell = determine_amount_to_sell2(long.entry, long.quantity, shortTp, actualLongReduce, "long", decimal_places);
|
|
61269
|
-
const risk_amount_short =
|
|
61270
|
-
const risk_amount_long =
|
|
61271
|
-
const profit_percent_long =
|
|
61272
|
-
const profit_percent_short =
|
|
61271
|
+
const risk_amount_short = to_f(shortToReduce - actualShortReduce, "%.2f");
|
|
61272
|
+
const risk_amount_long = to_f(longToReduce - actualLongReduce, "%.2f");
|
|
61273
|
+
const profit_percent_long = to_f(shortToReduce * 100 / (long.entry * long.quantity), "%.4f");
|
|
61274
|
+
const profit_percent_short = to_f(longToReduce * 100 / (short.entry * short.quantity), "%.4f");
|
|
61273
61275
|
return {
|
|
61274
61276
|
profit_percent: {
|
|
61275
61277
|
long: profit_percent_long,
|
|
@@ -61295,8 +61297,8 @@ function generateGapTp(payload) {
|
|
|
61295
61297
|
short: short_quantity_to_sell,
|
|
61296
61298
|
long: long_quantity_to_sell
|
|
61297
61299
|
},
|
|
61298
|
-
gap:
|
|
61299
|
-
gap_loss:
|
|
61300
|
+
gap: to_f(gap, price_places),
|
|
61301
|
+
gap_loss: to_f(gapLoss, "%.2f")
|
|
61300
61302
|
};
|
|
61301
61303
|
}
|
|
61302
61304
|
function calculate_factor(payload) {
|
|
@@ -61322,7 +61324,7 @@ function calculate_factor(payload) {
|
|
|
61322
61324
|
const calculated_shortPercent = target_to_reduce / (short_notional - target_to_reduce);
|
|
61323
61325
|
calculated_factor = calculated_shortPercent * long_notional / gapLoss;
|
|
61324
61326
|
}
|
|
61325
|
-
calculated_factor =
|
|
61327
|
+
calculated_factor = to_f(calculated_factor, places);
|
|
61326
61328
|
return calculated_factor;
|
|
61327
61329
|
}
|
|
61328
61330
|
function getHedgeZone(payload) {
|
|
@@ -61349,19 +61351,19 @@ function getHedgeZone(payload) {
|
|
|
61349
61351
|
const tp_diff = Math.abs(take_profit - position2.entry);
|
|
61350
61352
|
const quantity = position2.quantity;
|
|
61351
61353
|
const diff = risk / quantity;
|
|
61352
|
-
let new_take_profit = kind === "long" ?
|
|
61353
|
-
let base_factor =
|
|
61354
|
+
let new_take_profit = kind === "long" ? to_f(position2.entry + diff, symbol_config.price_places) : to_f(position2.entry - diff, symbol_config.price_places);
|
|
61355
|
+
let base_factor = to_f(Math.max(tp_diff, diff) / (Math.min(tp_diff, diff) || 1), "%.3f");
|
|
61354
61356
|
let factor = reward_factor || base_factor;
|
|
61355
61357
|
const new_risk = risk * factor * risk_factor;
|
|
61356
61358
|
const stop_loss_diff = new_risk / quantity;
|
|
61357
|
-
new_take_profit = kind === "long" ?
|
|
61358
|
-
const stop_loss = kind === "long" ?
|
|
61359
|
+
new_take_profit = kind === "long" ? to_f(position2.entry + stop_loss_diff, symbol_config.price_places) : to_f(position2.entry - stop_loss_diff, symbol_config.price_places);
|
|
61360
|
+
const stop_loss = kind === "long" ? to_f(position2.entry - stop_loss_diff, symbol_config.price_places) : to_f(position2.entry + stop_loss_diff, symbol_config.price_places);
|
|
61359
61361
|
const profit_percent = new_risk * 100 / (position2.entry * position2.quantity);
|
|
61360
61362
|
return {
|
|
61361
61363
|
support: Math.min(new_take_profit, stop_loss),
|
|
61362
61364
|
resistance: Math.max(new_take_profit, stop_loss),
|
|
61363
|
-
risk:
|
|
61364
|
-
profit_percent:
|
|
61365
|
+
risk: to_f(new_risk, "%.2f"),
|
|
61366
|
+
profit_percent: to_f(profit_percent, "%.2f")
|
|
61365
61367
|
};
|
|
61366
61368
|
}
|
|
61367
61369
|
function getOptimumHedgeFactor(payload) {
|
|
@@ -61396,10 +61398,10 @@ function getOptimumHedgeFactor(payload) {
|
|
|
61396
61398
|
}
|
|
61397
61399
|
if (diff <= tolerance) {
|
|
61398
61400
|
return {
|
|
61399
|
-
reward_factor:
|
|
61400
|
-
achieved_support:
|
|
61401
|
-
target_support:
|
|
61402
|
-
difference:
|
|
61401
|
+
reward_factor: to_f(mid_factor, "%.4f"),
|
|
61402
|
+
achieved_support: to_f(current_support, symbol_config.price_places),
|
|
61403
|
+
target_support: to_f(target_support, symbol_config.price_places),
|
|
61404
|
+
difference: to_f(diff, symbol_config.price_places),
|
|
61403
61405
|
iterations: iteration + 1
|
|
61404
61406
|
};
|
|
61405
61407
|
}
|
|
@@ -61419,10 +61421,10 @@ function getOptimumHedgeFactor(payload) {
|
|
|
61419
61421
|
reward_factor: best_factor
|
|
61420
61422
|
});
|
|
61421
61423
|
return {
|
|
61422
|
-
reward_factor:
|
|
61423
|
-
achieved_support:
|
|
61424
|
-
target_support:
|
|
61425
|
-
difference:
|
|
61424
|
+
reward_factor: to_f(best_factor, "%.4f"),
|
|
61425
|
+
achieved_support: to_f(final_hedge_zone.support, symbol_config.price_places),
|
|
61426
|
+
target_support: to_f(target_support, symbol_config.price_places),
|
|
61427
|
+
difference: to_f(best_diff, symbol_config.price_places),
|
|
61426
61428
|
iterations: max_iterations,
|
|
61427
61429
|
converged: best_diff <= tolerance
|
|
61428
61430
|
};
|
|
@@ -61467,15 +61469,14 @@ function determineCompoundLongTrade(payload) {
|
|
|
61467
61469
|
return {
|
|
61468
61470
|
start_risk,
|
|
61469
61471
|
short_profit,
|
|
61470
|
-
support:
|
|
61471
|
-
resistance:
|
|
61472
|
+
support: to_f(support, global_config.price_places),
|
|
61473
|
+
resistance: to_f(resistance, global_config.price_places),
|
|
61472
61474
|
long_v: long_app_config.last_value,
|
|
61473
|
-
profit_percent:
|
|
61475
|
+
profit_percent: to_f(long_profit_percent, "%.3f"),
|
|
61474
61476
|
result,
|
|
61475
61477
|
short_max_size
|
|
61476
61478
|
};
|
|
61477
61479
|
}
|
|
61478
|
-
|
|
61479
61480
|
// src/helpers/strategy.ts
|
|
61480
61481
|
class Strategy {
|
|
61481
61482
|
position;
|
|
@@ -61499,10 +61500,10 @@ class Strategy {
|
|
|
61499
61500
|
return this.config.global_config.decimal_places;
|
|
61500
61501
|
}
|
|
61501
61502
|
to_f(price) {
|
|
61502
|
-
return
|
|
61503
|
+
return to_f(price, this.price_places);
|
|
61503
61504
|
}
|
|
61504
61505
|
to_df(quantity) {
|
|
61505
|
-
return
|
|
61506
|
+
return to_f(quantity, this.decimal_places);
|
|
61506
61507
|
}
|
|
61507
61508
|
pnl(kind, _position) {
|
|
61508
61509
|
const position2 = _position || this.position[kind];
|
|
@@ -61703,7 +61704,7 @@ class Strategy {
|
|
|
61703
61704
|
remaining_quantity: this.to_df(reverse_avg.quantity - sell_quantity)
|
|
61704
61705
|
},
|
|
61705
61706
|
spread: Math.abs(avg.entry - reverse_avg.entry),
|
|
61706
|
-
gap_loss:
|
|
61707
|
+
gap_loss: to_f(Math.abs(avg.entry - reverse_avg.entry) * reverse_avg.quantity, "%.2f"),
|
|
61707
61708
|
net_profit: incurred_loss + reverse_pnl
|
|
61708
61709
|
};
|
|
61709
61710
|
}
|
|
@@ -61871,8 +61872,8 @@ class Strategy {
|
|
|
61871
61872
|
quantity: this.position[app_config.kind].quantity
|
|
61872
61873
|
}
|
|
61873
61874
|
]), app_config.decimal_places, app_config.price_places);
|
|
61874
|
-
const expected_loss =
|
|
61875
|
-
const profit_percent =
|
|
61875
|
+
const expected_loss = to_f(Math.abs(avg.price - stop) * avg.quantity, "%.2f");
|
|
61876
|
+
const profit_percent = to_f(this.pnl(kind) * 100 / (avg.price * avg.quantity), "%.3f");
|
|
61876
61877
|
app_config.entry = this.to_f(app_config.entry);
|
|
61877
61878
|
app_config.stop = this.to_f(app_config.stop);
|
|
61878
61879
|
return { ...app_config, avg, loss: -expected_loss, profit_percent };
|
|
@@ -61975,9 +61976,6 @@ class Strategy {
|
|
|
61975
61976
|
};
|
|
61976
61977
|
}
|
|
61977
61978
|
}
|
|
61978
|
-
|
|
61979
|
-
// src/exchanges/binance/index.ts
|
|
61980
|
-
var import_binance = __toESM(require_lib2(), 1);
|
|
61981
61979
|
// src/types/index.ts
|
|
61982
61980
|
class BaseExchange {
|
|
61983
61981
|
client;
|
|
@@ -62022,7 +62020,7 @@ class BaseExchange {
|
|
|
62022
62020
|
place = false
|
|
62023
62021
|
} = payload;
|
|
62024
62022
|
const totalQuantity = orders.reduce((sum, order) => sum + (order.quantity || 0), 0);
|
|
62025
|
-
let runningTotal =
|
|
62023
|
+
let runningTotal = to_f(totalQuantity, decimal_places);
|
|
62026
62024
|
let sortedOrders = [...orders].sort((a, b) => (a.entry || 0) - (b.entry || 0));
|
|
62027
62025
|
if (kind === "short") {
|
|
62028
62026
|
sortedOrders.reverse();
|
|
@@ -62034,7 +62032,7 @@ class BaseExchange {
|
|
|
62034
62032
|
cumulative_quantity: runningTotal
|
|
62035
62033
|
});
|
|
62036
62034
|
runningTotal -= order.quantity;
|
|
62037
|
-
runningTotal =
|
|
62035
|
+
runningTotal = to_f(runningTotal, decimal_places);
|
|
62038
62036
|
}
|
|
62039
62037
|
const positions = await this.getPositionInfo(symbol);
|
|
62040
62038
|
const position2 = positions[kind] || {
|
|
@@ -62563,8 +62561,8 @@ async function createLimitPurchaseOrdersParallel(client, symbol, priceFormat, qu
|
|
|
62563
62561
|
const createOrder = (x) => {
|
|
62564
62562
|
const v = {
|
|
62565
62563
|
symbol: symbol.toUpperCase(),
|
|
62566
|
-
price: x.price ?
|
|
62567
|
-
quantity: x.quantity ?
|
|
62564
|
+
price: x.price ? to_f(x.price, priceFormat) : 0,
|
|
62565
|
+
quantity: x.quantity ? to_f(x.quantity, quantityFormat) : 0,
|
|
62568
62566
|
side: x.side?.toUpperCase() || "",
|
|
62569
62567
|
type: "LIMIT",
|
|
62570
62568
|
positionSide: x.kind.toUpperCase(),
|
|
@@ -62579,7 +62577,7 @@ async function createLimitPurchaseOrdersParallel(client, symbol, priceFormat, qu
|
|
|
62579
62577
|
delete v.timeInForce;
|
|
62580
62578
|
v.type = `${v.type}_MARKET`.toUpperCase();
|
|
62581
62579
|
} else if (typeof x.stop === "number") {
|
|
62582
|
-
v.stopPrice =
|
|
62580
|
+
v.stopPrice = to_f(x.stop, priceFormat);
|
|
62583
62581
|
}
|
|
62584
62582
|
}
|
|
62585
62583
|
if (x.force_market) {
|
|
@@ -62852,14 +62850,14 @@ async function getOpenOrders(client, symbol, type) {
|
|
|
62852
62850
|
async function getWalletBalance(client, asset = "USDT") {
|
|
62853
62851
|
const response = await client.getBalanceV3();
|
|
62854
62852
|
const balance = response.find((x) => x.asset.toLowerCase() === asset.toLowerCase())?.balance;
|
|
62855
|
-
return balance ?
|
|
62853
|
+
return balance ? to_f(balance, "%.2f") : 0;
|
|
62856
62854
|
}
|
|
62857
62855
|
async function allWalletBalances(client) {
|
|
62858
62856
|
const response = await client.getBalanceV3();
|
|
62859
62857
|
return response.map((x) => ({
|
|
62860
62858
|
type: "future",
|
|
62861
62859
|
asset: x.asset,
|
|
62862
|
-
balance:
|
|
62860
|
+
balance: to_f(x.balance, "%.8f")
|
|
62863
62861
|
}));
|
|
62864
62862
|
}
|
|
62865
62863
|
function buildPosition(position2, orders, options) {
|
|
@@ -62896,7 +62894,7 @@ function buildPosition(position2, orders, options) {
|
|
|
62896
62894
|
take_profit,
|
|
62897
62895
|
tp_quantity,
|
|
62898
62896
|
stop_quantity,
|
|
62899
|
-
liquidation: position2.liquidationPrice ?
|
|
62897
|
+
liquidation: position2.liquidationPrice ? to_f(position2.liquidationPrice, price_places) : 0
|
|
62900
62898
|
};
|
|
62901
62899
|
}
|
|
62902
62900
|
var emptyPosition = {
|
|
@@ -62917,7 +62915,7 @@ async function getLeverage(client, symbol) {
|
|
|
62917
62915
|
symbol
|
|
62918
62916
|
});
|
|
62919
62917
|
const leverage = response[0]?.leverage;
|
|
62920
|
-
return leverage ?
|
|
62918
|
+
return leverage ? to_f(leverage, "%0f") : 0;
|
|
62921
62919
|
}
|
|
62922
62920
|
async function fetchBinanceAccount(client, json, options) {
|
|
62923
62921
|
const [position2, balance, orders, current_price, all_balances, leverage] = await Promise.all([
|
|
@@ -63215,7 +63213,7 @@ class BinanceExchange extends BaseExchange {
|
|
|
63215
63213
|
const currentPrice = await getCurrentPrice(this.client, symbol);
|
|
63216
63214
|
const price_places = isBTC ? "%.1f" : `%.${getPricePlaces(currentPrice)}f`;
|
|
63217
63215
|
const decimal_places = `%.${target.quantityPrecision}f`;
|
|
63218
|
-
const min_size =
|
|
63216
|
+
const min_size = to_f((minNotional || 0) / support, decimal_places);
|
|
63219
63217
|
const configObj = {
|
|
63220
63218
|
support,
|
|
63221
63219
|
resistance,
|
|
@@ -63459,8 +63457,8 @@ async function createLimitPurchaseOrders(client, symbol, priceFormat, quantityFo
|
|
|
63459
63457
|
const createOrder = (x) => {
|
|
63460
63458
|
const v = {
|
|
63461
63459
|
symbol: symbol.toUpperCase(),
|
|
63462
|
-
price: (x.price ?
|
|
63463
|
-
qty: (x.quantity ?
|
|
63460
|
+
price: (x.price ? to_f(x.price, priceFormat) : 0).toString(),
|
|
63461
|
+
qty: (x.quantity ? to_f(x.quantity, quantityFormat) : 0).toString(),
|
|
63464
63462
|
side: titleCase(x.side || ""),
|
|
63465
63463
|
orderType: "LIMIT",
|
|
63466
63464
|
positionIdx: x.kind === "long" ? 1 : 2,
|
|
@@ -63477,12 +63475,12 @@ async function createLimitPurchaseOrders(client, symbol, priceFormat, quantityFo
|
|
|
63477
63475
|
delete v.timeInForce;
|
|
63478
63476
|
v.orderType = `MARKET`;
|
|
63479
63477
|
} else if (typeof x.stop === "number") {
|
|
63480
|
-
v.triggerPrice =
|
|
63478
|
+
v.triggerPrice = to_f(x.stop, priceFormat).toString();
|
|
63481
63479
|
}
|
|
63482
63480
|
if (x.kind === "long" && x.side === "sell" || x.kind === "short" && x.side === "buy") {
|
|
63483
63481
|
v.tpslMode = "Partial";
|
|
63484
63482
|
v.slOrderType = "Limit";
|
|
63485
|
-
v.slLimitPrice =
|
|
63483
|
+
v.slLimitPrice = to_f(v.triggerPrice, priceFormat).toString();
|
|
63486
63484
|
if (x.is_market) {
|
|
63487
63485
|
v.slOrderType = "Market";
|
|
63488
63486
|
v.tpslMode = "Full";
|
|
@@ -63715,7 +63713,7 @@ async function getWalletBalance2(client, asset = "USDT") {
|
|
|
63715
63713
|
accountType: "UNIFIED",
|
|
63716
63714
|
coin: asset
|
|
63717
63715
|
});
|
|
63718
|
-
return
|
|
63716
|
+
return to_f(response.result.list[0].totalWalletBalance, "%.2f");
|
|
63719
63717
|
}
|
|
63720
63718
|
async function allWalletBalances2(client) {
|
|
63721
63719
|
const response = await client.getWalletBalance({
|
|
@@ -63725,7 +63723,7 @@ async function allWalletBalances2(client) {
|
|
|
63725
63723
|
return response.result.list[0].coin.map((x) => ({
|
|
63726
63724
|
type: "future",
|
|
63727
63725
|
asset: x.coin,
|
|
63728
|
-
balance:
|
|
63726
|
+
balance: to_f(x.walletBalance, "%.8f")
|
|
63729
63727
|
}));
|
|
63730
63728
|
}
|
|
63731
63729
|
function buildPosition2(position2, orders, options) {
|
|
@@ -64022,7 +64020,7 @@ class BybitExchange extends BaseExchange {
|
|
|
64022
64020
|
function determine_liquidation(balance_diff, position2) {
|
|
64023
64021
|
const long_liquidation = position2.price - balance_diff / position2.quantity;
|
|
64024
64022
|
const short_liquidation = position2.price + balance_diff / position2.quantity;
|
|
64025
|
-
return position2.kind === "long" ?
|
|
64023
|
+
return position2.kind === "long" ? to_f(long_liquidation, "%.2f") : to_f(short_liquidation, "%.2f");
|
|
64026
64024
|
}
|
|
64027
64025
|
function calculate_avg_entry(kind, {
|
|
64028
64026
|
orders: _orders,
|
|
@@ -64187,13 +64185,13 @@ function calculateHedge(payload) {
|
|
|
64187
64185
|
const stopLossQuantity = Math.min(stopLossAmount / priceDifference, oppositePosition.quantity);
|
|
64188
64186
|
return {
|
|
64189
64187
|
[kind]: {
|
|
64190
|
-
price:
|
|
64191
|
-
quantity:
|
|
64188
|
+
price: to_f(takeProfitPrice, active_account.price_places),
|
|
64189
|
+
quantity: to_f(position_quantity || 0, active_account.decimal_places),
|
|
64192
64190
|
type: "TAKE_PROFIT"
|
|
64193
64191
|
},
|
|
64194
64192
|
[oppositeKind]: {
|
|
64195
|
-
stop_price:
|
|
64196
|
-
quantity:
|
|
64193
|
+
stop_price: to_f(stopLossPrice, active_account.price_places),
|
|
64194
|
+
quantity: to_f(stopLossQuantity || 0, active_account.decimal_places),
|
|
64197
64195
|
type: "STOP_LOSS"
|
|
64198
64196
|
}
|
|
64199
64197
|
};
|
|
@@ -64258,7 +64256,7 @@ function processPosition(codeNode, input, kind) {
|
|
|
64258
64256
|
side: reverse_kind === "long" ? "buy" : "sell"
|
|
64259
64257
|
},
|
|
64260
64258
|
orders_to_cancel,
|
|
64261
|
-
stop:
|
|
64259
|
+
stop: to_f(vv[kind].price, active_account.price_places),
|
|
64262
64260
|
quantity: vv[kind].quantity,
|
|
64263
64261
|
kind,
|
|
64264
64262
|
type: JSON.stringify("TAKE_PROFIT"),
|
|
@@ -64277,7 +64275,7 @@ function processPosition(codeNode, input, kind) {
|
|
|
64277
64275
|
}
|
|
64278
64276
|
async function reduceMajorPositionCalculation(input, exchange_instance) {
|
|
64279
64277
|
try {
|
|
64280
|
-
let conditionsCheck = input.position.tp_quantity !== input.quantity || input.position.take_profit !==
|
|
64278
|
+
let conditionsCheck = input.position.tp_quantity !== input.quantity || input.position.take_profit !== to_f(input.stop, input.price_places);
|
|
64281
64279
|
if (!isNaN(input.opposite_position.stop_quantity) && input.opposite_position.stop_quantity > -1) {
|
|
64282
64280
|
conditionsCheck = conditionsCheck || input.opposite_position.stop_quantity !== input.to_place.quantity;
|
|
64283
64281
|
}
|
|
@@ -64402,15 +64400,20 @@ async function reduceMajorPositionEntry(input, accountInfo, trigger2, exchange_i
|
|
|
64402
64400
|
// src/position.ts
|
|
64403
64401
|
class ExchangePosition {
|
|
64404
64402
|
exchange;
|
|
64403
|
+
symbol_config;
|
|
64405
64404
|
exchange_account;
|
|
64406
64405
|
app_db;
|
|
64407
64406
|
instance;
|
|
64408
64407
|
constructor(payload) {
|
|
64408
|
+
this.symbol_config = payload.symbol_config;
|
|
64409
64409
|
this.exchange = payload.exchange;
|
|
64410
64410
|
this.app_db = payload.app_db;
|
|
64411
64411
|
this.instance = payload.instance;
|
|
64412
64412
|
this.exchange_account = payload.exchange_account;
|
|
64413
64413
|
}
|
|
64414
|
+
getInstance() {
|
|
64415
|
+
return this.instance;
|
|
64416
|
+
}
|
|
64414
64417
|
get symbol() {
|
|
64415
64418
|
return this.instance.symbol;
|
|
64416
64419
|
}
|
|
@@ -64418,16 +64421,18 @@ class ExchangePosition {
|
|
|
64418
64421
|
return this.instance.kind;
|
|
64419
64422
|
}
|
|
64420
64423
|
get account() {
|
|
64421
|
-
|
|
64424
|
+
const { p_account } = this.instance.expand;
|
|
64425
|
+
return p_account;
|
|
64422
64426
|
}
|
|
64423
64427
|
async cancelOrders(payload) {
|
|
64424
|
-
const { limit, price: _price } = payload;
|
|
64428
|
+
const { limit, price: _price, raw } = payload;
|
|
64425
64429
|
if (limit) {
|
|
64426
64430
|
return await this.app_db.cancelLimitOrders({
|
|
64427
64431
|
symbol: this.symbol,
|
|
64428
64432
|
kind: this.kind,
|
|
64429
64433
|
account: this.account,
|
|
64430
|
-
cancelExchangeOrders: (p) => this.exchange.cancelOrders(p)
|
|
64434
|
+
cancelExchangeOrders: (p) => this.exchange.cancelOrders(p),
|
|
64435
|
+
raw
|
|
64431
64436
|
});
|
|
64432
64437
|
}
|
|
64433
64438
|
let price = _price || 0;
|
|
@@ -64460,6 +64465,9 @@ class ExchangePosition {
|
|
|
64460
64465
|
return await this.app_db.createOrUpdatePositionConfig(this.instance, params);
|
|
64461
64466
|
}
|
|
64462
64467
|
}
|
|
64468
|
+
if (this.instance.expand?.b_config) {
|
|
64469
|
+
return this.instance.expand.b_config;
|
|
64470
|
+
}
|
|
64463
64471
|
return await this.app_db.getPositionConfig({
|
|
64464
64472
|
symbol: this.symbol,
|
|
64465
64473
|
kind: this.kind,
|
|
@@ -64468,15 +64476,19 @@ class ExchangePosition {
|
|
|
64468
64476
|
}
|
|
64469
64477
|
async updateTargetPnl() {
|
|
64470
64478
|
const position2 = this.instance;
|
|
64471
|
-
|
|
64472
|
-
|
|
64479
|
+
const config2 = await this.getConfig();
|
|
64480
|
+
if (config2) {
|
|
64473
64481
|
let _profit = config2.profit;
|
|
64482
|
+
let risk = config2.risk;
|
|
64483
|
+
let next_risk = position2.next_risk;
|
|
64474
64484
|
let _profit_percent = config2?.profit_percent;
|
|
64475
64485
|
if (_profit_percent && (position2?.quantity || 0) > 0) {
|
|
64476
|
-
_profit =
|
|
64486
|
+
_profit = to_f(position2.quantity * _profit_percent * position2.entry / 100);
|
|
64487
|
+
next_risk = risk + _profit;
|
|
64477
64488
|
}
|
|
64478
64489
|
await this.app_db.update_db_position(position2, {
|
|
64479
|
-
target_pnl: _profit
|
|
64490
|
+
target_pnl: _profit,
|
|
64491
|
+
next_risk
|
|
64480
64492
|
});
|
|
64481
64493
|
return _profit;
|
|
64482
64494
|
}
|
|
@@ -64496,13 +64508,13 @@ class ExchangePosition {
|
|
|
64496
64508
|
}
|
|
64497
64509
|
}
|
|
64498
64510
|
async triggerTradeFromConfig(payload) {
|
|
64499
|
-
const { place = true, stop, use_current, ignore_config } = payload;
|
|
64511
|
+
const { place = true, stop, use_current, ignore_config, risky } = payload;
|
|
64500
64512
|
const position2 = this.instance;
|
|
64501
64513
|
const config2 = await this.getConfig();
|
|
64502
64514
|
let condition = ignore_config ? true : position2?.config;
|
|
64503
64515
|
if (condition) {
|
|
64504
64516
|
let entry = payload.tp ? position2.entry || config2.entry : config2.entry;
|
|
64505
|
-
const v = stop ? "place_stop_orders" : "place_limit_orders";
|
|
64517
|
+
const v = stop ? "place_stop_orders" : risky ? "dangerous_entry_orders" : "place_limit_orders";
|
|
64506
64518
|
return await this.placeSharedOrder(v, {
|
|
64507
64519
|
entry,
|
|
64508
64520
|
stop: config2.stop,
|
|
@@ -64510,18 +64522,26 @@ class ExchangePosition {
|
|
|
64510
64522
|
risk: config2.risk,
|
|
64511
64523
|
place,
|
|
64512
64524
|
raw: payload.raw,
|
|
64513
|
-
use_current
|
|
64525
|
+
use_current,
|
|
64526
|
+
stop_percent: config2.stop_percent || 100
|
|
64514
64527
|
});
|
|
64515
64528
|
}
|
|
64516
64529
|
}
|
|
64517
64530
|
async placeSharedOrder(action, payload) {
|
|
64531
|
+
const { stop_percent = 100 } = payload;
|
|
64532
|
+
const config2 = await this.getConfig();
|
|
64518
64533
|
const app_config = await this.buildAppConfig({
|
|
64519
64534
|
entry: payload.entry,
|
|
64520
64535
|
stop: payload.stop,
|
|
64521
64536
|
risk_reward: payload.risk_reward,
|
|
64522
64537
|
risk: payload.risk,
|
|
64523
64538
|
profit: 0,
|
|
64524
|
-
update_db: payload.update_db
|
|
64539
|
+
update_db: payload.update_db,
|
|
64540
|
+
use_kelly: config2.kelly?.use_kelly,
|
|
64541
|
+
kelly_confidence_factor: config2.kelly?.kelly_confidence_factor,
|
|
64542
|
+
kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
|
|
64543
|
+
kelly_prediction_model: config2.kelly?.kelly_prediction_model,
|
|
64544
|
+
kelly_func: config2.kelly?.kelly_func
|
|
64525
64545
|
});
|
|
64526
64546
|
const { entry_orders, stop_orders, trades } = await this.placeConfigOrders(app_config, {
|
|
64527
64547
|
risk_reward: payload.risk_reward,
|
|
@@ -64531,7 +64551,13 @@ class ExchangePosition {
|
|
|
64531
64551
|
avg_size: 0,
|
|
64532
64552
|
neg_pnl: 0,
|
|
64533
64553
|
min_size: app_config.min_size,
|
|
64534
|
-
symbol: this.symbol
|
|
64554
|
+
symbol: this.symbol,
|
|
64555
|
+
stop_percent,
|
|
64556
|
+
use_kelly: config2.kelly?.use_kelly,
|
|
64557
|
+
kelly_confidence_factor: config2.kelly?.kelly_confidence_factor,
|
|
64558
|
+
kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
|
|
64559
|
+
kelly_prediction_model: config2.kelly?.kelly_prediction_model,
|
|
64560
|
+
kelly_func: config2.kelly?.kelly_func
|
|
64535
64561
|
}, false);
|
|
64536
64562
|
if (payload.raw) {
|
|
64537
64563
|
let actual_orders_to_buy = await this.determineAmountToBuy({
|
|
@@ -64567,12 +64593,23 @@ class ExchangePosition {
|
|
|
64567
64593
|
symbol: this.symbol,
|
|
64568
64594
|
place: payload.place
|
|
64569
64595
|
});
|
|
64570
|
-
await this.exchange_account.getLiveExchangeInstance({
|
|
64571
|
-
symbol: this.symbol,
|
|
64572
|
-
refresh: true
|
|
64573
|
-
});
|
|
64574
64596
|
return result;
|
|
64575
64597
|
}
|
|
64598
|
+
if (action == "dangerous_entry_orders" && payload.place) {
|
|
64599
|
+
return await this.exchange.createLimitPurchaseOrders({
|
|
64600
|
+
orders: trades.map((x) => ({
|
|
64601
|
+
...x,
|
|
64602
|
+
price: x.entry,
|
|
64603
|
+
quantity: x.quantity,
|
|
64604
|
+
side: app_config.kind === "long" ? "buy" : "sell",
|
|
64605
|
+
kind: app_config.kind
|
|
64606
|
+
})),
|
|
64607
|
+
kind: app_config.kind,
|
|
64608
|
+
decimal_places: app_config.decimal_places,
|
|
64609
|
+
price_places: app_config.price_places,
|
|
64610
|
+
symbol: this.symbol
|
|
64611
|
+
});
|
|
64612
|
+
}
|
|
64576
64613
|
if (action === "place_stop_orders" && payload.place) {
|
|
64577
64614
|
const instance = this.instance;
|
|
64578
64615
|
let result = await this.exchange.placeStopOrders({
|
|
@@ -64584,10 +64621,6 @@ class ExchangePosition {
|
|
|
64584
64621
|
decimal_places: app_config.decimal_places,
|
|
64585
64622
|
place: true
|
|
64586
64623
|
});
|
|
64587
|
-
await this.exchange_account.getLiveExchangeInstance({
|
|
64588
|
-
symbol: this.symbol,
|
|
64589
|
-
refresh: true
|
|
64590
|
-
});
|
|
64591
64624
|
return result;
|
|
64592
64625
|
}
|
|
64593
64626
|
return {
|
|
@@ -64616,11 +64649,19 @@ class ExchangePosition {
|
|
|
64616
64649
|
return app_config;
|
|
64617
64650
|
}
|
|
64618
64651
|
async placeConfigOrders(app_config, solution, place, skip_stop) {
|
|
64652
|
+
const { stop_percent = 100 } = solution;
|
|
64619
64653
|
app_config.entry = solution.entry;
|
|
64620
64654
|
app_config.stop = solution.stop;
|
|
64621
64655
|
app_config.risk_per_trade = solution.risk_per_trade;
|
|
64622
64656
|
app_config.min_size = solution.min_size;
|
|
64623
64657
|
app_config.risk_reward = solution.risk_reward;
|
|
64658
|
+
app_config.kelly = {
|
|
64659
|
+
use_kelly: solution.use_kelly,
|
|
64660
|
+
kelly_confidence_factor: solution.kelly_confidence_factor,
|
|
64661
|
+
kelly_minimum_risk: solution.kelly_minimum_risk,
|
|
64662
|
+
kelly_prediction_model: solution.kelly_prediction_model,
|
|
64663
|
+
kelly_func: solution.kelly_func
|
|
64664
|
+
};
|
|
64624
64665
|
const options = {
|
|
64625
64666
|
take_profit: null,
|
|
64626
64667
|
entry: app_config.entry,
|
|
@@ -64634,7 +64675,12 @@ class ExchangePosition {
|
|
|
64634
64675
|
gap: app_config.gap,
|
|
64635
64676
|
rr: app_config.rr,
|
|
64636
64677
|
price_places: app_config.price_places,
|
|
64637
|
-
decimal_places: app_config.decimal_places
|
|
64678
|
+
decimal_places: app_config.decimal_places,
|
|
64679
|
+
use_kelly: solution.use_kelly,
|
|
64680
|
+
kelly_confidence_factor: solution.kelly_confidence_factor,
|
|
64681
|
+
kelly_minimum_risk: solution.kelly_minimum_risk,
|
|
64682
|
+
kelly_prediction_model: solution.kelly_prediction_model,
|
|
64683
|
+
kelly_func: solution.kelly_func
|
|
64638
64684
|
};
|
|
64639
64685
|
const trades = sortedBuildConfig(app_config, options);
|
|
64640
64686
|
const entry_orders = {
|
|
@@ -64648,9 +64694,13 @@ class ExchangePosition {
|
|
|
64648
64694
|
})),
|
|
64649
64695
|
kind: app_config.kind
|
|
64650
64696
|
};
|
|
64697
|
+
const last_order = trades[0]?.entry;
|
|
64698
|
+
const stop_spread = stop_percent / 100;
|
|
64699
|
+
const _stop = app_config.kind === "short" ? last_order * (1 + stop_spread) : last_order * (1 - stop_spread);
|
|
64700
|
+
const stop_to_user = stop_percent === 100 ? solution.stop : _stop;
|
|
64651
64701
|
const stop_orders = {
|
|
64652
|
-
stop:
|
|
64653
|
-
final_stop:
|
|
64702
|
+
stop: stop_to_user,
|
|
64703
|
+
final_stop: stop_to_user,
|
|
64654
64704
|
kind: app_config.kind,
|
|
64655
64705
|
quantity: trades[0]?.avg_size,
|
|
64656
64706
|
is_limit: true,
|
|
@@ -64692,7 +64742,7 @@ class ExchangePosition {
|
|
|
64692
64742
|
async determineAmountToBuy(payload) {
|
|
64693
64743
|
const { orders, kind, decimal_places = "%.3f", refresh, cancel } = payload;
|
|
64694
64744
|
const totalQuantity = orders.reduce((sum, order) => sum + (order.quantity || 0), 0);
|
|
64695
|
-
let runningTotal =
|
|
64745
|
+
let runningTotal = to_f(totalQuantity, decimal_places);
|
|
64696
64746
|
let sortedOrders = [...orders].sort((a, b) => (a.entry || 0) - (b.entry || 0));
|
|
64697
64747
|
if (kind === "short") {
|
|
64698
64748
|
sortedOrders.reverse();
|
|
@@ -64704,7 +64754,7 @@ class ExchangePosition {
|
|
|
64704
64754
|
cumulative_quantity: runningTotal
|
|
64705
64755
|
});
|
|
64706
64756
|
runningTotal -= order.quantity;
|
|
64707
|
-
runningTotal =
|
|
64757
|
+
runningTotal = to_f(runningTotal, decimal_places);
|
|
64708
64758
|
}
|
|
64709
64759
|
const { instance: position2, existingOrders } = await this.refresh(refresh);
|
|
64710
64760
|
let filteredOrders = withCumulative.filter((order) => (order.cumulative_quantity || 0) > position2?.quantity).map((order) => ({
|
|
@@ -64726,14 +64776,11 @@ class ExchangePosition {
|
|
|
64726
64776
|
return filteredOrders;
|
|
64727
64777
|
}
|
|
64728
64778
|
async refresh(live_refresh) {
|
|
64729
|
-
await this.exchange_account.refreshAccount({
|
|
64730
|
-
symbol: this.symbol,
|
|
64731
|
-
live_refresh
|
|
64732
|
-
});
|
|
64733
64779
|
const instance = await this.exchange_account.syncAccount({
|
|
64734
64780
|
symbol: this.symbol,
|
|
64735
64781
|
kind: this.kind,
|
|
64736
|
-
update: true
|
|
64782
|
+
update: true,
|
|
64783
|
+
live_refresh
|
|
64737
64784
|
});
|
|
64738
64785
|
let existingOrders = await this.exchange_account.syncOrders({
|
|
64739
64786
|
symbol: this.symbol,
|
|
@@ -64742,29 +64789,448 @@ class ExchangePosition {
|
|
|
64742
64789
|
return { instance, existingOrders };
|
|
64743
64790
|
}
|
|
64744
64791
|
async placeTrade(payload) {
|
|
64745
|
-
const {
|
|
64792
|
+
const {
|
|
64793
|
+
place,
|
|
64794
|
+
tp,
|
|
64795
|
+
raw: _raw,
|
|
64796
|
+
cancel,
|
|
64797
|
+
stop,
|
|
64798
|
+
ignore_config,
|
|
64799
|
+
risky,
|
|
64800
|
+
limit = true,
|
|
64801
|
+
target_pnl
|
|
64802
|
+
} = payload;
|
|
64746
64803
|
if (cancel) {
|
|
64747
64804
|
await this.cancelOrders({
|
|
64748
64805
|
limit: true
|
|
64749
64806
|
});
|
|
64750
64807
|
}
|
|
64751
|
-
if (
|
|
64808
|
+
if (limit) {
|
|
64752
64809
|
return await this.triggerTradeFromConfig({
|
|
64753
|
-
raw:
|
|
64810
|
+
raw: _raw,
|
|
64754
64811
|
stop,
|
|
64755
|
-
ignore_config
|
|
64812
|
+
ignore_config,
|
|
64813
|
+
risky,
|
|
64814
|
+
place
|
|
64756
64815
|
});
|
|
64757
64816
|
}
|
|
64758
64817
|
const rr = await this.refresh(true);
|
|
64759
|
-
await this.
|
|
64818
|
+
await this.updateConfigPnl();
|
|
64760
64819
|
if (tp) {
|
|
64761
64820
|
await this.exchange_account.placeProfitAndStop({
|
|
64762
64821
|
symbol: this.symbol,
|
|
64763
|
-
trigger: true
|
|
64822
|
+
trigger: true,
|
|
64823
|
+
target_pnl
|
|
64764
64824
|
});
|
|
64765
64825
|
}
|
|
64826
|
+
return [];
|
|
64766
64827
|
return rr.existingOrders;
|
|
64767
64828
|
}
|
|
64829
|
+
async placeStopLimit(payload) {
|
|
64830
|
+
const { place, stop, quantity: _quantity } = payload;
|
|
64831
|
+
const kind = this.kind;
|
|
64832
|
+
const symbol = this.symbol;
|
|
64833
|
+
const position2 = this.instance;
|
|
64834
|
+
if (position2.avg_qty && position2.avg_qty > 0) {
|
|
64835
|
+
const spread = 1.00005;
|
|
64836
|
+
const qty = _quantity || position2.avg_qty - position2.quantity;
|
|
64837
|
+
const symbol_config = this.symbol_config;
|
|
64838
|
+
const orders = [
|
|
64839
|
+
{
|
|
64840
|
+
kind,
|
|
64841
|
+
stop,
|
|
64842
|
+
quantity: to_f(qty, symbol_config.decimal_places),
|
|
64843
|
+
side: kind === "long" ? "buy" : "sell",
|
|
64844
|
+
price: to_f(kind === "short" ? stop * spread ** -1 : stop * spread, symbol_config.price_places)
|
|
64845
|
+
}
|
|
64846
|
+
];
|
|
64847
|
+
if (place) {
|
|
64848
|
+
return this.exchange.placeBadStopEntry({
|
|
64849
|
+
symbol,
|
|
64850
|
+
orders,
|
|
64851
|
+
price_places: symbol_config.price_places,
|
|
64852
|
+
decimal_places: symbol_config.decimal_places
|
|
64853
|
+
});
|
|
64854
|
+
}
|
|
64855
|
+
return orders;
|
|
64856
|
+
}
|
|
64857
|
+
return [];
|
|
64858
|
+
}
|
|
64859
|
+
async computeTargetPnl(payload) {
|
|
64860
|
+
const { secondary } = payload;
|
|
64861
|
+
const root_position = this.instance;
|
|
64862
|
+
const reverse_position = secondary.instance;
|
|
64863
|
+
if (reverse_position?.expand?.b_config && root_position.quantity > 0) {
|
|
64864
|
+
const reverse_config = reverse_position.expand.b_config;
|
|
64865
|
+
const diff = Math.abs(reverse_config.stop - root_position.entry);
|
|
64866
|
+
const result = to_f(diff * root_position.quantity);
|
|
64867
|
+
if (root_position.target_pnl !== result) {
|
|
64868
|
+
await this.app_db.update_db_position(root_position, {
|
|
64869
|
+
target_pnl: result
|
|
64870
|
+
});
|
|
64871
|
+
await secondary.getConfig({
|
|
64872
|
+
params: {
|
|
64873
|
+
...reverse_config,
|
|
64874
|
+
risk: result
|
|
64875
|
+
}
|
|
64876
|
+
});
|
|
64877
|
+
}
|
|
64878
|
+
return result;
|
|
64879
|
+
}
|
|
64880
|
+
return 0;
|
|
64881
|
+
}
|
|
64882
|
+
async runSimulation(payload) {
|
|
64883
|
+
const { iterations = 2, raw = false } = payload;
|
|
64884
|
+
const kind = this.kind;
|
|
64885
|
+
const symbol_config = this.symbol_config;
|
|
64886
|
+
const long_position = payload.long_position.instance;
|
|
64887
|
+
const short_position = payload.short_position.instance;
|
|
64888
|
+
const long_config = await payload.long_position.getConfig();
|
|
64889
|
+
const short_config = await payload.short_position.getConfig();
|
|
64890
|
+
const focus_config = kind === "long" ? long_config : short_config;
|
|
64891
|
+
const short_tp_factor = short_config.profit_percent / long_config.profit_percent;
|
|
64892
|
+
const reduce_ratio = focus_config.reduce_ratio;
|
|
64893
|
+
const budget = focus_config.risk;
|
|
64894
|
+
const risk_reward = focus_config.risk_reward;
|
|
64895
|
+
const tp_percent = long_config.profit_percent;
|
|
64896
|
+
const fee_percent = symbol_config.fee_percent;
|
|
64897
|
+
const strategy_config = {
|
|
64898
|
+
tp_percent,
|
|
64899
|
+
short_tp_factor,
|
|
64900
|
+
fee_percent,
|
|
64901
|
+
budget,
|
|
64902
|
+
risk_reward,
|
|
64903
|
+
reduce_ratio,
|
|
64904
|
+
global_config: symbol_config
|
|
64905
|
+
};
|
|
64906
|
+
const strategy2 = new Strategy({
|
|
64907
|
+
long: {
|
|
64908
|
+
entry: long_position.entry,
|
|
64909
|
+
quantity: long_position.quantity,
|
|
64910
|
+
avg_price: long_position.avg_price,
|
|
64911
|
+
avg_qty: long_position.avg_qty
|
|
64912
|
+
},
|
|
64913
|
+
short: {
|
|
64914
|
+
entry: short_position.entry,
|
|
64915
|
+
quantity: short_position.quantity,
|
|
64916
|
+
avg_price: short_position.avg_price,
|
|
64917
|
+
avg_qty: short_position.avg_qty
|
|
64918
|
+
},
|
|
64919
|
+
config: strategy_config
|
|
64920
|
+
});
|
|
64921
|
+
if (raw) {
|
|
64922
|
+
return strategy2;
|
|
64923
|
+
}
|
|
64924
|
+
return strategy2.runIterations({
|
|
64925
|
+
iterations,
|
|
64926
|
+
kind
|
|
64927
|
+
});
|
|
64928
|
+
}
|
|
64929
|
+
async placeOppositeTradeAction(payload) {
|
|
64930
|
+
const { data } = payload;
|
|
64931
|
+
const position2 = this.instance;
|
|
64932
|
+
if (position2.avg_qty !== data.avg.quantity) {
|
|
64933
|
+
const config2 = await this.getConfig();
|
|
64934
|
+
await this.app_db.updateScheduledTrade(config2.id, {
|
|
64935
|
+
entry: data.entry,
|
|
64936
|
+
stop: data.stop,
|
|
64937
|
+
risk: data.risk_per_trade,
|
|
64938
|
+
profit_percent: data.profit_percent,
|
|
64939
|
+
risk_reward: data.risk_reward
|
|
64940
|
+
});
|
|
64941
|
+
await this.placeTrade({
|
|
64942
|
+
place: true,
|
|
64943
|
+
ignore_config: true
|
|
64944
|
+
});
|
|
64945
|
+
await this.placeTrade({
|
|
64946
|
+
place: true,
|
|
64947
|
+
stop: true,
|
|
64948
|
+
ignore_config: true
|
|
64949
|
+
});
|
|
64950
|
+
}
|
|
64951
|
+
}
|
|
64952
|
+
async updateRiskOnEmpty() {
|
|
64953
|
+
const position2 = this.instance;
|
|
64954
|
+
if (position2 && position2.quantity === 0) {
|
|
64955
|
+
if (position2.next_risk && position2.next_risk > 0) {
|
|
64956
|
+
await this.getConfig({
|
|
64957
|
+
params: {
|
|
64958
|
+
risk: position2.next_risk
|
|
64959
|
+
}
|
|
64960
|
+
});
|
|
64961
|
+
console.log(`Updated ${this.kind} position config for ${this.symbol}: risk = ${position2.next_risk}`);
|
|
64962
|
+
return {
|
|
64963
|
+
updated: true,
|
|
64964
|
+
symbol: this.symbol,
|
|
64965
|
+
kind: this.kind,
|
|
64966
|
+
old_risk: position2.expand?.b_config?.risk,
|
|
64967
|
+
new_risk: position2.next_risk
|
|
64968
|
+
};
|
|
64969
|
+
}
|
|
64970
|
+
}
|
|
64971
|
+
return {
|
|
64972
|
+
updated: false,
|
|
64973
|
+
symbol: this.symbol,
|
|
64974
|
+
kind: this.kind,
|
|
64975
|
+
reason: position2 ? position2.quantity > 0 ? "Position not empty" : "No next_risk available" : "Position not found"
|
|
64976
|
+
};
|
|
64977
|
+
}
|
|
64978
|
+
async increasePositionAtStop(payload) {
|
|
64979
|
+
const { place = false, increase = true } = payload;
|
|
64980
|
+
const position2 = this.instance;
|
|
64981
|
+
console.log(position2);
|
|
64982
|
+
let price_params = {
|
|
64983
|
+
price: payload.price,
|
|
64984
|
+
quantity: payload.quantity
|
|
64985
|
+
};
|
|
64986
|
+
if (!payload.price && position2 && position2.stop_loss) {
|
|
64987
|
+
price_params.price = position2.stop_loss.price;
|
|
64988
|
+
}
|
|
64989
|
+
if (!payload.quantity && position2 && position2.stop_loss) {
|
|
64990
|
+
price_params.quantity = position2.stop_loss.quantity;
|
|
64991
|
+
}
|
|
64992
|
+
if (price_params.price && price_params.quantity) {
|
|
64993
|
+
const { price, quantity } = price_params;
|
|
64994
|
+
const symbol_config = this.symbol_config;
|
|
64995
|
+
const price_places = symbol_config.price_places;
|
|
64996
|
+
const decimal_places = symbol_config.decimal_places;
|
|
64997
|
+
if (place) {
|
|
64998
|
+
await this.cancelOrders({
|
|
64999
|
+
limit: true
|
|
65000
|
+
});
|
|
65001
|
+
}
|
|
65002
|
+
return await this.exchange.customStopLoss({
|
|
65003
|
+
symbol: this.symbol,
|
|
65004
|
+
kind: this.kind,
|
|
65005
|
+
stop: price,
|
|
65006
|
+
quantity,
|
|
65007
|
+
price_places,
|
|
65008
|
+
decimal_places,
|
|
65009
|
+
increase,
|
|
65010
|
+
place
|
|
65011
|
+
});
|
|
65012
|
+
}
|
|
65013
|
+
}
|
|
65014
|
+
async placeSingleOrder(payload) {
|
|
65015
|
+
const { long_position, short_position } = payload;
|
|
65016
|
+
const kind = this.kind;
|
|
65017
|
+
const long_config = await long_position.getConfig();
|
|
65018
|
+
const short_config = await short_position.getConfig();
|
|
65019
|
+
const focus_config = kind === "long" ? long_config : short_config;
|
|
65020
|
+
const focus_position = kind === "long" ? long_position.instance : short_position.instance;
|
|
65021
|
+
const track_position = kind === "long" ? short_position.instance : long_position.instance;
|
|
65022
|
+
const follow = focus_config.follow || focus_position.follow;
|
|
65023
|
+
const threshold_qty = focus_config.threshold_qty || focus_position.threshold_qty;
|
|
65024
|
+
if (!follow) {
|
|
65025
|
+
return "No follow set";
|
|
65026
|
+
}
|
|
65027
|
+
let should_place_order = false;
|
|
65028
|
+
if (threshold_qty === 0) {
|
|
65029
|
+
should_place_order = true;
|
|
65030
|
+
}
|
|
65031
|
+
if (threshold_qty > 0 && track_position.quantity >= threshold_qty) {
|
|
65032
|
+
should_place_order = true;
|
|
65033
|
+
}
|
|
65034
|
+
if (focus_position.quantity === 0) {
|
|
65035
|
+
should_place_order = true;
|
|
65036
|
+
}
|
|
65037
|
+
if (track_position.quantity !== focus_position.quantity && focus_position.quantity < track_position.quantity && should_place_order) {
|
|
65038
|
+
const remaining_quantity = Math.abs(track_position.quantity - focus_position.quantity);
|
|
65039
|
+
await this.placeMarketOrder({
|
|
65040
|
+
quantity: remaining_quantity
|
|
65041
|
+
});
|
|
65042
|
+
}
|
|
65043
|
+
}
|
|
65044
|
+
async placeMarketOrder(payload) {
|
|
65045
|
+
const { quantity } = payload;
|
|
65046
|
+
const symbol_config = this.symbol_config;
|
|
65047
|
+
await this.exchange.placeMarketOrder({
|
|
65048
|
+
symbol: this.symbol,
|
|
65049
|
+
kind: this.kind,
|
|
65050
|
+
quantity,
|
|
65051
|
+
price_places: symbol_config.price_places,
|
|
65052
|
+
decimal_places: symbol_config.decimal_places
|
|
65053
|
+
});
|
|
65054
|
+
}
|
|
65055
|
+
async generate_config_params(payload) {
|
|
65056
|
+
const { entry, stop, risk_reward, risk, with_trades = false } = payload;
|
|
65057
|
+
const symbol = this.symbol;
|
|
65058
|
+
const app_config = await this.buildAppConfig({
|
|
65059
|
+
entry,
|
|
65060
|
+
stop,
|
|
65061
|
+
risk_reward,
|
|
65062
|
+
risk
|
|
65063
|
+
});
|
|
65064
|
+
let config2 = generate_config_params(app_config, {
|
|
65065
|
+
entry,
|
|
65066
|
+
stop,
|
|
65067
|
+
risk_reward,
|
|
65068
|
+
risk,
|
|
65069
|
+
symbol
|
|
65070
|
+
});
|
|
65071
|
+
if (with_trades) {
|
|
65072
|
+
const app_config2 = await this.buildAppConfig({
|
|
65073
|
+
entry: config2.entry,
|
|
65074
|
+
stop: config2.stop,
|
|
65075
|
+
risk_reward: config2.risk_reward,
|
|
65076
|
+
risk: config2.risk,
|
|
65077
|
+
profit: 0,
|
|
65078
|
+
update_db: false
|
|
65079
|
+
});
|
|
65080
|
+
const { trades } = await this.placeConfigOrders(app_config2, {
|
|
65081
|
+
risk_reward: config2.risk_reward,
|
|
65082
|
+
entry: config2.entry,
|
|
65083
|
+
stop: config2.stop,
|
|
65084
|
+
risk_per_trade: config2.risk,
|
|
65085
|
+
avg_size: 0,
|
|
65086
|
+
neg_pnl: 0,
|
|
65087
|
+
min_size: app_config2.min_size,
|
|
65088
|
+
symbol
|
|
65089
|
+
}, false);
|
|
65090
|
+
config2.trades = trades;
|
|
65091
|
+
}
|
|
65092
|
+
return { ...config2, place_stop: false, profit_percent: 0 };
|
|
65093
|
+
}
|
|
65094
|
+
async extrapolateConfig(payload) {
|
|
65095
|
+
const { risk_reward = 199, risk, kind } = payload;
|
|
65096
|
+
const position2 = this.instance;
|
|
65097
|
+
if (position2) {
|
|
65098
|
+
let entry = position2.next_order || position2.avg_liquidation;
|
|
65099
|
+
if (kind == "short" && entry < 0) {
|
|
65100
|
+
const symbol_config = this.symbol_config;
|
|
65101
|
+
entry = symbol_config?.support;
|
|
65102
|
+
}
|
|
65103
|
+
return await this.generate_config_params({
|
|
65104
|
+
entry,
|
|
65105
|
+
stop: position2.take_profit,
|
|
65106
|
+
risk_reward,
|
|
65107
|
+
risk: risk || position2.target_pnl
|
|
65108
|
+
});
|
|
65109
|
+
}
|
|
65110
|
+
return null;
|
|
65111
|
+
}
|
|
65112
|
+
async build_short_order() {
|
|
65113
|
+
const kind = this.kind;
|
|
65114
|
+
const position2 = this.instance;
|
|
65115
|
+
const position_config = await this.getConfig();
|
|
65116
|
+
if (position2 && position_config && position2.entry > 0) {
|
|
65117
|
+
let next_order = position2.next_order;
|
|
65118
|
+
let take_profit = position2.take_profit;
|
|
65119
|
+
if (next_order && take_profit) {
|
|
65120
|
+
let config2 = await this.buildConfigForSymbol({
|
|
65121
|
+
risk: position_config.risk,
|
|
65122
|
+
risk_reward: position_config.risk_reward,
|
|
65123
|
+
as_config: true
|
|
65124
|
+
});
|
|
65125
|
+
const focus = config2.entries.filter((x) => {
|
|
65126
|
+
if (kind == "long") {
|
|
65127
|
+
return x.entry <= next_order;
|
|
65128
|
+
} else {
|
|
65129
|
+
return x.entry >= next_order;
|
|
65130
|
+
}
|
|
65131
|
+
});
|
|
65132
|
+
const focus_entry = focus.at(-1);
|
|
65133
|
+
if (focus_entry) {
|
|
65134
|
+
let entry = focus_entry.entry;
|
|
65135
|
+
let risk = Math.abs(focus_entry.neg_pnl);
|
|
65136
|
+
return await this.generate_config_params({
|
|
65137
|
+
entry,
|
|
65138
|
+
stop: take_profit,
|
|
65139
|
+
risk_reward: position_config.risk_reward,
|
|
65140
|
+
risk
|
|
65141
|
+
});
|
|
65142
|
+
}
|
|
65143
|
+
}
|
|
65144
|
+
}
|
|
65145
|
+
}
|
|
65146
|
+
async buildConfigForSymbol(payload) {
|
|
65147
|
+
const kind = this.kind;
|
|
65148
|
+
const { risk, risk_reward = 199, as_config = false } = payload;
|
|
65149
|
+
const symbol_config = this.symbol_config;
|
|
65150
|
+
const long_config = await this.generate_config_params({
|
|
65151
|
+
entry: kind === "long" ? symbol_config.resistance : symbol_config.support,
|
|
65152
|
+
stop: kind === "long" ? symbol_config.support : symbol_config.resistance,
|
|
65153
|
+
risk_reward,
|
|
65154
|
+
risk
|
|
65155
|
+
});
|
|
65156
|
+
if (as_config) {
|
|
65157
|
+
const app_config = buildAppConfig(symbol_config, {
|
|
65158
|
+
entry: long_config.entry,
|
|
65159
|
+
stop: long_config.stop,
|
|
65160
|
+
risk_reward,
|
|
65161
|
+
risk: long_config.risk,
|
|
65162
|
+
symbol: this.symbol
|
|
65163
|
+
});
|
|
65164
|
+
return app_config;
|
|
65165
|
+
}
|
|
65166
|
+
return long_config;
|
|
65167
|
+
}
|
|
65168
|
+
async buildTrades(payload) {
|
|
65169
|
+
const { risk } = payload;
|
|
65170
|
+
const config2 = await this.getConfig();
|
|
65171
|
+
const app_config = await this.buildAppConfig({
|
|
65172
|
+
entry: config2.entry,
|
|
65173
|
+
stop: config2.stop,
|
|
65174
|
+
risk_reward: config2.risk_reward,
|
|
65175
|
+
risk: risk || config2.risk
|
|
65176
|
+
});
|
|
65177
|
+
const { trades } = await this.placeConfigOrders(app_config, {
|
|
65178
|
+
risk_reward: config2.risk_reward,
|
|
65179
|
+
entry: config2.entry,
|
|
65180
|
+
stop: config2.stop,
|
|
65181
|
+
risk_per_trade: risk || config2.risk,
|
|
65182
|
+
avg_size: 0,
|
|
65183
|
+
neg_pnl: 0,
|
|
65184
|
+
min_size: app_config.min_size,
|
|
65185
|
+
symbol: this.symbol,
|
|
65186
|
+
kelly_confidence_factor: config2.kelly?.kelly_confidence_factor,
|
|
65187
|
+
kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
|
|
65188
|
+
kelly_prediction_model: config2.kelly?.kelly_prediction_model,
|
|
65189
|
+
kelly_func: config2.kelly?.kelly_func
|
|
65190
|
+
});
|
|
65191
|
+
const position2 = this.instance;
|
|
65192
|
+
const orders_to_place = await this.determineAmountToBuy({
|
|
65193
|
+
orders: trades.map((x) => ({
|
|
65194
|
+
entry: x.entry,
|
|
65195
|
+
quantity: x.quantity
|
|
65196
|
+
})),
|
|
65197
|
+
kind: this.kind,
|
|
65198
|
+
decimal_places: app_config.decimal_places,
|
|
65199
|
+
price_places: app_config.price_places
|
|
65200
|
+
});
|
|
65201
|
+
const avg_values = determine_average_entry_and_size(orders_to_place.map((u) => ({
|
|
65202
|
+
price: u.entry,
|
|
65203
|
+
quantity: u.quantity
|
|
65204
|
+
})).concat({
|
|
65205
|
+
price: position2.entry,
|
|
65206
|
+
quantity: position2.quantity
|
|
65207
|
+
}), app_config.decimal_places, app_config.price_places);
|
|
65208
|
+
return {
|
|
65209
|
+
trades: orders_to_place,
|
|
65210
|
+
max_size: trades[0].avg_size,
|
|
65211
|
+
last_price: trades[0].entry,
|
|
65212
|
+
total_size: avg_values.quantity,
|
|
65213
|
+
avg_entry: avg_values.price
|
|
65214
|
+
};
|
|
65215
|
+
}
|
|
65216
|
+
async tradeConfig(payload) {
|
|
65217
|
+
const { override = {} } = payload;
|
|
65218
|
+
const config2 = await this.getConfig();
|
|
65219
|
+
const app_config = await this.buildAppConfig({
|
|
65220
|
+
entry: config2.entry,
|
|
65221
|
+
stop: config2.stop,
|
|
65222
|
+
risk_reward: config2.risk_reward,
|
|
65223
|
+
risk: config2.risk,
|
|
65224
|
+
symbol: this.symbol,
|
|
65225
|
+
use_kelly: config2.kelly?.use_kelly,
|
|
65226
|
+
kelly_confidence_factor: config2.kelly?.kelly_confidence_factor,
|
|
65227
|
+
kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
|
|
65228
|
+
kelly_prediction_model: config2.kelly?.kelly_prediction_model,
|
|
65229
|
+
kelly_func: config2.kelly?.kelly_func,
|
|
65230
|
+
...override
|
|
65231
|
+
});
|
|
65232
|
+
return app_config;
|
|
65233
|
+
}
|
|
64768
65234
|
}
|
|
64769
65235
|
|
|
64770
65236
|
// src/exchange-account.ts
|
|
@@ -64815,16 +65281,22 @@ class ExchangeAccount {
|
|
|
64815
65281
|
return result;
|
|
64816
65282
|
}
|
|
64817
65283
|
async initializePositions(payload) {
|
|
65284
|
+
const raw_positions = await this.syncAccount({
|
|
65285
|
+
update: payload.update,
|
|
65286
|
+
symbol: payload.symbol,
|
|
65287
|
+
live_refresh: payload.update
|
|
65288
|
+
});
|
|
64818
65289
|
const positions = await this.syncAccount({
|
|
64819
65290
|
symbol: payload.symbol,
|
|
64820
|
-
as_view:
|
|
65291
|
+
as_view: true
|
|
64821
65292
|
});
|
|
64822
|
-
const
|
|
65293
|
+
const symbol_config = await this.recomputeSymbolConfig({
|
|
64823
65294
|
symbol: payload.symbol
|
|
64824
65295
|
});
|
|
64825
65296
|
const long_position = positions.find((x) => x.kind === "long");
|
|
64826
65297
|
const short_position = positions.find((x) => x.kind === "short");
|
|
64827
65298
|
this.long_position = new ExchangePosition({
|
|
65299
|
+
symbol_config,
|
|
64828
65300
|
exchange: this.exchange,
|
|
64829
65301
|
exchange_account: this,
|
|
64830
65302
|
instance: long_position,
|
|
@@ -64832,6 +65304,7 @@ class ExchangeAccount {
|
|
|
64832
65304
|
without_view: raw_positions.find((x) => x.kind === "long")
|
|
64833
65305
|
});
|
|
64834
65306
|
this.short_position = new ExchangePosition({
|
|
65307
|
+
symbol_config,
|
|
64835
65308
|
exchange: this.exchange,
|
|
64836
65309
|
exchange_account: this,
|
|
64837
65310
|
instance: short_position,
|
|
@@ -64953,44 +65426,26 @@ class ExchangeAccount {
|
|
|
64953
65426
|
}
|
|
64954
65427
|
}
|
|
64955
65428
|
}
|
|
64956
|
-
async
|
|
64957
|
-
const { symbol, kind,
|
|
64958
|
-
let
|
|
64959
|
-
|
|
64960
|
-
|
|
64961
|
-
kind,
|
|
64962
|
-
update: true
|
|
64963
|
-
});
|
|
64964
|
-
if (limit) {
|
|
64965
|
-
return await this.app_db.cancelLimitOrders({
|
|
64966
|
-
raw,
|
|
65429
|
+
async getFocusPosition(payload) {
|
|
65430
|
+
const { symbol, kind, update = false } = payload;
|
|
65431
|
+
let focus_position = kind === "long" ? this.long_position : this.short_position;
|
|
65432
|
+
if (!focus_position) {
|
|
65433
|
+
focus_position = await this.initializePositions({
|
|
64967
65434
|
symbol,
|
|
64968
65435
|
kind,
|
|
64969
|
-
|
|
64970
|
-
cancelExchangeOrders: this.cancelExchangeOrders.bind(this)
|
|
65436
|
+
update
|
|
64971
65437
|
});
|
|
64972
65438
|
}
|
|
64973
|
-
|
|
64974
|
-
|
|
64975
|
-
|
|
64976
|
-
|
|
64977
|
-
|
|
64978
|
-
kind: kind === "short" ? "long" : "short",
|
|
64979
|
-
as_view: true
|
|
64980
|
-
});
|
|
64981
|
-
price = position2?.take_profit || 0;
|
|
64982
|
-
}
|
|
64983
|
-
}
|
|
64984
|
-
let result = await this.app_db.cancelOrders({
|
|
64985
|
-
cancelExchangeOrders: this.cancelExchangeOrders.bind(this),
|
|
64986
|
-
all,
|
|
64987
|
-
kind,
|
|
64988
|
-
account: this.instance,
|
|
65439
|
+
return focus_position;
|
|
65440
|
+
}
|
|
65441
|
+
async cancelOrders(payload) {
|
|
65442
|
+
const { symbol, kind } = payload;
|
|
65443
|
+
const focus_position = await this.getFocusPosition({
|
|
64989
65444
|
symbol,
|
|
64990
|
-
|
|
64991
|
-
|
|
65445
|
+
kind,
|
|
65446
|
+
update: true
|
|
64992
65447
|
});
|
|
64993
|
-
return
|
|
65448
|
+
return await focus_position.cancelOrders(payload);
|
|
64994
65449
|
}
|
|
64995
65450
|
async cancelExchangeOrders(payload) {
|
|
64996
65451
|
return this.exchange.cancelOrders(payload);
|
|
@@ -65007,46 +65462,13 @@ class ExchangeAccount {
|
|
|
65007
65462
|
});
|
|
65008
65463
|
return break_even_price;
|
|
65009
65464
|
}
|
|
65010
|
-
async buildAppConfig(payload) {
|
|
65011
|
-
let config2 = await this.app_db.getSymbolConfigFromDB(payload.symbol);
|
|
65012
|
-
const app_config = buildAppConfig(config2, payload);
|
|
65013
|
-
if (payload.update_db) {
|
|
65014
|
-
const db_position = await this.syncAccount({
|
|
65015
|
-
symbol: payload.symbol,
|
|
65016
|
-
kind: app_config.kind
|
|
65017
|
-
});
|
|
65018
|
-
if (db_position) {
|
|
65019
|
-
await this.app_db.createOrUpdatePositionConfig(db_position, {
|
|
65020
|
-
entry: payload.entry,
|
|
65021
|
-
stop: payload.stop,
|
|
65022
|
-
risk_reward: payload.risk_reward,
|
|
65023
|
-
risk: payload.risk,
|
|
65024
|
-
profit_percent: payload.profit_percent
|
|
65025
|
-
});
|
|
65026
|
-
}
|
|
65027
|
-
}
|
|
65028
|
-
return app_config;
|
|
65029
|
-
}
|
|
65030
65465
|
async tradeConfig(payload) {
|
|
65031
65466
|
const { symbol, kind, override = {} } = payload;
|
|
65032
|
-
const
|
|
65467
|
+
const focus_position = await this.getFocusPosition({
|
|
65033
65468
|
symbol,
|
|
65034
65469
|
kind
|
|
65035
65470
|
});
|
|
65036
|
-
|
|
65037
|
-
entry: config2.entry,
|
|
65038
|
-
stop: config2.stop,
|
|
65039
|
-
risk_reward: config2.risk_reward,
|
|
65040
|
-
risk: config2.risk,
|
|
65041
|
-
symbol,
|
|
65042
|
-
use_kelly: config2.kelly?.use_kelly,
|
|
65043
|
-
kelly_confidence_factor: config2.kelly?.kelly_confidence_factor,
|
|
65044
|
-
kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
|
|
65045
|
-
kelly_prediction_model: config2.kelly?.kelly_prediction_model,
|
|
65046
|
-
kelly_func: config2.kelly?.kelly_func,
|
|
65047
|
-
...override
|
|
65048
|
-
});
|
|
65049
|
-
return app_config;
|
|
65471
|
+
return await focus_position.tradeConfig({ override });
|
|
65050
65472
|
}
|
|
65051
65473
|
async justInTimeProfit(payload) {
|
|
65052
65474
|
const { symbol, target_pnl, kind, refresh, place, take_profit, pause_tp } = payload;
|
|
@@ -65064,7 +65486,7 @@ class ExchangeAccount {
|
|
|
65064
65486
|
});
|
|
65065
65487
|
const current_price = take_profit || position2.current_price;
|
|
65066
65488
|
const notional_value = position2.quantity * position2.entry;
|
|
65067
|
-
const current_pnl =
|
|
65489
|
+
const current_pnl = to_f(Math.abs(current_price - position2.entry) * position2.quantity, "%.2f");
|
|
65068
65490
|
const profit_percent = current_pnl * 100 / notional_value;
|
|
65069
65491
|
const sell_ratio = target_pnl / current_pnl;
|
|
65070
65492
|
if (place) {
|
|
@@ -65108,320 +65530,24 @@ class ExchangeAccount {
|
|
|
65108
65530
|
}
|
|
65109
65531
|
async buildTrades(payload) {
|
|
65110
65532
|
const { symbol, kind, risk } = payload;
|
|
65111
|
-
const
|
|
65533
|
+
const focus_position = await this.getFocusPosition({
|
|
65112
65534
|
symbol,
|
|
65113
65535
|
kind
|
|
65114
65536
|
});
|
|
65115
|
-
|
|
65116
|
-
|
|
65117
|
-
|
|
65118
|
-
|
|
65119
|
-
|
|
65120
|
-
symbol
|
|
65121
|
-
});
|
|
65122
|
-
const { trades } = await this.placeConfigOrders(app_config, {
|
|
65123
|
-
risk_reward: config2.risk_reward,
|
|
65124
|
-
entry: config2.entry,
|
|
65125
|
-
stop: config2.stop,
|
|
65126
|
-
risk_per_trade: risk || config2.risk,
|
|
65127
|
-
avg_size: 0,
|
|
65128
|
-
neg_pnl: 0,
|
|
65129
|
-
min_size: app_config.min_size,
|
|
65130
|
-
symbol
|
|
65131
|
-
});
|
|
65132
|
-
const position2 = await this.syncAccount({
|
|
65133
|
-
symbol,
|
|
65537
|
+
return await focus_position.buildTrades({ risk });
|
|
65538
|
+
}
|
|
65539
|
+
async placeSharedOrder(action, payload) {
|
|
65540
|
+
const kind = payload.entry > payload.stop ? "long" : "short";
|
|
65541
|
+
const focus_position = await this.getFocusPosition({
|
|
65542
|
+
symbol: payload.symbol,
|
|
65134
65543
|
kind
|
|
65135
65544
|
});
|
|
65136
|
-
const
|
|
65137
|
-
|
|
65138
|
-
entry: x.entry,
|
|
65139
|
-
quantity: x.quantity
|
|
65140
|
-
})),
|
|
65141
|
-
kind,
|
|
65142
|
-
decimal_places: app_config.decimal_places,
|
|
65143
|
-
price_places: app_config.price_places,
|
|
65144
|
-
symbol
|
|
65145
|
-
});
|
|
65146
|
-
const avg_values = determine_average_entry_and_size(orders_to_place.map((u) => ({
|
|
65147
|
-
price: u.entry,
|
|
65148
|
-
quantity: u.quantity
|
|
65149
|
-
})).concat({
|
|
65150
|
-
price: position2.entry,
|
|
65151
|
-
quantity: position2.quantity
|
|
65152
|
-
}), app_config.decimal_places, app_config.price_places);
|
|
65153
|
-
return {
|
|
65154
|
-
trades: orders_to_place,
|
|
65155
|
-
max_size: trades[0].avg_size,
|
|
65156
|
-
last_price: trades[0].entry,
|
|
65157
|
-
total_size: avg_values.quantity,
|
|
65158
|
-
avg_entry: avg_values.price
|
|
65159
|
-
};
|
|
65160
|
-
}
|
|
65161
|
-
async placeConfigOrders(app_config, solution, place, skip_stop) {
|
|
65162
|
-
const { stop_percent = 100 } = solution;
|
|
65163
|
-
app_config.entry = solution.entry;
|
|
65164
|
-
app_config.stop = solution.stop;
|
|
65165
|
-
app_config.risk_per_trade = solution.risk_per_trade;
|
|
65166
|
-
app_config.min_size = solution.min_size;
|
|
65167
|
-
app_config.risk_reward = solution.risk_reward;
|
|
65168
|
-
app_config.kelly = {
|
|
65169
|
-
use_kelly: solution.use_kelly,
|
|
65170
|
-
kelly_confidence_factor: solution.kelly_confidence_factor,
|
|
65171
|
-
kelly_minimum_risk: solution.kelly_minimum_risk,
|
|
65172
|
-
kelly_prediction_model: solution.kelly_prediction_model,
|
|
65173
|
-
kelly_func: solution.kelly_func
|
|
65174
|
-
};
|
|
65175
|
-
const options = {
|
|
65176
|
-
take_profit: null,
|
|
65177
|
-
entry: app_config.entry,
|
|
65178
|
-
stop: app_config.stop,
|
|
65179
|
-
raw_instance: null,
|
|
65180
|
-
risk: app_config.risk_per_trade,
|
|
65181
|
-
no_of_trades: undefined,
|
|
65182
|
-
risk_reward: app_config.risk_reward,
|
|
65183
|
-
kind: app_config.kind,
|
|
65184
|
-
increase: true,
|
|
65185
|
-
gap: app_config.gap,
|
|
65186
|
-
rr: app_config.rr,
|
|
65187
|
-
price_places: app_config.price_places,
|
|
65188
|
-
decimal_places: app_config.decimal_places,
|
|
65189
|
-
use_kelly: solution.use_kelly,
|
|
65190
|
-
kelly_confidence_factor: solution.kelly_confidence_factor,
|
|
65191
|
-
kelly_minimum_risk: solution.kelly_minimum_risk,
|
|
65192
|
-
kelly_prediction_model: solution.kelly_prediction_model,
|
|
65193
|
-
kelly_func: solution.kelly_func
|
|
65194
|
-
};
|
|
65195
|
-
const trades = sortedBuildConfig(app_config, options);
|
|
65196
|
-
const entry_orders = {
|
|
65197
|
-
orders: trades.map((x) => ({
|
|
65198
|
-
entry: x.entry,
|
|
65199
|
-
quantity: x.quantity,
|
|
65200
|
-
reverse_avg_entry: x.reverse_avg_entry,
|
|
65201
|
-
reverse_avg_quantity: x.reverse_avg_quantity,
|
|
65202
|
-
avg_entry: x.avg_entry,
|
|
65203
|
-
avg_size: x.avg_size
|
|
65204
|
-
})),
|
|
65205
|
-
kind: app_config.kind
|
|
65206
|
-
};
|
|
65207
|
-
const last_order = trades[0]?.entry;
|
|
65208
|
-
const stop_spread = stop_percent / 100;
|
|
65209
|
-
const _stop = app_config.kind === "short" ? last_order * (1 + stop_spread) : last_order * (1 - stop_spread);
|
|
65210
|
-
const stop_to_user = stop_percent === 100 ? solution.stop : _stop;
|
|
65211
|
-
const stop_orders = {
|
|
65212
|
-
stop: stop_to_user,
|
|
65213
|
-
final_stop: stop_to_user,
|
|
65214
|
-
kind: app_config.kind,
|
|
65215
|
-
quantity: trades[0]?.avg_size,
|
|
65216
|
-
is_limit: true,
|
|
65217
|
-
neg_pnl: trades[0]?.neg_pnl,
|
|
65218
|
-
original_stop: solution.stop,
|
|
65219
|
-
last_entry: last_order
|
|
65220
|
-
};
|
|
65221
|
-
if (place) {
|
|
65222
|
-
let arr = [
|
|
65223
|
-
this.exchange.bulkPlaceLimitOrders({
|
|
65224
|
-
orders: trades.map((x) => ({
|
|
65225
|
-
entry: x.entry,
|
|
65226
|
-
quantity: x.quantity
|
|
65227
|
-
})),
|
|
65228
|
-
kind: app_config.kind,
|
|
65229
|
-
decimal_places: app_config.decimal_places,
|
|
65230
|
-
price_places: app_config.price_places,
|
|
65231
|
-
symbol: solution.symbol,
|
|
65232
|
-
place
|
|
65233
|
-
})
|
|
65234
|
-
];
|
|
65235
|
-
if (!skip_stop) {
|
|
65236
|
-
arr.push(this.exchange.placeStopOrders({
|
|
65237
|
-
symbol: solution.symbol,
|
|
65238
|
-
quantity: trades[0].avg_size,
|
|
65239
|
-
kind: app_config.kind,
|
|
65240
|
-
stop: solution.stop,
|
|
65241
|
-
price_places: app_config.price_places,
|
|
65242
|
-
decimal_places: app_config.decimal_places,
|
|
65243
|
-
place
|
|
65244
|
-
}));
|
|
65245
|
-
}
|
|
65246
|
-
await Promise.all(arr);
|
|
65247
|
-
}
|
|
65248
|
-
return {
|
|
65249
|
-
entry_orders,
|
|
65250
|
-
stop_orders,
|
|
65251
|
-
trades
|
|
65252
|
-
};
|
|
65253
|
-
}
|
|
65254
|
-
async determineAmountToBuy(payload) {
|
|
65255
|
-
const {
|
|
65256
|
-
orders,
|
|
65257
|
-
kind,
|
|
65258
|
-
decimal_places = "%.3f",
|
|
65259
|
-
symbol,
|
|
65260
|
-
refresh,
|
|
65261
|
-
cancel
|
|
65262
|
-
} = payload;
|
|
65263
|
-
const totalQuantity = orders.reduce((sum, order) => sum + (order.quantity || 0), 0);
|
|
65264
|
-
let runningTotal = to_f2(totalQuantity, decimal_places);
|
|
65265
|
-
let sortedOrders = [...orders].sort((a, b) => (a.entry || 0) - (b.entry || 0));
|
|
65266
|
-
if (kind === "short") {
|
|
65267
|
-
sortedOrders.reverse();
|
|
65268
|
-
}
|
|
65269
|
-
const withCumulative = [];
|
|
65270
|
-
for (const order of sortedOrders) {
|
|
65271
|
-
withCumulative.push({
|
|
65272
|
-
...order,
|
|
65273
|
-
cumulative_quantity: runningTotal
|
|
65274
|
-
});
|
|
65275
|
-
runningTotal -= order.quantity;
|
|
65276
|
-
runningTotal = to_f2(runningTotal, decimal_places);
|
|
65277
|
-
}
|
|
65278
|
-
const position2 = await this.syncAccount({
|
|
65279
|
-
symbol,
|
|
65280
|
-
kind,
|
|
65281
|
-
live_refresh: refresh,
|
|
65282
|
-
update: true
|
|
65283
|
-
});
|
|
65284
|
-
let existingOrders = await this.syncOrders({
|
|
65285
|
-
symbol,
|
|
65286
|
-
kind
|
|
65287
|
-
});
|
|
65288
|
-
let filteredOrders = withCumulative.filter((order) => (order.cumulative_quantity || 0) > position2?.quantity).map((order) => ({
|
|
65289
|
-
...order,
|
|
65290
|
-
price: order.entry,
|
|
65291
|
-
kind,
|
|
65292
|
-
side: kind.toLowerCase() === "long" ? "buy" : "sell"
|
|
65293
|
-
}));
|
|
65294
|
-
filteredOrders = filteredOrders.filter((k) => !existingOrders.map((j) => j.price).includes(k.price));
|
|
65295
|
-
const side = kind.toLowerCase() === "long" ? "buy" : "sell";
|
|
65296
|
-
const shouldCancel = existingOrders.filter((k) => !orders.map((j) => j.entry).includes(k.price) && k.side === side).map((u) => u.price);
|
|
65297
|
-
if (shouldCancel.length > 0 && cancel) {
|
|
65298
|
-
const pp = kind === "long" ? Math.max(...shouldCancel) : Math.min(...shouldCancel);
|
|
65299
|
-
const cancel_orders = await this.cancelOrders({
|
|
65300
|
-
symbol,
|
|
65301
|
-
kind,
|
|
65302
|
-
price: pp
|
|
65303
|
-
});
|
|
65304
|
-
console.log("cancel_orders", cancel_orders);
|
|
65305
|
-
}
|
|
65306
|
-
return filteredOrders;
|
|
65307
|
-
}
|
|
65308
|
-
async placeSharedOrder(action, payload) {
|
|
65309
|
-
const { stop_percent = 100 } = payload;
|
|
65310
|
-
const kind = payload.entry > payload.stop ? "long" : "short";
|
|
65311
|
-
const config2 = await this.getPositionConfig({
|
|
65312
|
-
symbol: payload.symbol,
|
|
65313
|
-
kind
|
|
65314
|
-
});
|
|
65315
|
-
const app_config = await this.buildAppConfig({
|
|
65316
|
-
entry: payload.entry,
|
|
65317
|
-
stop: payload.stop,
|
|
65318
|
-
risk_reward: payload.risk_reward,
|
|
65319
|
-
risk: payload.risk,
|
|
65545
|
+
const result = await focus_position.placeSharedOrder(action, payload);
|
|
65546
|
+
await this.getLiveExchangeInstance({
|
|
65320
65547
|
symbol: payload.symbol,
|
|
65321
|
-
|
|
65322
|
-
update_db: payload.update_db,
|
|
65323
|
-
use_kelly: config2.kelly?.use_kelly,
|
|
65324
|
-
kelly_confidence_factor: config2.kelly?.kelly_confidence_factor,
|
|
65325
|
-
kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
|
|
65326
|
-
kelly_prediction_model: config2.kelly?.kelly_prediction_model,
|
|
65327
|
-
kelly_func: config2.kelly?.kelly_func
|
|
65548
|
+
refresh: true
|
|
65328
65549
|
});
|
|
65329
|
-
|
|
65330
|
-
risk_reward: payload.risk_reward,
|
|
65331
|
-
entry: payload.entry,
|
|
65332
|
-
stop: payload.stop,
|
|
65333
|
-
risk_per_trade: payload.risk,
|
|
65334
|
-
avg_size: 0,
|
|
65335
|
-
neg_pnl: 0,
|
|
65336
|
-
min_size: app_config.min_size,
|
|
65337
|
-
symbol: payload.symbol,
|
|
65338
|
-
stop_percent,
|
|
65339
|
-
use_kelly: config2.kelly?.use_kelly,
|
|
65340
|
-
kelly_confidence_factor: config2.kelly?.kelly_confidence_factor,
|
|
65341
|
-
kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
|
|
65342
|
-
kelly_prediction_model: config2.kelly?.kelly_prediction_model,
|
|
65343
|
-
kelly_func: config2.kelly?.kelly_func
|
|
65344
|
-
}, false);
|
|
65345
|
-
if (payload.raw) {
|
|
65346
|
-
let actual_orders_to_buy = await this.determineAmountToBuy({
|
|
65347
|
-
orders: trades,
|
|
65348
|
-
kind: app_config.kind,
|
|
65349
|
-
decimal_places: app_config.decimal_places,
|
|
65350
|
-
price_places: app_config.price_places,
|
|
65351
|
-
symbol: payload.symbol,
|
|
65352
|
-
place: payload.place
|
|
65353
|
-
});
|
|
65354
|
-
if (action === "place_limit_orders" && payload.place) {
|
|
65355
|
-
return await this.exchange.createLimitPurchaseOrders({
|
|
65356
|
-
orders: actual_orders_to_buy.map((x) => ({
|
|
65357
|
-
entry: x.entry,
|
|
65358
|
-
quantity: x.quantity
|
|
65359
|
-
})),
|
|
65360
|
-
kind: app_config.kind,
|
|
65361
|
-
decimal_places: app_config.decimal_places,
|
|
65362
|
-
price_places: app_config.price_places,
|
|
65363
|
-
symbol: payload.symbol
|
|
65364
|
-
});
|
|
65365
|
-
}
|
|
65366
|
-
return actual_orders_to_buy;
|
|
65367
|
-
}
|
|
65368
|
-
if (action === "place_limit_orders" && payload.place) {
|
|
65369
|
-
let result = await this.exchange.bulkPlaceLimitOrders({
|
|
65370
|
-
orders: trades.map((x) => ({
|
|
65371
|
-
entry: x.entry,
|
|
65372
|
-
quantity: x.quantity
|
|
65373
|
-
})),
|
|
65374
|
-
kind: app_config.kind,
|
|
65375
|
-
price_places: app_config.price_places,
|
|
65376
|
-
decimal_places: app_config.decimal_places,
|
|
65377
|
-
symbol: payload.symbol,
|
|
65378
|
-
place: payload.place
|
|
65379
|
-
});
|
|
65380
|
-
await this.getLiveExchangeInstance({
|
|
65381
|
-
symbol: payload.symbol,
|
|
65382
|
-
refresh: true
|
|
65383
|
-
});
|
|
65384
|
-
return result;
|
|
65385
|
-
}
|
|
65386
|
-
if (action == "dangerous_entry_orders" && payload.place) {
|
|
65387
|
-
return await this.exchange.createLimitPurchaseOrders({
|
|
65388
|
-
orders: trades.map((x) => ({
|
|
65389
|
-
...x,
|
|
65390
|
-
price: x.entry,
|
|
65391
|
-
quantity: x.quantity,
|
|
65392
|
-
side: app_config.kind === "long" ? "buy" : "sell",
|
|
65393
|
-
kind: app_config.kind
|
|
65394
|
-
})),
|
|
65395
|
-
kind: app_config.kind,
|
|
65396
|
-
decimal_places: app_config.decimal_places,
|
|
65397
|
-
price_places: app_config.price_places,
|
|
65398
|
-
symbol: payload.symbol
|
|
65399
|
-
});
|
|
65400
|
-
}
|
|
65401
|
-
if (action === "place_stop_orders" && payload.place) {
|
|
65402
|
-
const instance = await this.syncAccount({
|
|
65403
|
-
symbol: payload.symbol,
|
|
65404
|
-
kind: app_config.kind
|
|
65405
|
-
});
|
|
65406
|
-
let result = await this.exchange.placeStopOrders({
|
|
65407
|
-
symbol: payload.symbol,
|
|
65408
|
-
quantity: payload.use_current ? instance.quantity : trades[0].avg_size,
|
|
65409
|
-
kind: app_config.kind,
|
|
65410
|
-
stop: stop_orders.stop,
|
|
65411
|
-
price_places: app_config.price_places,
|
|
65412
|
-
decimal_places: app_config.decimal_places,
|
|
65413
|
-
place: true
|
|
65414
|
-
});
|
|
65415
|
-
await this.getLiveExchangeInstance({
|
|
65416
|
-
symbol: payload.symbol,
|
|
65417
|
-
refresh: true
|
|
65418
|
-
});
|
|
65419
|
-
return result;
|
|
65420
|
-
}
|
|
65421
|
-
return {
|
|
65422
|
-
entry_orders,
|
|
65423
|
-
stop_orders
|
|
65424
|
-
};
|
|
65550
|
+
return result;
|
|
65425
65551
|
}
|
|
65426
65552
|
async getOrCreatePositionConfig(payload) {
|
|
65427
65553
|
const { symbol, kind, risk = 50, risk_reward = 199 } = payload;
|
|
@@ -65449,29 +65575,9 @@ class ExchangeAccount {
|
|
|
65449
65575
|
return config2;
|
|
65450
65576
|
}
|
|
65451
65577
|
async getPositionConfig(payload) {
|
|
65452
|
-
|
|
65453
|
-
|
|
65454
|
-
|
|
65455
|
-
kind: payload.kind
|
|
65456
|
-
});
|
|
65457
|
-
if (db_position) {
|
|
65458
|
-
const config2 = db_position.expand?.config;
|
|
65459
|
-
const params = {
|
|
65460
|
-
entry: payload.params.entry !== undefined ? payload.params.entry : config2?.entry,
|
|
65461
|
-
stop: payload.params.stop !== undefined ? payload.params.stop : config2?.stop,
|
|
65462
|
-
risk_reward: payload.params.risk_reward !== undefined ? payload.params.risk_reward : config2?.risk_reward,
|
|
65463
|
-
risk: payload.params.risk !== undefined ? payload.params.risk : config2?.risk,
|
|
65464
|
-
profit_percent: payload.params.profit_percent !== undefined ? payload.params.profit_percent : config2?.profit_percent,
|
|
65465
|
-
place_tp: payload.params.place_tp !== undefined ? payload.params.place_tp : true,
|
|
65466
|
-
profit: payload.params.profit !== undefined ? payload.params.profit : config2?.profit
|
|
65467
|
-
};
|
|
65468
|
-
return await this.app_db.createOrUpdatePositionConfig(db_position, params);
|
|
65469
|
-
}
|
|
65470
|
-
}
|
|
65471
|
-
return await this.app_db.getPositionConfig({
|
|
65472
|
-
symbol: payload.symbol,
|
|
65473
|
-
kind: payload.kind,
|
|
65474
|
-
account: this.instance
|
|
65578
|
+
const focus_position = await this.getFocusPosition(payload);
|
|
65579
|
+
return await focus_position.getConfig({
|
|
65580
|
+
params: payload.params
|
|
65475
65581
|
});
|
|
65476
65582
|
}
|
|
65477
65583
|
async getCurrentPrice(symbol) {
|
|
@@ -65484,23 +65590,23 @@ class ExchangeAccount {
|
|
|
65484
65590
|
});
|
|
65485
65591
|
}
|
|
65486
65592
|
async buildReduceConfig(payload) {
|
|
65487
|
-
const
|
|
65488
|
-
symbol: payload.symbol
|
|
65489
|
-
});
|
|
65490
|
-
const long_position = positions.find((x) => x.kind === "long");
|
|
65491
|
-
const short_position = positions.find((x) => x.kind === "short");
|
|
65492
|
-
const long_config = await this.getPositionConfig({
|
|
65593
|
+
const long_position = await this.getFocusPosition({
|
|
65493
65594
|
symbol: payload.symbol,
|
|
65494
65595
|
kind: "long"
|
|
65495
65596
|
});
|
|
65496
|
-
const
|
|
65597
|
+
const short_position = await this.getFocusPosition({
|
|
65497
65598
|
symbol: payload.symbol,
|
|
65498
65599
|
kind: "short"
|
|
65499
65600
|
});
|
|
65601
|
+
const long_config = await long_position.getConfig();
|
|
65602
|
+
const short_config = await short_position.getConfig();
|
|
65500
65603
|
const config2 = build_reduce_config({
|
|
65501
65604
|
account: this.instance,
|
|
65502
65605
|
symbol: payload.symbol,
|
|
65503
|
-
_positions:
|
|
65606
|
+
_positions: [
|
|
65607
|
+
long_position.getInstance(),
|
|
65608
|
+
short_position.getInstance()
|
|
65609
|
+
],
|
|
65504
65610
|
long_config,
|
|
65505
65611
|
short_config
|
|
65506
65612
|
});
|
|
@@ -65509,8 +65615,8 @@ class ExchangeAccount {
|
|
|
65509
65615
|
}
|
|
65510
65616
|
let long_target_pnl = payload.kind == "long" ? payload.target_pnl : 0;
|
|
65511
65617
|
let short_target_pnl = payload.kind == "short" ? payload.target_pnl : 0;
|
|
65512
|
-
const long_sell_ratio = long_config.sell_ratio || long_position?.sell_ratio;
|
|
65513
|
-
const short_sell_ratio = short_config.sell_ratio || short_position?.sell_ratio;
|
|
65618
|
+
const long_sell_ratio = long_config.sell_ratio || long_position.getInstance()?.sell_ratio;
|
|
65619
|
+
const short_sell_ratio = short_config.sell_ratio || short_position.getInstance()?.sell_ratio;
|
|
65514
65620
|
if (payload.as_dict) {
|
|
65515
65621
|
return {
|
|
65516
65622
|
long: {
|
|
@@ -65590,9 +65696,9 @@ class ExchangeAccount {
|
|
|
65590
65696
|
async placeProfitAndStop(payload) {
|
|
65591
65697
|
const { symbol, trigger: trigger2, refresh, kind, target_pnl } = payload;
|
|
65592
65698
|
if (refresh) {
|
|
65593
|
-
await this.
|
|
65699
|
+
await this.initializePositions({
|
|
65594
65700
|
symbol,
|
|
65595
|
-
|
|
65701
|
+
kind,
|
|
65596
65702
|
update: true
|
|
65597
65703
|
});
|
|
65598
65704
|
}
|
|
@@ -65625,14 +65731,16 @@ class ExchangeAccount {
|
|
|
65625
65731
|
kind
|
|
65626
65732
|
});
|
|
65627
65733
|
}
|
|
65628
|
-
const
|
|
65734
|
+
const long_position = await this.getFocusPosition({
|
|
65629
65735
|
symbol,
|
|
65630
65736
|
kind: "long"
|
|
65631
65737
|
});
|
|
65632
|
-
const
|
|
65738
|
+
const short_position = await this.getFocusPosition({
|
|
65633
65739
|
symbol,
|
|
65634
65740
|
kind: "short"
|
|
65635
65741
|
});
|
|
65742
|
+
const long_config = await long_position.getConfig();
|
|
65743
|
+
const short_config = await short_position.getConfig();
|
|
65636
65744
|
const long_pause_tp = long_config?.pause_tp;
|
|
65637
65745
|
const short_pause_tp = short_config?.pause_tp;
|
|
65638
65746
|
if (payload.trigger && !long_pause_tp && !short_pause_tp && config2) {
|
|
@@ -65646,299 +65754,75 @@ class ExchangeAccount {
|
|
|
65646
65754
|
return config2;
|
|
65647
65755
|
}
|
|
65648
65756
|
async reEnterPositionOnEmpty(symbol) {
|
|
65649
|
-
await this.
|
|
65757
|
+
const long_position = await this.getFocusPosition({
|
|
65650
65758
|
symbol,
|
|
65651
|
-
|
|
65759
|
+
kind: "long"
|
|
65652
65760
|
});
|
|
65653
|
-
const
|
|
65761
|
+
const short_position = await this.getFocusPosition({
|
|
65654
65762
|
symbol,
|
|
65655
|
-
|
|
65763
|
+
kind: "short"
|
|
65656
65764
|
});
|
|
65657
|
-
|
|
65658
|
-
|
|
65659
|
-
if (long_position && long_position.quantity === 0) {
|
|
65660
|
-
await this.triggerTradeFromConfig({
|
|
65661
|
-
symbol,
|
|
65662
|
-
kind: "long"
|
|
65663
|
-
});
|
|
65765
|
+
if (long_position && long_position.getInstance().quantity === 0) {
|
|
65766
|
+
await long_position.triggerTradeFromConfig({});
|
|
65664
65767
|
}
|
|
65665
|
-
if (short_position && short_position.quantity === 0) {
|
|
65666
|
-
await
|
|
65667
|
-
symbol,
|
|
65668
|
-
kind: "short"
|
|
65669
|
-
});
|
|
65768
|
+
if (short_position && short_position.getInstance().quantity === 0) {
|
|
65769
|
+
await short_position.triggerTradeFromConfig({});
|
|
65670
65770
|
}
|
|
65671
|
-
if (long_position.target_pnl > 0 || short_position.target_pnl > 0) {
|
|
65771
|
+
if (long_position.getInstance().target_pnl > 0 || short_position.getInstance().target_pnl > 0) {
|
|
65672
65772
|
await Promise.all([
|
|
65673
|
-
|
|
65674
|
-
|
|
65675
|
-
kind: "long"
|
|
65676
|
-
}),
|
|
65677
|
-
this.updateTargetPnl({
|
|
65678
|
-
symbol,
|
|
65679
|
-
kind: "short"
|
|
65680
|
-
})
|
|
65773
|
+
long_position.updateTargetPnl(),
|
|
65774
|
+
short_position.updateTargetPnl()
|
|
65681
65775
|
]);
|
|
65682
65776
|
}
|
|
65683
65777
|
}
|
|
65684
|
-
async generate_config_params(payload) {
|
|
65685
|
-
const {
|
|
65686
|
-
entry,
|
|
65687
|
-
stop,
|
|
65688
|
-
risk_reward,
|
|
65689
|
-
risk,
|
|
65690
|
-
symbol,
|
|
65691
|
-
with_trades = false
|
|
65692
|
-
} = payload;
|
|
65693
|
-
const app_config = await this.buildAppConfig({
|
|
65694
|
-
entry,
|
|
65695
|
-
stop,
|
|
65696
|
-
risk_reward,
|
|
65697
|
-
risk,
|
|
65698
|
-
symbol
|
|
65699
|
-
});
|
|
65700
|
-
let config2 = generate_config_params(app_config, {
|
|
65701
|
-
entry,
|
|
65702
|
-
stop,
|
|
65703
|
-
risk_reward,
|
|
65704
|
-
risk,
|
|
65705
|
-
symbol
|
|
65706
|
-
});
|
|
65707
|
-
if (with_trades) {
|
|
65708
|
-
const app_config2 = await this.buildAppConfig({
|
|
65709
|
-
entry: config2.entry,
|
|
65710
|
-
stop: config2.stop,
|
|
65711
|
-
risk_reward: config2.risk_reward,
|
|
65712
|
-
risk: config2.risk,
|
|
65713
|
-
symbol,
|
|
65714
|
-
profit: 0,
|
|
65715
|
-
update_db: false
|
|
65716
|
-
});
|
|
65717
|
-
const { trades } = await this.placeConfigOrders(app_config2, {
|
|
65718
|
-
risk_reward: config2.risk_reward,
|
|
65719
|
-
entry: config2.entry,
|
|
65720
|
-
stop: config2.stop,
|
|
65721
|
-
risk_per_trade: config2.risk,
|
|
65722
|
-
avg_size: 0,
|
|
65723
|
-
neg_pnl: 0,
|
|
65724
|
-
min_size: app_config2.min_size,
|
|
65725
|
-
symbol
|
|
65726
|
-
}, false);
|
|
65727
|
-
config2.trades = trades;
|
|
65728
|
-
}
|
|
65729
|
-
return { ...config2, place_stop: false, profit_percent: 0 };
|
|
65730
|
-
}
|
|
65731
65778
|
async build_short_order(payload) {
|
|
65732
|
-
const
|
|
65733
|
-
|
|
65734
|
-
symbol,
|
|
65735
|
-
kind,
|
|
65736
|
-
as_view: true
|
|
65737
|
-
});
|
|
65738
|
-
const position_config = await this.getPositionConfig({
|
|
65739
|
-
symbol,
|
|
65740
|
-
kind
|
|
65741
|
-
});
|
|
65742
|
-
if (position2 && position_config && position2.entry > 0) {
|
|
65743
|
-
let next_order = position2.next_order;
|
|
65744
|
-
let take_profit = position2.take_profit;
|
|
65745
|
-
if (next_order && take_profit) {
|
|
65746
|
-
let config2 = await this.buildConfigForSymbol({
|
|
65747
|
-
symbol,
|
|
65748
|
-
risk: position_config.risk,
|
|
65749
|
-
risk_reward: position_config.risk_reward,
|
|
65750
|
-
kind,
|
|
65751
|
-
as_config: true
|
|
65752
|
-
});
|
|
65753
|
-
const focus = config2.entries.filter((x) => {
|
|
65754
|
-
if (kind == "long") {
|
|
65755
|
-
return x.entry <= next_order;
|
|
65756
|
-
} else {
|
|
65757
|
-
return x.entry >= next_order;
|
|
65758
|
-
}
|
|
65759
|
-
});
|
|
65760
|
-
const focus_entry = focus.at(-1);
|
|
65761
|
-
if (focus_entry) {
|
|
65762
|
-
let entry = focus_entry.entry;
|
|
65763
|
-
let risk = Math.abs(focus_entry.neg_pnl);
|
|
65764
|
-
return await this.generate_config_params({
|
|
65765
|
-
entry,
|
|
65766
|
-
stop: take_profit,
|
|
65767
|
-
risk_reward: position_config.risk_reward,
|
|
65768
|
-
risk,
|
|
65769
|
-
symbol
|
|
65770
|
-
});
|
|
65771
|
-
}
|
|
65772
|
-
}
|
|
65773
|
-
}
|
|
65779
|
+
const focus_position = await this.getFocusPosition(payload);
|
|
65780
|
+
return await focus_position.build_short_order();
|
|
65774
65781
|
}
|
|
65775
65782
|
async extrapolateShortConfig(payload) {
|
|
65776
|
-
const { symbol,
|
|
65783
|
+
const { symbol, kind } = payload;
|
|
65777
65784
|
let reverse_kind = kind === "long" ? "short" : "long";
|
|
65778
|
-
const
|
|
65785
|
+
const focus_position = await this.getFocusPosition({
|
|
65779
65786
|
symbol,
|
|
65780
|
-
kind: reverse_kind
|
|
65781
|
-
|
|
65787
|
+
kind: reverse_kind
|
|
65788
|
+
});
|
|
65789
|
+
return await focus_position.extrapolateConfig({
|
|
65790
|
+
kind
|
|
65782
65791
|
});
|
|
65783
|
-
if (position2) {
|
|
65784
|
-
let entry = position2.next_order || position2.avg_liquidation;
|
|
65785
|
-
if (kind == "short" && entry < 0) {
|
|
65786
|
-
const symbol_config = await this.recomputeSymbolConfig({
|
|
65787
|
-
symbol
|
|
65788
|
-
});
|
|
65789
|
-
entry = symbol_config?.support;
|
|
65790
|
-
}
|
|
65791
|
-
return await this.generate_config_params({
|
|
65792
|
-
entry,
|
|
65793
|
-
stop: position2.take_profit,
|
|
65794
|
-
risk_reward,
|
|
65795
|
-
risk: risk || position2.target_pnl,
|
|
65796
|
-
symbol
|
|
65797
|
-
});
|
|
65798
|
-
}
|
|
65799
|
-
return null;
|
|
65800
65792
|
}
|
|
65801
65793
|
async placeMarketOrder(payload) {
|
|
65802
|
-
const { symbol, kind
|
|
65803
|
-
const
|
|
65804
|
-
|
|
65805
|
-
|
|
65806
|
-
await this.exchange.placeMarketOrder({
|
|
65794
|
+
const { symbol, kind } = payload;
|
|
65795
|
+
const focus_position = await this.getFocusPosition(payload);
|
|
65796
|
+
await focus_position.placeMarketOrder(payload);
|
|
65797
|
+
await this.initializePositions({
|
|
65807
65798
|
symbol,
|
|
65808
65799
|
kind,
|
|
65809
|
-
|
|
65810
|
-
price_places: symbol_config.price_places,
|
|
65811
|
-
decimal_places: symbol_config.decimal_places
|
|
65812
|
-
});
|
|
65813
|
-
await this.syncAccount({
|
|
65814
|
-
symbol,
|
|
65815
|
-
update: true,
|
|
65816
|
-
live_refresh: true
|
|
65800
|
+
update: true
|
|
65817
65801
|
});
|
|
65818
65802
|
}
|
|
65819
65803
|
async placeSingleOrder(payload) {
|
|
65820
65804
|
const { symbol, kind } = payload;
|
|
65821
|
-
const
|
|
65822
|
-
live_refresh: true,
|
|
65823
|
-
update: true,
|
|
65824
|
-
symbol
|
|
65825
|
-
});
|
|
65826
|
-
const long_position = positions.find((x) => x.kind === "long");
|
|
65827
|
-
const short_position = positions.find((x) => x.kind === "short");
|
|
65828
|
-
const long_config = await this.getPositionConfig({
|
|
65805
|
+
const long_position = await this.getFocusPosition({
|
|
65829
65806
|
symbol,
|
|
65830
65807
|
kind: "long"
|
|
65831
65808
|
});
|
|
65832
|
-
const
|
|
65809
|
+
const short_position = await this.getFocusPosition({
|
|
65833
65810
|
symbol,
|
|
65834
65811
|
kind: "short"
|
|
65835
65812
|
});
|
|
65836
|
-
const focus_config = kind === "long" ? long_config : short_config;
|
|
65837
65813
|
const focus_position = kind === "long" ? long_position : short_position;
|
|
65838
|
-
|
|
65839
|
-
|
|
65840
|
-
|
|
65841
|
-
|
|
65842
|
-
return "No follow set";
|
|
65843
|
-
}
|
|
65844
|
-
let should_place_order = false;
|
|
65845
|
-
if (threshold_qty === 0) {
|
|
65846
|
-
should_place_order = true;
|
|
65847
|
-
}
|
|
65848
|
-
if (threshold_qty > 0 && track_position.quantity >= threshold_qty) {
|
|
65849
|
-
should_place_order = true;
|
|
65850
|
-
}
|
|
65851
|
-
if (focus_position.quantity === 0) {
|
|
65852
|
-
should_place_order = true;
|
|
65853
|
-
}
|
|
65854
|
-
if (track_position.quantity !== focus_position.quantity && focus_position.quantity < track_position.quantity && should_place_order) {
|
|
65855
|
-
const remaining_quantity = Math.abs(track_position.quantity - focus_position.quantity);
|
|
65856
|
-
await this.placeMarketOrder({
|
|
65857
|
-
symbol,
|
|
65858
|
-
kind,
|
|
65859
|
-
quantity: remaining_quantity
|
|
65860
|
-
});
|
|
65861
|
-
}
|
|
65814
|
+
return await focus_position.placeSingleOrder({
|
|
65815
|
+
long_position,
|
|
65816
|
+
short_position
|
|
65817
|
+
});
|
|
65862
65818
|
}
|
|
65863
65819
|
async increasePositionAtStop(payload) {
|
|
65864
|
-
const
|
|
65865
|
-
|
|
65866
|
-
symbol,
|
|
65867
|
-
kind,
|
|
65868
|
-
as_view: true
|
|
65869
|
-
});
|
|
65870
|
-
console.log(position2);
|
|
65871
|
-
let price_params = {
|
|
65872
|
-
price: payload.price,
|
|
65873
|
-
quantity: payload.quantity
|
|
65874
|
-
};
|
|
65875
|
-
if (!payload.price && position2 && position2.stop_loss) {
|
|
65876
|
-
price_params.price = position2.stop_loss.price;
|
|
65877
|
-
}
|
|
65878
|
-
if (!payload.quantity && position2 && position2.stop_loss) {
|
|
65879
|
-
price_params.quantity = position2.stop_loss.quantity;
|
|
65880
|
-
}
|
|
65881
|
-
if (price_params.price && price_params.quantity) {
|
|
65882
|
-
const { price, quantity } = price_params;
|
|
65883
|
-
const symbol_config = await this.recomputeSymbolConfig({
|
|
65884
|
-
symbol
|
|
65885
|
-
});
|
|
65886
|
-
const price_places = symbol_config.price_places;
|
|
65887
|
-
const decimal_places = symbol_config.decimal_places;
|
|
65888
|
-
if (place) {
|
|
65889
|
-
await this.cancelOrders({
|
|
65890
|
-
symbol,
|
|
65891
|
-
kind,
|
|
65892
|
-
limit: true
|
|
65893
|
-
});
|
|
65894
|
-
}
|
|
65895
|
-
return await this.exchange.customStopLoss({
|
|
65896
|
-
symbol,
|
|
65897
|
-
kind,
|
|
65898
|
-
stop: price,
|
|
65899
|
-
quantity,
|
|
65900
|
-
price_places,
|
|
65901
|
-
decimal_places,
|
|
65902
|
-
increase,
|
|
65903
|
-
place
|
|
65904
|
-
});
|
|
65905
|
-
}
|
|
65820
|
+
const focus_position = await this.getFocusPosition(payload);
|
|
65821
|
+
return await focus_position.increasePositionAtStop(payload);
|
|
65906
65822
|
}
|
|
65907
65823
|
async triggerTradeFromConfig(payload) {
|
|
65908
|
-
const
|
|
65909
|
-
|
|
65910
|
-
kind,
|
|
65911
|
-
place = true,
|
|
65912
|
-
stop,
|
|
65913
|
-
use_current,
|
|
65914
|
-
ignore_config,
|
|
65915
|
-
risky
|
|
65916
|
-
} = payload;
|
|
65917
|
-
const position2 = await this.syncAccount({
|
|
65918
|
-
symbol,
|
|
65919
|
-
kind,
|
|
65920
|
-
as_view: true
|
|
65921
|
-
});
|
|
65922
|
-
const config2 = await this.getPositionConfig({
|
|
65923
|
-
symbol,
|
|
65924
|
-
kind
|
|
65925
|
-
});
|
|
65926
|
-
let condition = ignore_config ? true : position2?.config;
|
|
65927
|
-
if (condition) {
|
|
65928
|
-
let entry = payload.tp ? position2.entry || config2.entry : config2.entry;
|
|
65929
|
-
const v = stop ? "place_stop_orders" : risky ? "dangerous_entry_orders" : "place_limit_orders";
|
|
65930
|
-
return await this.placeSharedOrder(v, {
|
|
65931
|
-
symbol,
|
|
65932
|
-
entry,
|
|
65933
|
-
stop: config2.stop,
|
|
65934
|
-
risk_reward: config2.risk_reward,
|
|
65935
|
-
risk: config2.risk,
|
|
65936
|
-
place,
|
|
65937
|
-
raw: payload.raw,
|
|
65938
|
-
use_current,
|
|
65939
|
-
stop_percent: config2.stop_percent || 100
|
|
65940
|
-
});
|
|
65941
|
-
}
|
|
65824
|
+
const focus_position = await this.getFocusPosition(payload);
|
|
65825
|
+
return await focus_position.triggerTradeFromConfig(payload);
|
|
65942
65826
|
}
|
|
65943
65827
|
async verifyStopLoss(payload) {
|
|
65944
65828
|
const { symbol, kind, revert } = payload;
|
|
@@ -66120,59 +66004,19 @@ class ExchangeAccount {
|
|
|
66120
66004
|
}
|
|
66121
66005
|
async updateTargetPnl(payload) {
|
|
66122
66006
|
const { symbol, kind } = payload;
|
|
66123
|
-
const
|
|
66007
|
+
const focus_position = await this.getFocusPosition({
|
|
66124
66008
|
symbol,
|
|
66125
66009
|
kind
|
|
66126
66010
|
});
|
|
66127
|
-
|
|
66128
|
-
const config2 = position2.expand.config;
|
|
66129
|
-
let _profit = config2.profit;
|
|
66130
|
-
let risk = config2.risk;
|
|
66131
|
-
let next_risk = position2.next_risk;
|
|
66132
|
-
let _profit_percent = config2?.profit_percent;
|
|
66133
|
-
if (_profit_percent && (position2?.quantity || 0) > 0) {
|
|
66134
|
-
_profit = to_f2(position2.quantity * _profit_percent * position2.entry / 100);
|
|
66135
|
-
next_risk = risk + _profit;
|
|
66136
|
-
}
|
|
66137
|
-
await this.app_db.update_db_position(position2, {
|
|
66138
|
-
target_pnl: _profit,
|
|
66139
|
-
next_risk
|
|
66140
|
-
});
|
|
66141
|
-
return _profit;
|
|
66142
|
-
}
|
|
66143
|
-
return 0;
|
|
66011
|
+
return await focus_position.updateTargetPnl();
|
|
66144
66012
|
}
|
|
66145
66013
|
async updateRiskOnEmpty(payload) {
|
|
66146
66014
|
const { symbol, kind } = payload;
|
|
66147
|
-
const
|
|
66015
|
+
const focus_position = await this.getFocusPosition({
|
|
66148
66016
|
symbol,
|
|
66149
66017
|
kind
|
|
66150
66018
|
});
|
|
66151
|
-
|
|
66152
|
-
if (position2.next_risk && position2.next_risk > 0) {
|
|
66153
|
-
await this.getPositionConfig({
|
|
66154
|
-
symbol,
|
|
66155
|
-
kind,
|
|
66156
|
-
params: {
|
|
66157
|
-
risk: position2.next_risk
|
|
66158
|
-
}
|
|
66159
|
-
});
|
|
66160
|
-
console.log(`Updated ${kind} position config for ${symbol}: risk = ${position2.next_risk}`);
|
|
66161
|
-
return {
|
|
66162
|
-
updated: true,
|
|
66163
|
-
symbol,
|
|
66164
|
-
kind,
|
|
66165
|
-
old_risk: position2.expand?.config?.risk,
|
|
66166
|
-
new_risk: position2.next_risk
|
|
66167
|
-
};
|
|
66168
|
-
}
|
|
66169
|
-
}
|
|
66170
|
-
return {
|
|
66171
|
-
updated: false,
|
|
66172
|
-
symbol,
|
|
66173
|
-
kind,
|
|
66174
|
-
reason: position2 ? position2.quantity > 0 ? "Position not empty" : "No next_risk available" : "Position not found"
|
|
66175
|
-
};
|
|
66019
|
+
return await focus_position.updateRiskOnEmpty();
|
|
66176
66020
|
}
|
|
66177
66021
|
async updateGoodHedgeConfig(payload) {
|
|
66178
66022
|
const {
|
|
@@ -66184,19 +66028,20 @@ class ExchangeAccount {
|
|
|
66184
66028
|
update = true
|
|
66185
66029
|
} = payload;
|
|
66186
66030
|
let _params = params;
|
|
66031
|
+
const long_position = await this.getFocusPosition({
|
|
66032
|
+
symbol,
|
|
66033
|
+
kind: "long"
|
|
66034
|
+
});
|
|
66035
|
+
const short_position = await this.getFocusPosition({
|
|
66036
|
+
symbol,
|
|
66037
|
+
kind: "short"
|
|
66038
|
+
});
|
|
66187
66039
|
if (!params) {
|
|
66188
66040
|
const result = await this.exchange.analyzeCandlesticks({ symbol });
|
|
66189
66041
|
const support_price = Math.min(...Object.keys(result.support).map(Number));
|
|
66190
|
-
const symbol_config =
|
|
66191
|
-
const config2 = await
|
|
66192
|
-
|
|
66193
|
-
kind: "long"
|
|
66194
|
-
});
|
|
66195
|
-
const position2 = await this.syncAccount({
|
|
66196
|
-
symbol,
|
|
66197
|
-
kind: "long",
|
|
66198
|
-
as_view: true
|
|
66199
|
-
});
|
|
66042
|
+
const symbol_config = long_position.symbol_config;
|
|
66043
|
+
const config2 = await long_position.getConfig();
|
|
66044
|
+
const position2 = long_position.getInstance();
|
|
66200
66045
|
const bot_position = {
|
|
66201
66046
|
kind: "long",
|
|
66202
66047
|
entry: position2.entry,
|
|
@@ -66213,9 +66058,7 @@ class ExchangeAccount {
|
|
|
66213
66058
|
});
|
|
66214
66059
|
}
|
|
66215
66060
|
if (update) {
|
|
66216
|
-
await
|
|
66217
|
-
symbol,
|
|
66218
|
-
kind: "short",
|
|
66061
|
+
await short_position.getConfig({
|
|
66219
66062
|
params: {
|
|
66220
66063
|
entry: _params.support,
|
|
66221
66064
|
stop: _params.resistance,
|
|
@@ -66224,22 +66067,15 @@ class ExchangeAccount {
|
|
|
66224
66067
|
});
|
|
66225
66068
|
}
|
|
66226
66069
|
if (update_tp) {
|
|
66227
|
-
await
|
|
66228
|
-
symbol,
|
|
66229
|
-
kind: "long",
|
|
66070
|
+
await long_position.getConfig({
|
|
66230
66071
|
params: {
|
|
66231
66072
|
profit_percent: _params.profit_percent
|
|
66232
66073
|
}
|
|
66233
66074
|
});
|
|
66234
|
-
await
|
|
66235
|
-
symbol,
|
|
66236
|
-
kind: "long"
|
|
66237
|
-
});
|
|
66075
|
+
await long_position.updateTargetPnl();
|
|
66238
66076
|
}
|
|
66239
66077
|
if (place) {
|
|
66240
|
-
await
|
|
66241
|
-
symbol,
|
|
66242
|
-
kind: "short",
|
|
66078
|
+
await short_position.placeTrade({
|
|
66243
66079
|
limit: true,
|
|
66244
66080
|
ignore_config: true
|
|
66245
66081
|
});
|
|
@@ -66248,37 +66084,13 @@ class ExchangeAccount {
|
|
|
66248
66084
|
}
|
|
66249
66085
|
async placeOppositeTradeAction(payload) {
|
|
66250
66086
|
const { symbol, kind, data } = payload;
|
|
66251
|
-
const
|
|
66087
|
+
const focus_position = await this.getFocusPosition({
|
|
66252
66088
|
symbol,
|
|
66253
|
-
kind
|
|
66254
|
-
|
|
66089
|
+
kind
|
|
66090
|
+
});
|
|
66091
|
+
return await focus_position.placeOppositeTradeAction({
|
|
66092
|
+
data
|
|
66255
66093
|
});
|
|
66256
|
-
if (position2.avg_qty !== data.avg.quantity) {
|
|
66257
|
-
const config2 = await this.getPositionConfig({
|
|
66258
|
-
symbol,
|
|
66259
|
-
kind
|
|
66260
|
-
});
|
|
66261
|
-
await this.app_db.updateScheduledTrade(config2.id, {
|
|
66262
|
-
entry: data.entry,
|
|
66263
|
-
stop: data.stop,
|
|
66264
|
-
risk: data.risk_per_trade,
|
|
66265
|
-
profit_percent: data.profit_percent,
|
|
66266
|
-
risk_reward: data.risk_reward
|
|
66267
|
-
});
|
|
66268
|
-
await this.placeTrade({
|
|
66269
|
-
symbol,
|
|
66270
|
-
kind,
|
|
66271
|
-
place: true,
|
|
66272
|
-
ignore_config: true
|
|
66273
|
-
});
|
|
66274
|
-
await this.placeTrade({
|
|
66275
|
-
symbol,
|
|
66276
|
-
kind,
|
|
66277
|
-
place: true,
|
|
66278
|
-
stop: true,
|
|
66279
|
-
ignore_config: true
|
|
66280
|
-
});
|
|
66281
|
-
}
|
|
66282
66094
|
}
|
|
66283
66095
|
async buildOppositeTrades(payload) {
|
|
66284
66096
|
const { symbol, kind, place, place_symbol } = payload;
|
|
@@ -66308,60 +66120,20 @@ class ExchangeAccount {
|
|
|
66308
66120
|
}
|
|
66309
66121
|
async runSimulation(payload) {
|
|
66310
66122
|
const { symbol, kind, iterations = 2, raw = false } = payload;
|
|
66311
|
-
const
|
|
66312
|
-
symbol,
|
|
66313
|
-
as_view: true
|
|
66314
|
-
});
|
|
66315
|
-
const symbol_config = await this.recomputeSymbolConfig({
|
|
66316
|
-
symbol
|
|
66317
|
-
});
|
|
66318
|
-
const long_position = positions.find((x) => x.kind === "long");
|
|
66319
|
-
const short_position = positions.find((x) => x.kind === "short");
|
|
66320
|
-
const long_config = await this.getPositionConfig({
|
|
66123
|
+
const long_position = await this.getFocusPosition({
|
|
66321
66124
|
symbol,
|
|
66322
66125
|
kind: "long"
|
|
66323
66126
|
});
|
|
66324
|
-
const
|
|
66127
|
+
const short_position = await this.getFocusPosition({
|
|
66325
66128
|
symbol,
|
|
66326
66129
|
kind: "short"
|
|
66327
66130
|
});
|
|
66328
|
-
const
|
|
66329
|
-
|
|
66330
|
-
const reduce_ratio = focus_config.reduce_ratio;
|
|
66331
|
-
const budget = focus_config.risk;
|
|
66332
|
-
const risk_reward = focus_config.risk_reward;
|
|
66333
|
-
const tp_percent = long_config.profit_percent;
|
|
66334
|
-
const fee_percent = symbol_config.fee_percent;
|
|
66335
|
-
const strategy_config = {
|
|
66336
|
-
tp_percent,
|
|
66337
|
-
short_tp_factor,
|
|
66338
|
-
fee_percent,
|
|
66339
|
-
budget,
|
|
66340
|
-
risk_reward,
|
|
66341
|
-
reduce_ratio,
|
|
66342
|
-
global_config: symbol_config
|
|
66343
|
-
};
|
|
66344
|
-
const strategy2 = new Strategy({
|
|
66345
|
-
long: {
|
|
66346
|
-
entry: long_position.entry,
|
|
66347
|
-
quantity: long_position.quantity,
|
|
66348
|
-
avg_price: long_position.avg_price,
|
|
66349
|
-
avg_qty: long_position.avg_qty
|
|
66350
|
-
},
|
|
66351
|
-
short: {
|
|
66352
|
-
entry: short_position.entry,
|
|
66353
|
-
quantity: short_position.quantity,
|
|
66354
|
-
avg_price: short_position.avg_price,
|
|
66355
|
-
avg_qty: short_position.avg_qty
|
|
66356
|
-
},
|
|
66357
|
-
config: strategy_config
|
|
66358
|
-
});
|
|
66359
|
-
if (raw) {
|
|
66360
|
-
return strategy2;
|
|
66361
|
-
}
|
|
66362
|
-
return strategy2.runIterations({
|
|
66131
|
+
const focus_position = kind === "long" ? long_position : short_position;
|
|
66132
|
+
return focus_position.runSimulation({
|
|
66363
66133
|
iterations,
|
|
66364
|
-
|
|
66134
|
+
raw,
|
|
66135
|
+
long_position,
|
|
66136
|
+
short_position
|
|
66365
66137
|
});
|
|
66366
66138
|
}
|
|
66367
66139
|
async getCurrentRun(payload) {
|
|
@@ -66423,34 +66195,12 @@ class ExchangeAccount {
|
|
|
66423
66195
|
return this.app_db.getSymbolConfigFromDB(symbol);
|
|
66424
66196
|
}
|
|
66425
66197
|
async buildConfigForSymbol(payload) {
|
|
66426
|
-
const {
|
|
66198
|
+
const { symbol, kind = "long" } = payload;
|
|
66199
|
+
const focus_position = await this.getFocusPosition({
|
|
66427
66200
|
symbol,
|
|
66428
|
-
|
|
66429
|
-
risk_reward = 199,
|
|
66430
|
-
as_config = false,
|
|
66431
|
-
kind = "long"
|
|
66432
|
-
} = payload;
|
|
66433
|
-
const symbol_config = await this.recomputeSymbolConfig({
|
|
66434
|
-
symbol
|
|
66435
|
-
});
|
|
66436
|
-
const long_config = await this.generate_config_params({
|
|
66437
|
-
entry: kind === "long" ? symbol_config.resistance : symbol_config.support,
|
|
66438
|
-
stop: kind === "long" ? symbol_config.support : symbol_config.resistance,
|
|
66439
|
-
risk_reward,
|
|
66440
|
-
risk,
|
|
66441
|
-
symbol
|
|
66201
|
+
kind
|
|
66442
66202
|
});
|
|
66443
|
-
|
|
66444
|
-
const app_config = buildAppConfig(symbol_config, {
|
|
66445
|
-
entry: long_config.entry,
|
|
66446
|
-
stop: long_config.stop,
|
|
66447
|
-
risk_reward,
|
|
66448
|
-
risk: long_config.risk,
|
|
66449
|
-
symbol
|
|
66450
|
-
});
|
|
66451
|
-
return app_config;
|
|
66452
|
-
}
|
|
66453
|
-
return long_config;
|
|
66203
|
+
return await focus_position.buildConfigForSymbol(payload);
|
|
66454
66204
|
}
|
|
66455
66205
|
async triggerBullishMarket(payload) {
|
|
66456
66206
|
let { symbol, profit_percent = 10, risk_reward = 199 } = payload;
|
|
@@ -66876,139 +66626,32 @@ class ExchangeAccount {
|
|
|
66876
66626
|
}
|
|
66877
66627
|
async computeTargetPnl(payload) {
|
|
66878
66628
|
const { symbol, kind } = payload;
|
|
66879
|
-
const
|
|
66880
|
-
const root_position = await this.syncAccount({
|
|
66629
|
+
const focus_position = await this.getFocusPosition({
|
|
66881
66630
|
symbol,
|
|
66882
66631
|
kind
|
|
66883
66632
|
});
|
|
66884
|
-
const
|
|
66633
|
+
const secondary_position = await this.getFocusPosition({
|
|
66885
66634
|
symbol,
|
|
66886
|
-
kind:
|
|
66635
|
+
kind: kind === "long" ? "short" : "long"
|
|
66636
|
+
});
|
|
66637
|
+
return await focus_position.computeTargetPnl({
|
|
66638
|
+
secondary: secondary_position
|
|
66887
66639
|
});
|
|
66888
|
-
if (reverse_position?.expand?.config && root_position.quantity > 0) {
|
|
66889
|
-
const reverse_config = reverse_position.expand.config;
|
|
66890
|
-
const diff = Math.abs(reverse_config.stop - root_position.entry);
|
|
66891
|
-
const result = to_f2(diff * root_position.quantity);
|
|
66892
|
-
if (root_position.target_pnl !== result) {
|
|
66893
|
-
await this.app_db.update_db_position(root_position, {
|
|
66894
|
-
target_pnl: result
|
|
66895
|
-
});
|
|
66896
|
-
await this.getPositionConfig({
|
|
66897
|
-
kind: reverse_kind,
|
|
66898
|
-
symbol,
|
|
66899
|
-
params: {
|
|
66900
|
-
...reverse_config,
|
|
66901
|
-
risk: result
|
|
66902
|
-
}
|
|
66903
|
-
});
|
|
66904
|
-
}
|
|
66905
|
-
return result;
|
|
66906
|
-
}
|
|
66907
|
-
return 0;
|
|
66908
66640
|
}
|
|
66909
66641
|
async placeStopLimit(payload) {
|
|
66910
|
-
const
|
|
66911
|
-
|
|
66912
|
-
symbol,
|
|
66913
|
-
kind,
|
|
66914
|
-
as_view: true
|
|
66915
|
-
});
|
|
66916
|
-
if (position2.avg_qty && position2.avg_qty > 0) {
|
|
66917
|
-
const spread = 1.00005;
|
|
66918
|
-
const qty = _quantity || position2.avg_qty - position2.quantity;
|
|
66919
|
-
const symbol_config = await this.recomputeSymbolConfig({ symbol });
|
|
66920
|
-
const orders = [
|
|
66921
|
-
{
|
|
66922
|
-
kind,
|
|
66923
|
-
stop,
|
|
66924
|
-
quantity: to_f2(qty, symbol_config.decimal_places),
|
|
66925
|
-
side: kind === "long" ? "buy" : "sell",
|
|
66926
|
-
price: to_f2(kind === "short" ? stop * spread ** -1 : stop * spread, symbol_config.price_places)
|
|
66927
|
-
}
|
|
66928
|
-
];
|
|
66929
|
-
if (place) {
|
|
66930
|
-
return this.exchange.placeBadStopEntry({
|
|
66931
|
-
symbol,
|
|
66932
|
-
orders,
|
|
66933
|
-
price_places: symbol_config.price_places,
|
|
66934
|
-
decimal_places: symbol_config.decimal_places
|
|
66935
|
-
});
|
|
66936
|
-
}
|
|
66937
|
-
return orders;
|
|
66938
|
-
}
|
|
66939
|
-
return [];
|
|
66642
|
+
const focus_position = await this.getFocusPosition(payload);
|
|
66643
|
+
return await focus_position.placeStopLimit(payload);
|
|
66940
66644
|
}
|
|
66941
66645
|
async placeTrade(payload) {
|
|
66942
|
-
const {
|
|
66943
|
-
symbol,
|
|
66944
|
-
kind
|
|
66945
|
-
place,
|
|
66946
|
-
tp,
|
|
66947
|
-
limit = true,
|
|
66948
|
-
raw: _raw,
|
|
66949
|
-
cancel,
|
|
66950
|
-
stop,
|
|
66951
|
-
ignore_config,
|
|
66952
|
-
target_pnl,
|
|
66953
|
-
risky
|
|
66954
|
-
} = payload;
|
|
66955
|
-
if (cancel) {
|
|
66956
|
-
await this.cancelOrders({
|
|
66957
|
-
symbol,
|
|
66958
|
-
kind
|
|
66959
|
-
});
|
|
66960
|
-
}
|
|
66961
|
-
if (limit) {
|
|
66962
|
-
return await this.triggerTradeFromConfig({
|
|
66963
|
-
symbol,
|
|
66964
|
-
kind,
|
|
66965
|
-
raw: payload.raw,
|
|
66966
|
-
stop,
|
|
66967
|
-
ignore_config,
|
|
66968
|
-
place,
|
|
66969
|
-
risky
|
|
66970
|
-
});
|
|
66971
|
-
}
|
|
66972
|
-
await this.syncAccount({
|
|
66973
|
-
symbol,
|
|
66974
|
-
live_refresh: true,
|
|
66975
|
-
update: true
|
|
66976
|
-
});
|
|
66977
|
-
await this.updateConfigPnl({
|
|
66978
|
-
symbol,
|
|
66979
|
-
kind
|
|
66646
|
+
const focus_position = await this.getFocusPosition({
|
|
66647
|
+
symbol: payload.symbol,
|
|
66648
|
+
kind: payload.kind
|
|
66980
66649
|
});
|
|
66981
|
-
|
|
66982
|
-
await this.placeProfitAndStop({
|
|
66983
|
-
symbol,
|
|
66984
|
-
trigger: true,
|
|
66985
|
-
target_pnl
|
|
66986
|
-
});
|
|
66987
|
-
}
|
|
66988
|
-
return [];
|
|
66650
|
+
return await focus_position.placeTrade(payload);
|
|
66989
66651
|
}
|
|
66990
66652
|
async updateConfigPnl(payload) {
|
|
66991
|
-
const
|
|
66992
|
-
|
|
66993
|
-
symbol,
|
|
66994
|
-
kind
|
|
66995
|
-
});
|
|
66996
|
-
if (!position2?.config) {
|
|
66997
|
-
const config2 = await this.getPositionConfig({ symbol, kind });
|
|
66998
|
-
if (config2) {
|
|
66999
|
-
await this.app_db.update_db_position(position2, { config: config2.id });
|
|
67000
|
-
await this.updateTargetPnl({
|
|
67001
|
-
symbol,
|
|
67002
|
-
kind
|
|
67003
|
-
});
|
|
67004
|
-
await this.app_db.update_db_position(position2, { config: null });
|
|
67005
|
-
}
|
|
67006
|
-
} else {
|
|
67007
|
-
await this.updateTargetPnl({
|
|
67008
|
-
symbol,
|
|
67009
|
-
kind
|
|
67010
|
-
});
|
|
67011
|
-
}
|
|
66653
|
+
const focus_position = await this.getFocusPosition(payload);
|
|
66654
|
+
return await focus_position.updateConfigPnl();
|
|
67012
66655
|
}
|
|
67013
66656
|
async determineReduceTp(payload) {
|
|
67014
66657
|
const { symbol, factor } = payload;
|
|
@@ -67023,10 +66666,10 @@ class ExchangeAccount {
|
|
|
67023
66666
|
const gap_cost = gap * long_position.quantity * factor;
|
|
67024
66667
|
const long_diff = gap_cost / (short_position.entry * short_position.quantity);
|
|
67025
66668
|
const short_diff = gap_cost / (long_position.entry * long_position.quantity);
|
|
67026
|
-
const long_tp =
|
|
67027
|
-
const short_tp =
|
|
67028
|
-
const long_percent =
|
|
67029
|
-
const short_percent =
|
|
66669
|
+
const long_tp = to_f((long_diff + 1) * short_position.entry, symbol_config.price_places);
|
|
66670
|
+
const short_tp = to_f((short_diff + 1) ** -1 * long_position.entry, symbol_config.price_places);
|
|
66671
|
+
const long_percent = to_f(Math.abs(long_tp - long_position.entry) * 100 / long_position.entry, "%.4f");
|
|
66672
|
+
const short_percent = to_f(Math.abs(short_tp - short_position.entry) * 100 / short_position.entry, "%.4f");
|
|
67030
66673
|
return {
|
|
67031
66674
|
long_diff,
|
|
67032
66675
|
short_diff,
|
|
@@ -67040,7 +66683,6 @@ class ExchangeAccount {
|
|
|
67040
66683
|
}
|
|
67041
66684
|
async profitWithinGapStrategy(payload) {
|
|
67042
66685
|
const { symbol } = payload;
|
|
67043
|
-
let reward_factor = 1;
|
|
67044
66686
|
console.log("Fetching positions for ", symbol);
|
|
67045
66687
|
const positions = await this.syncAccount({
|
|
67046
66688
|
symbol,
|
|
@@ -67054,70 +66696,11 @@ class ExchangeAccount {
|
|
|
67054
66696
|
if (!strategy2) {
|
|
67055
66697
|
return;
|
|
67056
66698
|
}
|
|
67057
|
-
const risk = strategy2.risk;
|
|
67058
66699
|
const kind = strategy2.kind;
|
|
67059
|
-
const
|
|
67060
|
-
const resistance = strategy2.resistance;
|
|
67061
|
-
console.log("Getting long and short positions for ", symbol);
|
|
67062
|
-
const long_position = positions.find((k) => k.kind === "long");
|
|
67063
|
-
const short_position = positions.find((k) => k.kind === "short");
|
|
67064
|
-
console.log("Getting focus position for ", symbol, kind);
|
|
67065
|
-
if (strategy2.max_reward_factor === 0) {
|
|
67066
|
-
reward_factor = strategy2.reward_factor;
|
|
67067
|
-
}
|
|
67068
|
-
if (focus_position.avg_qty >= focus_position.quantity && strategy2.max_reward_factor) {
|
|
67069
|
-
if (strategy2.dynamic) {
|
|
67070
|
-
const quantity_ratio = focus_position.quantity / focus_position.avg_qty;
|
|
67071
|
-
reward_factor = to_f2(quantity_ratio ** 2 * strategy2.max_reward_factor, "%.2f");
|
|
67072
|
-
} else {
|
|
67073
|
-
reward_factor = to_f2(focus_position.quantity * strategy2.max_reward_factor / focus_position.avg_qty, "%.4f");
|
|
67074
|
-
}
|
|
67075
|
-
} else {
|
|
67076
|
-
reward_factor = strategy2.reward_factor;
|
|
67077
|
-
}
|
|
67078
|
-
console.log("Getting entry and stop for ", symbol, kind);
|
|
67079
|
-
const entry = kind === "long" ? resistance : support;
|
|
67080
|
-
const stop = kind === "long" ? support : resistance;
|
|
67081
|
-
console.log("Building app config for ", symbol, kind);
|
|
67082
|
-
const initial_app_config = await this.buildAppConfig({
|
|
67083
|
-
entry,
|
|
67084
|
-
stop,
|
|
67085
|
-
risk_reward: 199,
|
|
67086
|
-
risk,
|
|
67087
|
-
symbol
|
|
67088
|
-
});
|
|
67089
|
-
console.log("Computing risk reward for ", symbol, kind);
|
|
67090
|
-
const risk_reward = strategy2.risk_reward || computeRiskReward({
|
|
67091
|
-
app_config: initial_app_config,
|
|
67092
|
-
entry: initial_app_config.entry,
|
|
67093
|
-
stop: initial_app_config.stop,
|
|
67094
|
-
risk_per_trade: initial_app_config.risk_per_trade
|
|
67095
|
-
});
|
|
67096
|
-
console.log("Re-computing app config for ", symbol, kind);
|
|
67097
|
-
const { entries, last_value, ...app_config } = await this.buildAppConfig({
|
|
67098
|
-
entry: initial_app_config.entry,
|
|
67099
|
-
stop: initial_app_config.stop,
|
|
67100
|
-
risk_reward,
|
|
67101
|
-
risk,
|
|
67102
|
-
symbol
|
|
67103
|
-
});
|
|
67104
|
-
console.log("Computing profit percent for ", symbol, kind);
|
|
67105
|
-
const pnl = reward_factor * risk;
|
|
67106
|
-
const profit_percent = to_f2(pnl * 100 / (last_value.avg_entry * last_value.avg_size), "%.4f");
|
|
67107
|
-
let config2 = {
|
|
67108
|
-
entry,
|
|
67109
|
-
stop,
|
|
67110
|
-
risk,
|
|
67111
|
-
risk_reward,
|
|
67112
|
-
profit_percent
|
|
67113
|
-
};
|
|
67114
|
-
console.log("Saving new config for ", symbol, kind);
|
|
67115
|
-
const data = await this.getPositionConfig({
|
|
66700
|
+
const { entries, last_value, ...app_config } = await this.tradeConfig({
|
|
67116
66701
|
symbol,
|
|
67117
|
-
kind
|
|
67118
|
-
params: config2
|
|
66702
|
+
kind
|
|
67119
66703
|
});
|
|
67120
|
-
console.log("Checking orders to place for ", symbol, kind);
|
|
67121
66704
|
await this.placeTrade({
|
|
67122
66705
|
symbol,
|
|
67123
66706
|
kind,
|
|
@@ -67125,10 +66708,6 @@ class ExchangeAccount {
|
|
|
67125
66708
|
ignore_config: true,
|
|
67126
66709
|
tp: true
|
|
67127
66710
|
});
|
|
67128
|
-
config2 = {
|
|
67129
|
-
...config2,
|
|
67130
|
-
...data
|
|
67131
|
-
};
|
|
67132
66711
|
if (focus_position.avg_qty < last_value.avg_size) {
|
|
67133
66712
|
console.log("Placing trade for ", symbol, kind);
|
|
67134
66713
|
await this.placeTrade({
|
|
@@ -67140,15 +66719,9 @@ class ExchangeAccount {
|
|
|
67140
66719
|
}
|
|
67141
66720
|
console.log("Checking if focus position has quantity for ", symbol, kind);
|
|
67142
66721
|
return {
|
|
67143
|
-
positions: {
|
|
67144
|
-
long: long_position,
|
|
67145
|
-
short: short_position
|
|
67146
|
-
},
|
|
67147
66722
|
config_details: {
|
|
67148
66723
|
app_config,
|
|
67149
|
-
last_value
|
|
67150
|
-
config: config2,
|
|
67151
|
-
pnl
|
|
66724
|
+
last_value
|
|
67152
66725
|
}
|
|
67153
66726
|
};
|
|
67154
66727
|
}
|