Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ DB_USERNAME=""
DB_PASSWORD=""
DB_HOST=""
REDIS_HOST=""
REDIS_PORT=""
REDIS_PASSWORD=""
DB_PORT=""
DB_NAME=""
PUBLIC_VAPID_KEY=""
Expand Down
4 changes: 2 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ app.use("/web-subscription", webSubscriptionRoutes);
app.use("/line-notify-callback", lineNotifyRoutes);
app.use("/telegram-updates", telegramBotRoutes);

// 更新redis資料庫
updateSymbolData.initialUpdate();
// // 更新redis資料庫
// updateSymbolData.initialUpdate();

// 建立webSocket連線
trackPrices();
Expand Down
26 changes: 18 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
version: '3'
services:
app:
build: .
ports:
- "8000:8000"
depends_on:
- mongodb
- redis
# - redis
env_file:
- ./.env
restart: unless-stopped
networks:
- cryptosniper-network


mongodb:
image: mongo
Expand All @@ -21,12 +23,20 @@ services:
volumes:
- mongodb_data:/data/db
restart: unless-stopped
networks:
- cryptosniper-network

# redis:
# image: redis
# ports:
# - "6379:6379"
# restart: unless-stopped

redis:
image: redis
ports:
- "6379:6379"
restart: unless-stopped

volumes:
mongodb_data:
mongodb_data:

networks:
cryptosniper-network:
external:
name: binance-sync-service_cryptosniper-network
18 changes: 16 additions & 2 deletions models/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,22 @@
require("dotenv").config();
const Redis = require("ioredis");
const REDIS_HOST = process.env.REDIS_HOST;
const REDIS_PORT = 6379;
const redis = new Redis(REDIS_PORT, REDIS_HOST);
const REDIS_PORT = process.env.REDIS_PORT;
const REDIS_PASSWORD = process.env.REDIS_PASSWORD;

const redis = new Redis({
port: REDIS_PORT,
host: REDIS_HOST,
password: REDIS_PASSWORD,
});

redis.set("key", "value", function (err, result) {
if (err) {
console.log("Redis connection error:", err);
} else {
console.log("Redis set result:", result);
}
});

const time_intervals = {
"5m": 5,
Expand Down
38 changes: 19 additions & 19 deletions services/updateSymbolData.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ const timeIntervals = {
"1M": 24 * 60 * 60 * 1000,
};

async function initialUpdate() {
try {
setInterval(async () => {
await updateSymbolQuoteVolumeData();
}, 5 * 60 * 1000);
// 24hr Data
await updateSymbolQuoteVolumeData();
// async function initialUpdate() {
// try {
// setInterval(async () => {
// await updateSymbolQuoteVolumeData();
// }, 5 * 60 * 1000);
// // 24hr Data
// await updateSymbolQuoteVolumeData();

// Klines Data
for (const [timeInterval, intervalMs] of Object.entries(timeIntervals)) {
setInterval(async () => {
await updateSymbolKlinesData(timeInterval);
}, intervalMs);
updateSymbolKlinesData(timeInterval);
}
} catch (error) {
console.error(`Initial update failed: ${error}`);
}
}
// // Klines Data
// for (const [timeInterval, intervalMs] of Object.entries(timeIntervals)) {
// setInterval(async () => {
// await updateSymbolKlinesData(timeInterval);
// }, intervalMs);
// updateSymbolKlinesData(timeInterval);
// }
// } catch (error) {
// console.error(`Initial update failed: ${error}`);
// }
// }

module.exports = { initialUpdate };
// module.exports = { initialUpdate };