Skip to content

Commit

Permalink
feat: save coin1AmountInitial on order update
Browse files Browse the repository at this point in the history
  • Loading branch information
adamant-al committed Mar 23, 2023
1 parent b5a04e6 commit 4ba1955
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions trade/orderUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ module.exports = {
if (exchangeOrders) {
for (const dbOrder of dbOrders) {

const orderInfoString = `${dbOrder.purpose}-order${onWhichAccount} with params: id=${dbOrder._id}, type=${dbOrder.type}, pair=${dbOrder.pair}, price=${dbOrder.price}, coin1Amount=${dbOrder.coin1Amount}, coin2Amount=${dbOrder.coin2Amount}`;
const orderInfoString = `${dbOrder.purpose}-order${onWhichAccount} with params: id=${dbOrder._id}, type=${dbOrder.type}, pair=${dbOrder.pair}, price=${dbOrder.price}, coin1Amount=${dbOrder.coin1AmountInitial || dbOrder.coin1Amount}, coin2Amount=${dbOrder.coin2Amount}`;

let isLifeOrder = false;
let isOrderFound = false;
Expand All @@ -275,18 +275,26 @@ module.exports = {
break;
case 'part_filled':
isLifeOrder = true;

if (dbOrder.coin1Amount > exchangeOrder.amountLeft) {
if (dbOrder.purpose === 'ld') {
dbOrder.update({
ladderState: 'Partly filled',
});
}

if (!dbOrder.coin1AmountInitial) {
dbOrder.coin1AmountInitial = dbOrder.coin1Amount;
dbOrder.amountUpdateCount = 0;
}

await dbOrder.update({
isExecuted: true,
coin1Amount: exchangeOrder.amountLeft,
amountUpdateCount: dbOrder.amountUpdateCount + 1,
}, true);
log.log(`orderUtils: Updating ${orderInfoString}: order is partly filled. Amount left: ${dbOrder.coin1Amount}.`);

log.log(`orderUtils: Updating ${orderInfoString}. It's partly filled (${utils.inclineNumber(dbOrder.amountUpdateCount)} update): ${dbOrder.coin1AmountInitial} -> ${dbOrder.coin1Amount} ${dbOrder.coin1}.`);
}
break;
default:
Expand Down

0 comments on commit 4ba1955

Please sign in to comment.