App-cryp-arbit
view release on metacpan or search on metacpan
lib/App/cryp/arbit.pm view on Meta::CPAN
my $time = time();
for my $op (@open_order_pairs) {
log_debug "Checking order pair #%d (buy status=%s, sell status=%s) ...",
$op->{id}, $op->{buy_status}, $op->{sell_status};
CHECK_BUY_ORDER: {
last if $op->{buy_status} =~ /\A(done|cancelled)\z/;
my $client = _get_exchange_client($r, $op->{buy_exchange}, $op->{buy_account});
my $res = $client->get_order(pair=>$op->{buy_pair}, type=>'buy', order_id=>$op->{buy_order_id});
if ($res->[0] == 404) {
# assume 404 as order which was never filled and got cancelled.
# some exchanges, e.g. coinbase-pro returns 404 for such orders
$code_update_buy_status->($op->{id}, 'cancelled', 'not found via get_order(), assume cancelled without being filled');
last;
} elsif ($res->[0] != 200) {
log_error "Couldn't get buy order %s (pair %s): %s",
$op->{buy_order_id}, $op->{buy_pair}, $res;
last;
} else {
my $status = $res->[2]{status};
$code_update_buy_filled_base_size->($op->{id}, $res->[2]{filled_base_size});
$code_update_buy_status->($op->{id}, $status);
lib/App/cryp/arbit.pm view on Meta::CPAN
$code_update_buy_status->($op->{id}, "cancelled");
}
}
}
} # CHECK_BUY_ORDER
CHECK_SELL_ORDER: {
last if $op->{sell_status} =~ /\A(done|cancelled)\z/;
my $client = _get_exchange_client($r, $op->{sell_exchange}, $op->{sell_account});
my $res = $client->get_order(pair=>$op->{sell_pair}, type=>'sell', order_id=>$op->{sell_order_id});
if ($res->[0] == 404) {
# assume 404 as order which was never filled and got cancelled.
# some exchanges, e.g. coinbase-pro returns 404 for such orders
$code_update_sell_status->($op->{id}, 'cancelled', 'not found via get_order(), assume cancelled without being filled');
last;
} elsif ($res->[0] != 200) {
log_error "Couldn't get sell order %s (pair %s): %s",
$op->{sell_order_id}, $op->{sell_pair}, $res;
last;
} else {
my $status = $res->[2]{status};
$code_update_sell_filled_base_size->($op->{id}, $res->[2]{filled_base_size});
$code_update_sell_status->($op->{id}, $status);
( run in 1.333 second using v1.01-cache-2.11-cpan-39bf76dae61 )