hft-js
Version:
High-Frequency Trading in Node.js
125 lines • 4.09 kB
JavaScript
"use strict";
/*
* tape.ts
*
* Copyright (c) 2025 Xiongfei Shi
*
* Author: Xiongfei Shi <xiongfei.shi(a)icloud.com>
* License: Apache-2.0
*
* https://github.com/shixiongfei/hft.js
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.calcTapeData = void 0;
var calcTapeType = function (volumeDelta, interestDelta) {
if (interestDelta > 0) {
return volumeDelta === interestDelta ? "dual-open" : "open";
}
if (interestDelta < 0) {
return volumeDelta + interestDelta === 0 ? "dual-close" : "close";
}
if (volumeDelta > 0) {
return "turnover";
}
return "no-deal";
};
var calcTapeDirection = function (tick, preTick) {
var _a, _b, _c, _d, _e, _f;
var lastPrice = tick.lastPrice;
if (preTick) {
var preAskPrice1 = (_a = preTick.orderBook.asks.price[0]) !== null && _a !== void 0 ? _a : Number.MAX_VALUE;
if (lastPrice >= preAskPrice1) {
return "up";
}
var preBidPrice1 = (_b = preTick.orderBook.bids.price[0]) !== null && _b !== void 0 ? _b : Number.MIN_VALUE;
if (lastPrice <= preBidPrice1) {
return "down";
}
var askPrice1 = (_c = tick.orderBook.asks.price[0]) !== null && _c !== void 0 ? _c : Number.MAX_VALUE;
if (lastPrice >= askPrice1) {
return "up";
}
var bidPrice1 = (_d = tick.orderBook.bids.price[0]) !== null && _d !== void 0 ? _d : Number.MIN_VALUE;
if (lastPrice <= bidPrice1) {
return "down";
}
var prePrice = preTick.lastPrice;
if (lastPrice > prePrice) {
return "up";
}
if (lastPrice < prePrice) {
return "down";
}
if (bidPrice1 >= preAskPrice1) {
return "up";
}
if (askPrice1 <= preBidPrice1) {
return "down";
}
return "none";
}
else {
var askPrice1 = (_e = tick.orderBook.asks.price[0]) !== null && _e !== void 0 ? _e : Number.MAX_VALUE;
if (lastPrice >= askPrice1) {
return "up";
}
var bidPrice1 = (_f = tick.orderBook.bids.price[0]) !== null && _f !== void 0 ? _f : Number.MIN_VALUE;
if (lastPrice <= bidPrice1) {
return "down";
}
if (lastPrice > tick.preClose) {
return "up";
}
if (lastPrice < tick.preClose) {
return "down";
}
return "none";
}
};
var calcTapeStatus = function (tapeType, tapeDirection) {
if (tapeType === "open" && tapeDirection === "up") {
return "open-long";
}
if (tapeType === "open" && tapeDirection === "down") {
return "open-short";
}
if (tapeType === "close" && tapeDirection === "up") {
return "close-short";
}
if (tapeType === "close" && tapeDirection === "down") {
return "close-long";
}
if (tapeType === "turnover" && tapeDirection === "up") {
return "turnover-long";
}
if (tapeType === "turnover" && tapeDirection === "down") {
return "turnover-short";
}
if (tapeType === "dual-open") {
return "dual-open";
}
if (tapeType === "dual-close") {
return "dual-close";
}
return "invalid";
};
var calcTapeData = function (tick, preTick) {
var volumeDelta = preTick ? tick.volume - preTick.volume : tick.volume;
var amountDelta = preTick ? tick.amount - preTick.amount : tick.amount;
var interestDelta = preTick
? tick.openInterest - preTick.openInterest
: tick.openInterest - tick.preOpenInterest;
var tapeType = calcTapeType(volumeDelta, interestDelta);
var tapeDirection = calcTapeDirection(tick, preTick);
var tapeStatus = calcTapeStatus(tapeType, tapeDirection);
return Object.freeze({
type: tapeType,
direction: tapeDirection,
status: tapeStatus,
interestDelta: interestDelta,
volumeDelta: volumeDelta,
amountDelta: amountDelta,
});
};
exports.calcTapeData = calcTapeData;
//# sourceMappingURL=tape.js.map