vault recent orders (status bugfix)

This commit is contained in:
Tim
2024-04-11 16:27:03 -04:00
parent 39de96bca5
commit 59740cf6e9
3 changed files with 31 additions and 27 deletions

View File

@@ -29,9 +29,9 @@ export class CacheDict {
this.series = series
}
async get(chain, key) {
async get(chain, key, default_=null) {
const result = await redis.hGet(`${chain}|${this.series}`, key)
return result === null ? null : '' + result
return result === null ? default_ : '' + result
}
async contains(chain, key) {
@@ -80,5 +80,6 @@ export const vaultBalances = new CacheDict('vb')
export const prices = new CacheDict('p')
export const orderStatuses = new CacheDict('o')
export const vaultOpenOrders = new CacheDict('voo')
export const vaultRecentlyClosedOrders = new CacheDict('vrco')
export const orderFilled = new CacheDict('of')
export const ohlcs = new CacheDict('ohlc')

View File

@@ -1,12 +1,20 @@
import {orderFilled, orderStatuses, vaultOpenOrders} from "./cache.js"
import {orderFilled, orderStatuses, vaultOpenOrders, vaultRecentlyClosedOrders} from "./cache.js"
import {sql} from "./db.js";
export function sendVaultOrders( socket, chainId, vault ) {
vaultOpenOrders.get(chainId, vault).then(async (orderIndexes)=>{
Promise.all([
vaultOpenOrders.get(chainId, vault, '[]'),
vaultRecentlyClosedOrders.get(chainId, vault, '[]'),
archivedOrders(chainId, vault),
]).then(async (got)=>{
const [openIndexes, closedIndexes, recents] = got
console.log('vault open orders', openIndexes)
console.log('vault closed orders', closedIndexes)
const statuses = {}
if( orderIndexes !== null ) {
for (const orderIndex of JSON.parse(orderIndexes)) {
const indexes = [...JSON.parse(openIndexes), ...JSON.parse(closedIndexes)]
if( openIndexes !== null ) {
for (const orderIndex of indexes) {
// there is a race condition here since we need multiple queries to get the complete order status,
// so we check for nulls and exclude such an order, since it was deleted and no longer active.
const status = await orderStatus(chainId, vault, orderIndex)
@@ -14,7 +22,7 @@ export function sendVaultOrders( socket, chainId, vault ) {
statuses[orderIndex] = status
}
}
recentOrders(socket, chainId, vault).then(async (recents)=>{
console.log('vault archived orders', recents)
const proms = []
for( let [orderIndex, status] of recents ) {
if( !(orderIndex in statuses) ) {
@@ -30,7 +38,6 @@ export function sendVaultOrders( socket, chainId, vault ) {
result.push([parseInt(index), statuses[index]])
socket.emit('os', chainId, vault, result)
})
}).catch((reason)=>console.error('Could not send orders', reason))
}
export function unsubVaultOrders( socket, chainId, vault ) {
@@ -53,7 +60,7 @@ async function fillOrderStatus( chainId, orderKey, status ) {
applyFills(status, JSON.parse(fills))
}
export async function recentOrders( socket, chainId, vault, limit=25 ) {
export async function archivedOrders(chainId, vault, limit=25 ) {
const query = await sql(
`select oi.order_index, sd.value
from seriesdict sd,

View File

@@ -5,10 +5,6 @@ import {vaultBalances, vaults} from './cache.js';
import {chainInfo, VAULT_INIT_CODE_HASH} from "./chain.js";
import {sendVaultOrders} from "./order.js";
// Vault
// address owner
// balances { tokenAddress: amount }
// recentOrders []
const vaultAbi = await getAbi('Vault')
const factoryAbi = await getAbi('Factory')