ai-trading-sys/test.ts
2025-07-16 23:12:09 +07:00

62 lines
1.8 KiB
TypeScript

import "dotenv/config";
import { BybitService } from "./src/services/bybitService";
import * as indicatorService from "./src/services/indicatorService";
import {
analyzeCandleSequence,
isHighVolatilityCandle,
isPinBar,
} from "./src/helpers/candles";
import { analyzeCandlesJob } from "./src/schedule/candleAnalysisSchedule";
import { log } from "console";
import { eventHandlerFuture } from "./src/schedule";
const bybitService = new BybitService(
'dqGCPAJzLKoTRfgCMq',
'aDYziLWN2jvdWNuz4QhWrM1O65JZ5f1NtEUO',
false
);
function toTimestamp(strTime: string): number {
return new Date(strTime).getTime();
}
(async () => {
// await analyzeCandlesJob("ETHUSDT", "15", toTimestamp("2025-07-08 23:59:59"));
// await analyzeCandlesJob("BTCUSDT", "15", undefined, toTimestamp("2025-07-16 22:14:59"));
const positions = await bybitService.listPositions({
category: "linear",
symbol: "BTCUSDT",
});
console.log(positions);
if (positions.length > 0) {
const position = positions[0];
console.log(position);
if (position.side === "Buy") {
const halfSize = (Number(position.size) / 2).toFixed(2);
console.log(halfSize);
const res = await bybitService.submitOrder({
category: "linear",
symbol: "BTCUSDT",
side: "Sell",
orderType: "Limit",
price: "119310.2",
qty: halfSize,
});
console.log(res);
}
if (position.side === "Sell") {
const halfSize = (Number(position.size) / 2).toFixed(2);
await bybitService.submitOrder({
category: "linear",
symbol: "BTCUSDT",
side: "Buy",
orderType: "Limit",
price: "119310.2",
qty: halfSize,
});
}
}
// const balance = await bybitService.getBalance();
// console.log(balance.result.list[0].totalEquity);
})();