Skip to content

Commit

Permalink
Add verbose logging
Browse files Browse the repository at this point in the history
  • Loading branch information
djkazic committed Nov 10, 2023
1 parent 34e1ecf commit 34a3390
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ async function loadModules() {
let lastCalledTime = Date.now() - fetchInterval;
let lastTradeLogicCall = 0;
let rsiData = [];
let lastTickDirection = '';
const period = 14;
const tradeLogicCooldown = 60 * 1000;

Expand Down Expand Up @@ -326,6 +327,7 @@ async function loadModules() {
logger("error", `Fetching positions failed: ${JSON.stringify(error)}`);
logger(error.stack);
}
logger("info", `Last tick direction: ${lastTickDirection}`);
try {
let action = "none";
let rsi = await fetchRSI("15m");
Expand Down Expand Up @@ -429,16 +431,19 @@ async function loadModules() {

// WebSocket client for live data
async function setupWebSocket() {
logger("info", "Setting up websocket");
try {
const wsClient = await createWebsocketClient(apiConfig);
await wsClient.publicSubscribe([
"futures:btc_usd:last-price",
"futures:btc_usd:index",
]);
logger("info", "Subscribed to websocket topics");
wsClient.ws.on("futures:btc_usd:last-price", (data) => {
// console.log(`Received data: ${JSON.stringify(data, null, 2)}`); // Log the entire data object
// logger("info", `Received price data: ${JSON.stringify(data, null, 2)}`);
if (data?.lastPrice !== undefined) {
lastPrice = data.lastPrice;
lastTickDirection = data.lastTickDirection;
// console.log(`Updated last price: ${lastPrice}`);
if (shouldCallTradeLogic()) {
tradeLogic();
Expand All @@ -449,7 +454,7 @@ async function loadModules() {
}
});
wsClient.ws.on("futures:btc_usd:index", (data) => {
// console.log(`Received index data: ${JSON.stringify(data, null, 2)}`); // Log the entire data object
// logger("info", `Received index data: ${JSON.stringify(data, null, 2)}`);
if (data?.index !== undefined) {
indexPrice = data.index;
if (shouldCallTradeLogic()) {
Expand Down

0 comments on commit 34a3390

Please sign in to comment.