Skip to content

Commit

Permalink
improve updateStuckOrders
Browse files Browse the repository at this point in the history
  • Loading branch information
peterszombati committed Nov 6, 2023
1 parent 3fe981d commit 5099cd5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/v2/core/Trading/Trading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {getPositionType} from "../../utils/getPositionType"
import {sleep} from "../../utils/sleep"
import {Transaction} from "../Transaction"
import {tradeTransactionResponse, tradeTransactionStatusResponse} from "../../interface/Response"
import {isEmpty} from "../../utils/Object";

export interface Orders {
[order: number]: {
Expand Down Expand Up @@ -171,6 +172,9 @@ export class Trading {
})

const updateStuckOrders = async () => {
if (isEmpty(this.pendingOrders)) {
return
}
const start = new Time()
if (Object.values(this.XAPI.Socket.connections).some((c) => c.lastReceivedMessage !== null && c.status === 'CONNECTED')) {
for (const order of Object.values(this.pendingOrders)) {
Expand Down
7 changes: 7 additions & 0 deletions src/v2/utils/Object.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function isEmpty(obj: Record<string, any>) {
for (const prop in obj) {
if (obj.hasOwnProperty(prop))
return false
}
return true
}

0 comments on commit 5099cd5

Please sign in to comment.