some progress on independent price

This commit is contained in:
vixidev99
2022-02-06 10:22:19 +05:30
parent 0d44518cbe
commit 6ae1ea7c0a

View File

@@ -14,6 +14,7 @@ const NONCES = {};
let ACCOUNT_STATE = null; let ACCOUNT_STATE = null;
let ORDER_BROADCASTING = false; let ORDER_BROADCASTING = false;
const FILL_QUEUE = []; const FILL_QUEUE = [];
const FILLS = [];
// Load MM config // Load MM config
let MM_CONFIG; let MM_CONFIG;
@@ -34,7 +35,7 @@ for (let marketId in MM_CONFIG.pairs) {
console.log("ACTIVE PAIRS", activePairs); console.log("ACTIVE PAIRS", activePairs);
// Start price feeds // Start price feeds
cryptowatchWsSetup(); priceFeedSetup();
// Initiate fill loop // Initiate fill loop
setTimeout(processFillQueue, 1000); setTimeout(processFillQueue, 1000);
@@ -109,7 +110,7 @@ function onWsClose () {
zigzagws = new WebSocket(MM_CONFIG.zigzagWsUrl); zigzagws = new WebSocket(MM_CONFIG.zigzagWsUrl);
zigzagws.on('open', onWsOpen); zigzagws.on('open', onWsOpen);
zigzagws.on('error', onWsClose); zigzagws.on('error', onWsClose);
}, 5000); }, 10000);
} }
async function handleMessage(json) { async function handleMessage(json) {
@@ -133,11 +134,21 @@ async function handleMessage(json) {
} }
}); });
break break
case "fills":
const fills = msg.args[0];
fills.forEach(fill => {
if (ACCOUNT_STATE.id.toString() === fill[
});
break
case "orderstatus":
break
case "userordermatch": case "userordermatch":
const chainid = msg.args[0]; const chainid = msg.args[0];
const orderid = msg.args[1]; const orderid = msg.args[1];
const zkTaker = msg.args[2];
const zkMaker = msg.args[3];
try { try {
await broadcastfill(chainid, orderid, msg.args[2], msg.args[3]); await broadcastfill(chainid, orderid, zkTaker, zkMaker);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
@@ -391,13 +402,16 @@ async function processFillQueue() {
setTimeout(processFillQueue, 50); setTimeout(processFillQueue, 50);
} }
async function cryptowatchWsSetup() { async function priceFeedSetup() {
const cryptowatch_market_ids = []; const cryptowatch_market_ids = [];
for (let market in MM_CONFIG.pairs) { for (let market in MM_CONFIG.pairs) {
const primaryPriceFeed = MM_CONFIG.pairs[market].priceFeedPrimary; const mmConfig = MM_CONFIG.pairs[market];
const secondaryPriceFeed = MM_CONFIG.pairs[market].priceFeedSecondary; if (mmConfig.priceFeedPrimary) cryptowatch_market_ids.push(mmConfig.priceFeedPrimary);
if (primaryPriceFeed) cryptowatch_market_ids.push(primaryPriceFeed); if (mmConfig.priceFeedSecondary) cryptowatch_market_ids.push(mmConfig.priceFeedSecondary);
if (secondaryPriceFeed) cryptowatch_market_ids.push(secondaryPriceFeed); if ((["independent", "constant"]).includes(mmConfig.mode)) {
if (!mmConfig.initPrice) throw new Error("Constant and independent mode must have an initPrice");
PRICE_FEEDS[market] = mmConfig.initPrice;
}
} }
// Set initial prices // Set initial prices
@@ -490,8 +504,8 @@ function getMidPrice (market_id) {
const mmConfig = MM_CONFIG.pairs[market_id]; const mmConfig = MM_CONFIG.pairs[market_id];
const mode = mmConfig.mode || "pricefeed"; const mode = mmConfig.mode || "pricefeed";
let midPrice; let midPrice;
if (mode == "constant") { if (mode == "constant" || mode == "independent") {
midPrice = mmConfig.initPrice; midPrice = PRICE_FEEDS[market_id];
} }
else if (mode == "pricefeed") { else if (mode == "pricefeed") {
midPrice = PRICE_FEEDS[mmConfig.priceFeedPrimary]; midPrice = PRICE_FEEDS[mmConfig.priceFeedPrimary];