applyFills fix
This commit is contained in:
45
order.js
45
order.js
@@ -10,6 +10,7 @@ export function sendVaultOrders( socket, chainId, vault ) {
|
|||||||
]).then(async (got)=>{
|
]).then(async (got)=>{
|
||||||
const [openIndexes, closedIndexes, recents] = got
|
const [openIndexes, closedIndexes, recents] = got
|
||||||
const statuses = {}
|
const statuses = {}
|
||||||
|
// noinspection JSCheckFunctionSignatures
|
||||||
const indexes = [...JSON.parse(openIndexes), ...JSON.parse(closedIndexes)]
|
const indexes = [...JSON.parse(openIndexes), ...JSON.parse(closedIndexes)]
|
||||||
const proms = []
|
const proms = []
|
||||||
if( openIndexes !== null ) {
|
if( openIndexes !== null ) {
|
||||||
@@ -58,7 +59,7 @@ export async function orderStatus( chainId, vault, orderIndex ) {
|
|||||||
async function fillOrderStatus(chainId, orderKey, status ) {
|
async function fillOrderStatus(chainId, orderKey, status ) {
|
||||||
const fills = await orderFilled.get(chainId, orderKey)
|
const fills = await orderFilled.get(chainId, orderKey)
|
||||||
if (fills !== null)
|
if (fills !== null)
|
||||||
applyFills(status, JSON.parse(fills))
|
applyFillsServer(status, JSON.parse(fills))
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function archivedOrders(chainId, vault, limit=100 ) {
|
export async function archivedOrders(chainId, vault, limit=100 ) {
|
||||||
@@ -79,23 +80,43 @@ export async function archivedOrders(chainId, vault, limit=100 ) {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyFills( orderStatus, filled ) {
|
export function applyFillsServer(orderStatus, orderFills) {
|
||||||
// console.log('apply fills OrderStatus', orderStatus)
|
|
||||||
// console.log('apply fills filled', filled)
|
|
||||||
const [[orderFilledIn, orderFilledOut], trancheFills] = filled
|
|
||||||
orderStatus[7] = orderFilledIn
|
|
||||||
orderStatus[8] = orderFilledOut
|
|
||||||
for( const i in trancheFills ) {
|
|
||||||
const [filledIn, filledOut] = trancheFills[i]
|
|
||||||
// class ElaboratedTrancheStatus:
|
// class ElaboratedTrancheStatus:
|
||||||
// filledIn: int
|
// filledIn: int
|
||||||
// filledOut: int
|
// filledOut: int
|
||||||
// activationTime: int
|
// activationTime: int
|
||||||
// startTime: int
|
// startTime: int
|
||||||
// endTime: int
|
// endTime: int
|
||||||
|
// fills: list[Fill]
|
||||||
|
//
|
||||||
|
// class Fill:
|
||||||
|
// tx: str
|
||||||
|
// time: int
|
||||||
|
// filledIn: int
|
||||||
|
// filledOut: int
|
||||||
|
// fee: int
|
||||||
|
|
||||||
orderStatus[9][i][0] = filledIn
|
// console.log('apply fills OrderStatus', orderStatus)
|
||||||
orderStatus[9][i][1] = filledOut
|
// console.log('apply fills orderFills', orderFills)
|
||||||
|
const trancheStatus = orderStatus[9]
|
||||||
|
let orderIn = 0n
|
||||||
|
let orderOut = 0n
|
||||||
|
for (const i in orderFills) {
|
||||||
|
let filledIn = 0n
|
||||||
|
let filledOut = 0n
|
||||||
|
const [activationTime, fills] = orderFills[i];
|
||||||
|
for (const fill of fills) {
|
||||||
|
filledIn += BigInt(fill[2])
|
||||||
|
filledOut += BigInt(fill[3])
|
||||||
}
|
}
|
||||||
// console.log('applied fills', orderStatus)
|
const old = trancheStatus[i]
|
||||||
|
const startTime = old[3]
|
||||||
|
const endTime = old[4]
|
||||||
|
trancheStatus[i] = [filledIn.toString(), filledOut.toString(), activationTime, startTime, endTime, fills]
|
||||||
|
orderIn += filledIn
|
||||||
|
orderOut += filledOut
|
||||||
|
}
|
||||||
|
orderStatus[7] = orderIn.toString()
|
||||||
|
orderStatus[8] = orderOut.toString()
|
||||||
|
// console.log('apply fills final', orderStatus, orderStatus[1][8])
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user