order status updates working
This commit is contained in:
35
order.js
35
order.js
@@ -1,23 +1,36 @@
|
||||
import {redis, vaultOpenOrders} from "./cache.js";
|
||||
import {orderFilled, orderStatuses, vaultOpenOrders} from "./cache.js"
|
||||
import {applyFills} from "../web/src/blockchain/common.js"
|
||||
|
||||
|
||||
export function subVaultOrders( socket, chainId, vault ) {
|
||||
export function sendVaultOrders( socket, chainId, vault ) {
|
||||
vaultOpenOrders.get(chainId, vault).then(async (orderIndexes)=>{
|
||||
for( const orderIndex of JSON.parse(orderIndexes) ) {
|
||||
// there is a race condition here since we need multiple queries to get the complete order status,
|
||||
// so we diligently check for nulls and exclude such an order, since it was deleted and no longer active.
|
||||
const status = orderStatus( chainId, vault, orderIndex )
|
||||
if( status != null ) {
|
||||
|
||||
const result = []
|
||||
if( orderIndexes !== null ) {
|
||||
for (const orderIndex of JSON.parse(orderIndexes)) {
|
||||
// there is a race condition here since we need multiple queries to get the complete order status,
|
||||
// so we diligently check for nulls and exclude such an order, since it was deleted and no longer active.
|
||||
const status = await orderStatus(chainId, vault, orderIndex)
|
||||
if (status !== null)
|
||||
result.push([orderIndex, status])
|
||||
}
|
||||
}
|
||||
socket.emit('os', chainId, vault, result)
|
||||
})
|
||||
}
|
||||
|
||||
export function unsubVaultOrders( socket, chainId, vault ) {
|
||||
|
||||
console.log('todo: unsubVaultOrders') // todo
|
||||
}
|
||||
|
||||
export function orderStatus( chainId, vault, orderIndex ) {
|
||||
|
||||
export async function orderStatus( chainId, vault, orderIndex ) {
|
||||
const orderKey = `${vault}|${orderIndex}`
|
||||
let status = await orderStatuses.get(chainId, orderKey)
|
||||
if( status !== null ) {
|
||||
status = JSON.parse(status)
|
||||
const fills = await orderFilled.get(chainId, orderKey)
|
||||
if (fills !== null) {
|
||||
applyFills(status, JSON.parse(fills))
|
||||
}
|
||||
}
|
||||
return status
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user