-
Notifications
You must be signed in to change notification settings - Fork 5
/
cancel-all-orders.js
37 lines (32 loc) · 1.13 KB
/
cancel-all-orders.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict'
const isLive = true
const RippleAPI = require('ripple-lib').RippleAPI
const credentials = './credentials.txt'
const env = require('./env-utils.js').makeEnv(isLive, credentials)
const api = new RippleAPI({server: 'wss://s1.ripple.com'})
function fail(message) {
console.error(message);
process.exit(1);
}
function cancelOrder(orderSequence) {
console.log('Cancelling order: ' + orderSequence.toString());
return api.prepareOrderCancellation(env.address, {orderSequence})
.then(prepared => {
const signing = api.sign(prepared.txJSON, env.secret);
return api.submit(signing.signedTransaction);
});
}
function cancelAllOrders(orderSequences) {
if (orderSequences.length === 0) {
return Promise.resolve();
}
const orderSequence = orderSequences.pop();
return cancelOrder(orderSequence).then(() => cancelAllOrders(orderSequences));
}
api.connect().then(() => {
console.log('Connected...');
return api.getOrders(env.address).then(orders => {
const orderSequences = orders.map(order => order.properties.sequence);
return cancelAllOrders(orderSequences);
}).then(() => process.exit(0));
}).catch(fail);