App-cryp-exchange

 view release on metacpan or  search on metacpan

lib/App/cryp/Exchange/coinbase_pro.pm  view on Meta::CPAN

package App::cryp::Exchange::coinbase_pro;

our $DATE = '2021-05-26'; # DATE
our $VERSION = '0.012'; # VERSION

use 5.010001;
use strict;
use warnings;
use Log::ger;

use POSIX qw(floor);

use Role::Tiny::With;
with 'App::cryp::Role::Exchange';

sub __parse_time {
    state $parser = do {
        require DateTime::Format::ISO8601;
        DateTime::Format::ISO8601->new;
    };
    my $dt = $parser->parse_datetime($_[0]);
    return undef unless $dt;
    $dt->epoch;
}

sub new {
    require Finance::CoinbasePro::Lite;

    my ($class, %args) = @_;

    unless ($args{public_only}) {
        die "Please supply api_key, api_secret, api_passphrase"
            unless $args{api_key} && $args{api_secret}
            && defined $args{api_passphrase};
    }

    $args{_client} = Finance::CoinbasePro::Lite->new(
        key => $args{api_key},
        secret => $args{api_secret},
        passphrase => $args{api_passphrase},
    );

    bless \%args, $class;
}

sub cancel_order {
    my ($self, %args) = @_;

    my $type = $args{type} or return [400, "Please specify type (buy/sell)"];
    my $pair = $args{pair} or return [400, "Please specify pair"];
    my ($basecur, $quotecur) = $pair =~ m!(.+)/(.+)!;
    my $order_id = $args{order_id} or return [400, "Please specify order_id"];

    my $apires = $self->{_client}->private_request(DELETE => "/orders/$order_id");
    return $apires unless $apires->[0] == 200;

    [200, "OK"];
}

my $cache_list_pairs;
sub create_limit_order {
    my ($self, %args) = @_;

    my $type = $args{type} or return [400, "Please specify type (buy/sell)"];
    my $cpair = $args{pair} or return [400, "Please specify pair"];
    my ($basecur, $quotecur) = $cpair =~ m!(.+)/(.+)!;
    my $price = $args{price} or return [400, "Please specify price"];

    my %api_args = (
        type => 'limit',
        side => $args{type},
        product_id => $self->to_native_pair($cpair),
    );

    # round down price according to quote_increment
  HANDLE_OVERPRECISE_PRICE:
    {
        unless ($cache_list_pairs) {
            my $res = $self->list_pairs(detail=>1);



( run in 1.318 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )