Skip to content

Commit

Permalink
updated URLS and env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
suyeshs committed Apr 18, 2024
1 parent 2e28eec commit b91ea38
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 26 deletions.
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
"@aws-sdk/credential-providers": "^3.515.0",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",


"@mui/icons-material": "^5.11.16",
"@mui/material": "^5.13.5",
"@react-oauth/google": "^0.11.0",
Expand All @@ -31,6 +29,7 @@
"aws4": "^1.12.0",
"axios": "^1.4.0",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"eslint": "8.42.0",
"eslint-config-next": "13.4.4",
"firebase": "^9.22.2",
Expand Down
8 changes: 5 additions & 3 deletions src/app/lib/mongodb.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { MongoClient } from 'mongodb';
import { aggregateDailyData, ChartData } from '../utils/dataAggregation';
import dotenv from 'dotenv';

dotenv.config(); // Load environment variables from .env file

export async function fetchHistoricalData(specificStrikePrice: number, startDate: Date, endDate: Date) {
const uri = "mongodb://127.0.0.1:27017/";
const uri = process.env.MONGODB_URI || "mongodb://127.0.0.1:27017/"; // Use MongoDB URI from environment variable or fallback to default

//const uri = "mongodb://ns3151328.ip-151-106-34.eu:27017/";
const client = new MongoClient(uri);

try {
Expand Down Expand Up @@ -38,4 +40,4 @@ export async function fetchHistoricalData(specificStrikePrice: number, startDate
} finally {
client.close();
}
}
}
38 changes: 17 additions & 21 deletions src/hooks/useSocketMobx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import { paytmSocketStore } from '../stores/PaytmSocketStore';
import { OptionData } from '../types';
import { autorun } from "mobx";


export const useWebSocketMobX = () => {
console.log("useWebSocketMobX called");

const [isInitialLoadCompleted, setInitialLoadCompleted] = useState(false);
const socket = useRef<WebSocket | null>(null);
const accumulatedData = useRef<OptionData[]>([]);
const url = 'ws://tradepodsocket-vzpocpxkaa-uc.a.run.app/tradepod';
//const url = 'ws://127.0.0.1:8888/tradepod';
const url = process.env.NEXT_PUBLIC_WEBSOCKET_PROD || "wss://tradepodsocket-vzpocpxkaa-uc.a.run.app/tradepod";

// Track whether a response has been received
const responseReceived = useRef(false);
Expand Down Expand Up @@ -52,21 +50,19 @@ export const useWebSocketMobX = () => {
} else if (lastStrike && dataObject.strikePrice !== lastStrike) {
paytmSocketStore.updateData(dataObject);
}
// Set the response received flag to true
responseReceived.current = true;

// Set the response received flag to true
responseReceived.current = true;
};


const handleError = (error: Event) => {
console.error("WebSocket Error:", error);
responseReceived.current = true;

};

const handleClose = (event: CloseEvent) => {
console.log("WebSocket Disconnected with code:", event.code, "reason:", event.reason);
responseReceived.current = true;

};

socket.current.onopen = handleOpen;
Expand All @@ -93,19 +89,19 @@ export const useWebSocketMobX = () => {
};
}, []);

// Retry logic after waiting for a certain duration
useEffect(() => {
const retryTimeout = setTimeout(() => {
// Retry only if no response has been received
if (!responseReceived.current) {
console.log("No response received. Retrying...");
connectWebSocket();
}
}, 3000); // Wait for 3 seconds before retrying
// Cleanup function
return () => clearTimeout(retryTimeout);
}, [responseReceived.current]);
// Retry logic after waiting for a certain duration
useEffect(() => {
const retryTimeout = setTimeout(() => {
// Retry only if no response has been received
if (!responseReceived.current) {
console.log("No response received. Retrying...");
connectWebSocket();
}
}, 3000); // Wait for 3 seconds before retrying

// Cleanup function
return () => clearTimeout(retryTimeout);
}, [responseReceived.current]);

useEffect(() => {
// Re-establish WebSocket connection when selectedSymbol changes
Expand Down

0 comments on commit b91ea38

Please sign in to comment.