Skip to content

Commit

Permalink
add cancel-all to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
defunctzombie committed Mar 28, 2012
1 parent 53c804c commit f37f4d3
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion bin/cli_trader.js
Expand Up @@ -69,7 +69,7 @@ var handlers = {
}

var details = {
productt: params.shift(),
product_id: params.shift(),
size: params.shift(),
price: params.shift(),
side: 1,
Expand Down Expand Up @@ -106,6 +106,44 @@ var handlers = {
cb();
});
},
'cancel-all': function(params, cb) {
if (params.length != 1) {
console.log('cancel-all <product_id>');
return cb();
}

var product_id = params.shift();

trader.orders(function(err, orders) {
if (err) {
console.log('[error] %s'.red, err.message);
return cb();
}

(function next(err, detail) {
if (err) {
console.log('[error] %s'.red, err.message);
return cb();
}

if (detail) {
console.log('[cancelled] order id: %s'.green, detail.order_id);
}

var order = orders.shift();
if (!order) {
return cb();
}

var details = {
product_id: product_id,
order_id: order.id,
}

trader.cancel_order(details, next);
})();
});
},
'orders': function(params, cb) {
trader.orders(function(err, orders) {
if (err) {
Expand Down Expand Up @@ -161,6 +199,7 @@ var handlers = {
console.log('buy <product_id> <size> <price>');
console.log('sell <product_id> <size> <price>');
console.log('cancel <product_id> <order_id>');
console.log('cancel-all <product_id>');
console.log('--------');
console.log('orders');
console.log('accounts');
Expand Down

0 comments on commit f37f4d3

Please sign in to comment.