@@ -145,18 +145,20 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
const mms = await this.indicativeQuotesRedisClient.smembers(
|
const mms = await this.indicativeQuotesRedisClient.smembers(
|
||||||
`market_mms_${marketType}_${marketArgs.marketIndex}`
|
`market_mms_${marketType}_${marketArgs.marketIndex}`
|
||||||
);
|
);
|
||||||
const mmQuotes = await Promise.all(
|
let mmQuotes: any = await Promise.all(
|
||||||
mms.map((mm) => {
|
mms.map((mm) => {
|
||||||
return this.indicativeQuotesRedisClient.get(
|
return this.indicativeQuotesRedisClient.get(
|
||||||
`mm_quotes_${marketType}_${marketArgs.marketIndex}_${mm}`
|
`mm_quotes_v2_${marketType}_${marketArgs.marketIndex}_${mm}`
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
mmQuotes = mmQuotes.filter((x) => !!x);
|
||||||
|
|
||||||
const nowMinus1000Ms = Date.now() - 1000;
|
const nowMinus1000Ms = Date.now() - 1000;
|
||||||
for (const quote of mmQuotes) {
|
for (const quotes of mmQuotes) {
|
||||||
try {
|
try {
|
||||||
if (Number(quote['ts']) > nowMinus1000Ms) {
|
if (Number(quotes['ts']) > nowMinus1000Ms) {
|
||||||
|
for (const quote of quotes['quotes']) {
|
||||||
const indicativeBaseOrder: Order = {
|
const indicativeBaseOrder: Order = {
|
||||||
status: OrderStatus.OPEN,
|
status: OrderStatus.OPEN,
|
||||||
orderType: OrderType.LIMIT,
|
orderType: OrderType.LIMIT,
|
||||||
@@ -239,6 +241,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
indicativeOrderId += 1;
|
indicativeOrderId += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('skipping mmQuote: ', error);
|
console.log('skipping mmQuote: ', error);
|
||||||
}
|
}
|
||||||
|
|||||||
43
src/index.ts
43
src/index.ts
@@ -786,14 +786,20 @@ const main = async (): Promise<void> => {
|
|||||||
try {
|
try {
|
||||||
// Check origin validation
|
// Check origin validation
|
||||||
const origin = req.get('Origin') || req.get('Referer');
|
const origin = req.get('Origin') || req.get('Referer');
|
||||||
const allowedOrigins = ['https://app.drift.trade', 'https://beta.drift.trade'];
|
const allowedOrigins = [
|
||||||
|
'https://app.drift.trade',
|
||||||
|
'https://beta.drift.trade',
|
||||||
|
];
|
||||||
|
|
||||||
const hasAuth = (
|
const hasAuth =
|
||||||
(req.headers.Authorization || req.headers.authorization) ===
|
(req.headers.Authorization || req.headers.authorization) ===
|
||||||
process.env.INTERNAL_SECRET
|
process.env.INTERNAL_SECRET;
|
||||||
)
|
|
||||||
|
|
||||||
if (!hasAuth && (!origin || !allowedOrigins.some(allowed => origin.startsWith(allowed)))) {
|
if (
|
||||||
|
!hasAuth &&
|
||||||
|
(!origin ||
|
||||||
|
!allowedOrigins.some((allowed) => origin.startsWith(allowed)))
|
||||||
|
) {
|
||||||
res.status(403).json({ error: 'Forbidden: Invalid origin' });
|
res.status(403).json({ error: 'Forbidden: Invalid origin' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -816,22 +822,19 @@ const main = async (): Promise<void> => {
|
|||||||
jsonBinaryEncoding: 'hex',
|
jsonBinaryEncoding: 'hex',
|
||||||
};
|
};
|
||||||
|
|
||||||
const latestPriceRes = await fetch(
|
const latestPriceRes = await fetch(pythLazerEndpoint, {
|
||||||
pythLazerEndpoint,
|
|
||||||
{
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${pythLazerDriftToken}`,
|
Authorization: `Bearer ${pythLazerDriftToken}`,
|
||||||
},
|
},
|
||||||
body: JSON.stringify(latestLazerPricePayload),
|
body: JSON.stringify(latestLazerPricePayload),
|
||||||
}
|
}).then((res) => res.json());
|
||||||
).then((res) => res.json());
|
|
||||||
|
|
||||||
const data = latestPriceRes.solana.data;
|
const data = latestPriceRes.solana.data;
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
data
|
data,
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -848,14 +851,20 @@ const main = async (): Promise<void> => {
|
|||||||
try {
|
try {
|
||||||
// Check origin validation
|
// Check origin validation
|
||||||
const origin = req.get('Origin') || req.get('Referer');
|
const origin = req.get('Origin') || req.get('Referer');
|
||||||
const allowedOrigins = ['https://app.drift.trade', 'https://beta.drift.trade'];
|
const allowedOrigins = [
|
||||||
|
'https://app.drift.trade',
|
||||||
|
'https://beta.drift.trade',
|
||||||
|
];
|
||||||
|
|
||||||
const hasAuth = (
|
const hasAuth =
|
||||||
(req.headers.Authorization || req.headers.authorization) ===
|
(req.headers.Authorization || req.headers.authorization) ===
|
||||||
process.env.INTERNAL_SECRET
|
process.env.INTERNAL_SECRET;
|
||||||
)
|
|
||||||
|
|
||||||
if (!hasAuth && (!origin || !allowedOrigins.some(allowed => origin.startsWith(allowed)))) {
|
if (
|
||||||
|
!hasAuth &&
|
||||||
|
(!origin ||
|
||||||
|
!allowedOrigins.some((allowed) => origin.startsWith(allowed)))
|
||||||
|
) {
|
||||||
res.status(403).json({ error: 'Forbidden: Invalid origin' });
|
res.status(403).json({ error: 'Forbidden: Invalid origin' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -881,7 +890,7 @@ const main = async (): Promise<void> => {
|
|||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
data
|
data,
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user