nodejs-order-book
Version:
Node.js Lmit Order Book for high-frequency trading (HFT).
78 lines (77 loc) • 3.82 kB
JavaScript
var _a, _b;
export var ERROR;
(function (ERROR) {
ERROR["DEFAULT"] = "DEFAULT";
ERROR["INSUFFICIENT_QUANTITY"] = "INSUFFICIENT_QUANTITY";
ERROR["INVALID_CONDITIONAL_ORDER"] = "INVALID_CONDITIONAL_ORDER";
ERROR["INVALID_JOURNAL_LOG"] = "INVALID_JOURNAL_LOG";
ERROR["INVALID_ORDER_TYPE"] = "INVALID_ORDER_TYPE";
ERROR["INVALID_PRICE"] = "INVALID_PRICE";
ERROR["INVALID_PRICE_LEVEL"] = "INVALID_PRICE_LEVEL";
ERROR["INVALID_PRICE_OR_QUANTITY"] = "INVALID_PRICE_OR_QUANTITY";
ERROR["INVALID_QUANTITY"] = "INVALID_QUANTITY";
ERROR["INVALID_SIDE"] = "INVALID_SIDE";
ERROR["INVALID_TIF"] = "INVALID_TIF";
ERROR["LIMIT_ORDER_FOK_NOT_FILLABLE"] = "LIMIT_ORDER_FOK_NOT_FILLABLE";
ERROR["LIMIT_ORDER_POST_ONLY"] = "LIMIT_ORDER_POST_ONLY";
ERROR["ORDER_ALREDY_EXISTS"] = "ORDER_ALREDY_EXISTS";
ERROR["ORDER_NOT_FOUND"] = "ORDER_NOT_FOUND";
})(ERROR || (ERROR = {}));
export var ErrorCodes = (_a = {},
// 10xx General issues
_a[ERROR.DEFAULT] = 1000,
// 11xx Request issues
_a[ERROR.INVALID_ORDER_TYPE] = 1100,
_a[ERROR.INVALID_SIDE] = 1101,
_a[ERROR.INVALID_QUANTITY] = 1102,
_a[ERROR.INVALID_PRICE] = 1103,
_a[ERROR.INVALID_PRICE_OR_QUANTITY] = 1104,
_a[ERROR.INVALID_TIF] = 1105,
_a[ERROR.LIMIT_ORDER_FOK_NOT_FILLABLE] = 1106,
_a[ERROR.LIMIT_ORDER_POST_ONLY] = 1107,
_a[ERROR.INVALID_CONDITIONAL_ORDER] = 1108,
_a[ERROR.ORDER_ALREDY_EXISTS] = 1109,
_a[ERROR.ORDER_NOT_FOUND] = 1110,
// 12xx Internal error
_a[ERROR.INSUFFICIENT_QUANTITY] = 1200,
_a[ERROR.INVALID_PRICE_LEVEL] = 1201,
_a[ERROR.INVALID_JOURNAL_LOG] = 1201,
_a);
export var ErrorMessages = (_b = {},
_b[ERROR.DEFAULT] = "Something wrong",
_b[ERROR.INSUFFICIENT_QUANTITY] = "Insufficient quantity to calculate price",
_b[ERROR.INVALID_CONDITIONAL_ORDER] = "Stop-Limit Order (BUY: marketPrice < stopPrice <= price, SELL: marketPrice > stopPrice >= price). Stop-Market Order (BUY: marketPrice < stopPrice, SELL: marketPrice > stopPrice). OCO order (BUY: price < marketPrice < stopPrice, SELL: price > marketPrice > stopPrice)",
_b[ERROR.INVALID_ORDER_TYPE] = "Supported order type are 'limit' and 'market'",
_b[ERROR.INVALID_PRICE] = "Invalid order price",
_b[ERROR.INVALID_PRICE_LEVEL] = "Invalid order price level",
_b[ERROR.INVALID_PRICE_OR_QUANTITY] = "Invalid order price or quantity",
_b[ERROR.INVALID_QUANTITY] = "Invalid order quantity",
_b[ERROR.INVALID_SIDE] = "Invalid side: must be either 'sell' or 'buy'",
_b[ERROR.INVALID_TIF] = "Invalid TimeInForce: must be one of 'GTC', 'IOC' or 'FOK'",
_b[ERROR.LIMIT_ORDER_FOK_NOT_FILLABLE] = "Limit FOK order not fillable",
_b[ERROR.LIMIT_ORDER_POST_ONLY] = "Post-only limit order rejected because would execute immediately",
_b[ERROR.ORDER_ALREDY_EXISTS] = "Order already exists",
_b[ERROR.ORDER_NOT_FOUND] = "Order not found",
_b[ERROR.INVALID_JOURNAL_LOG] = "Invalid journal log format",
_b);
var OrderBookError = /** @class */ (function () {
function OrderBookError(error) {
var _a;
var errorMessage;
if (error != null && ErrorMessages[error] != null) {
errorMessage = ErrorMessages[error];
}
else {
var customMessage = error === undefined || error === "" ? "" : ": ".concat(error);
errorMessage = "".concat(ErrorMessages.DEFAULT).concat(customMessage);
}
this.message = errorMessage;
this.code = (_a = ErrorCodes[error]) !== null && _a !== void 0 ? _a : ErrorCodes[ERROR.DEFAULT];
}
return OrderBookError;
}());
export { OrderBookError };
/* node:coverage ignore next - Don't know why this line is uncoverd */
export var CustomError = function (error) {
return new OrderBookError(error);
};