Last active
April 1, 2022 20:13
-
-
Save shortthefomo/76c47806218691f3401486aa6a6e5eb0 to your computer and use it in GitHub Desktop.
Filter expired orders XRPL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { XrplClient } from "xrpl-client" | |
const tx = { | |
"id": 4, | |
"command": "book_offers", | |
"taker": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", | |
"taker_gets": { | |
"currency": "XRP" | |
}, | |
"taker_pays": { | |
"currency": "USD", | |
"issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" | |
}, | |
"limit": 10 | |
} | |
const client = new XrplClient() | |
const response = await client.send(tx) | |
const book_offers = [] | |
for (let index = 0; index < response.offers.length; index++) { | |
const offer = response.offers[index] | |
if ('Expiration' in offer && offer.Expiration < LedgerEpoch()) { | |
// do nothing expired | |
} else { | |
book_offers.push(offer) | |
} | |
} | |
// filtered book with out expired orders | |
console.log('book_offers', book_offers) | |
const LedgerEpoch = () => { | |
const unix_time = Date.now() | |
return Math.floor((unix_time) / 1000) - 946684800 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment