| 1 | package Finance::CoinbasePro::API::CLI::Fill; | ||||||||||
| 2 | # this knows about Finance::GDAX::Fill objects and can display them | ||||||||||
| 3 | 1 | ▶ | use Mouse; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Finance::CoinbasePro::API::CLI::Util::CurrencyUtil qw(format_currency); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Finance::CoinbasePro::API::CLI::Util::DateUtil qw(getdatetime convert_seconds_to_human_time my_str2time); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Finance::CoinbasePro::API::CLI::Value; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | has 'created_at' => (is=>'rw', isa=>'Str', required=>1 ); # created_at => "2017-10-31T20:34:14.675Z", | |||||||||
| 9 | 1 | has 'fee' => (is=>'rw', isa=>'Num', required=>1 ); # fee => 0.0044347376379036, | |||||||||
| 10 | 1 | has 'liquidity' => (is=>'rw', isa=>'Str', required=>1 ); # liquidity => "T", | |||||||||
| 11 | 1 | has 'order_id' => (is=>'rw', isa=>'Str', required=>1 ); # order_id => "45eb4883-ed4f-4df5-bf0d-fde87dad2339", | |||||||||
| 12 | 1 | has 'price' => (is=>'rw', isa=>'Num', required=>1 ); # price => "0.04804000", | |||||||||
| 13 | 1 | has 'product_id' => (is=>'rw', isa=>'Str', required=>1 ); # product_id => "ETH-BTC", | |||||||||
| 14 | 1 | has 'profile_id' => (is=>'rw', isa=>'Str', required=>1 ); # profile_id => "18f975e3-6d43-4127-aca5-7d2c13b2ea31", | |||||||||
| 15 | 1 | has 'settled' => (is=>'rw', isa=>'Bool', required=>1 ); # settled => '0', | |||||||||
| 16 | 1 | has 'side' => (is=>'rw', isa=>'Str', required=>1 ); # side => "sell", | |||||||||
| 17 | 1 | has 'size' => (is=>'rw', isa=>'Num', required=>1 ); # size => 30.77114653, | |||||||||
| 18 | 1 | has 'trade_id' => (is=>'rw', isa=>'Num', required=>1 ); # trade_id => 1736807, | |||||||||
| 19 | 1 | has 'volume' => (is=>'rw', isa=>'Maybe[Num]', ); # usd_volume => undef, | |||||||||
| 20 | 1 | has 'user_id' => (is=>'rw', isa=>'Str', required=>1 ); # user_id => "513378df5210ff660900002b", | |||||||||
| 21 | |||||||||||
| 22 | sub source_offset { | ||||||||||
| 23 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
source_offset: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 24 | 0 | my $offset = $self->{size}; | |||||||||
| 25 | 0 | ▶ | if ($self->{side} eq "sell") { $offset = -$offset } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 0 | return Finance::CoinbasePro::API::CLI::Value->new( num=>$offset, currency=>$self->source_currency() ); | |||||||||
| 27 | } | ||||||||||
| 28 | sub source_currency { | ||||||||||
| 29 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
source_currency: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 30 | 0 | my (@n) = split(/-/, $self->{product_id}, 2); | |||||||||
| 31 | 0 | return $n[0]; | |||||||||
| 32 | } | ||||||||||
| 33 | sub destination_offset { | ||||||||||
| 34 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
destination_offset: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 35 | 0 | my $offset = $self->{size} * $self->{price}; | |||||||||
| 36 | 0 | ▶ | if ($self->{side} eq "buy") { $offset = -$offset } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | return Finance::CoinbasePro::API::CLI::Value->new( currency=>$self->destination_currency, num=>$offset ); | |||||||||
| 38 | } | ||||||||||
| 39 | sub destination_currency { | ||||||||||
| 40 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
destination_currency: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 41 | 0 | my (@n) = split(/-/, $self->{product_id}, 2); | |||||||||
| 42 | 0 | return $n[1]; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | # returns a string like '2018-06-13 11:14:11: buy BTC-USD: 10.00000000 BTC at $7,000.00, cost $70,000.00' | ||||||||||
| 47 | sub to_str { | ||||||||||
| 48 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
to_str: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 49 | 1 | my ($from_currency, $to_currency) = split(/-/, $self->{product_id}); | |||||||||
| 50 | 1 | my $offset = $self->{size} * $self->{price}; | |||||||||
| 51 | 1 | ▶ | if ($self->{side} eq "buy") { $offset = -$offset } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | my $str = sprintf( "%s: %s %s: %s at %s, offset %s", | ||||||||||
| 53 | #ago( $self->{created_at} ), | ||||||||||
| 54 | reformat_datetime( $self->{created_at} ), | ||||||||||
| 55 | $self->{side}, # buy/sell | ||||||||||
| 56 | $self->{product_id}, | ||||||||||
| 57 | format_currency($self->{size}, $from_currency), | ||||||||||
| 58 | 1 | format_currency($self->{price}, $to_currency), | |||||||||
| 59 | format_currency($offset, $to_currency) | ||||||||||
| 60 | ); | ||||||||||
| 61 | |||||||||||
| 62 | 1 | return $str; | |||||||||
| 63 | } | ||||||||||
| 64 | sub reformat_datetime { | ||||||||||
| 65 | 1 | ▶ | my $s = shift; | ||||||||
|
Subroutine
reformat_datetime: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 66 | 1 | print "$0: converting time $s\n"; | |||||||||
| 67 | |||||||||||
| 68 | 1 | my $t ; #= my_str2time( $s ); | |||||||||
| 69 | 1 | ▶ | if (! $t) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 1 | $t = my_str2time( $s ); | |||||||||
| 71 | # my $dt = DateTime::Format::ISO8601->parse_datetime( $s ); | ||||||||||
| 72 | # $t = $dt->datetime(); | ||||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 1 | print " to epoch $t\n"; | |||||||||
| 76 | 1 | return getdatetime( $t ); | |||||||||
| 77 | } | ||||||||||
| 78 | sub ago { | ||||||||||
| 79 | 0 | ▶ | my $date = shift; | ||||||||
|
Subroutine
ago: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 80 | 0 | return convert_seconds_to_human_time( time() - my_str2time( $date ) ) . " ago"; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 1 | 1; | |||||||||
| 84 | __END__ | ||||||||||
| 85 | created_at => "2017-10-31T20:34:14.675Z", | ||||||||||
| 86 | fee => 0.0044347376379036, | ||||||||||
| 87 | liquidity => "T", | ||||||||||
| 88 | order_id => "45eb4883-ed4f-4df5-bf0d-fde87dad2339", | ||||||||||
| 89 | price => "0.04804000", | ||||||||||
| 90 | product_id => "ETH-BTC", | ||||||||||
| 91 | profile_id => "18f975e3-6d43-4127-aca5-7d2c13b2ea31", | ||||||||||
| 92 | settled => 1, | ||||||||||
| 93 | side => "sell", | ||||||||||
| 94 | size => 30.77114653, | ||||||||||
| 95 | trade_id => 1736807, | ||||||||||
| 96 | usd_volume => undef, | ||||||||||
| 97 | user_id => "513378df5210ff660900002b", | ||||||||||
| 98 | |||||||||||
| 99 | |||||||||||
| 100 | |||||||||||
| 101 | |||||||||||
| 102 | |||||||||||
| 103 | #################### pod generated by Pod::Autopod - keep this line to make pod updates possible #################### | ||||||||||
| 104 | |||||||||||
| 105 | =head1 NAME | ||||||||||
| 106 | |||||||||||
| 107 | Finance::CoinbasePro::API::CLI::Fill - CoinbasePro Filled Trade Object | ||||||||||
| 108 | |||||||||||
| 109 | |||||||||||
| 110 | =head1 DESCRIPTION | ||||||||||
| 111 | |||||||||||
| 112 | this knows about Finance::GDAX::Fill objects and can display them | ||||||||||
| 113 | |||||||||||
| 114 | |||||||||||
| 115 | =head1 REQUIRES | ||||||||||
| 116 | |||||||||||
| 117 | L<Finance::CoinbasePro::API::CLI::Value> | ||||||||||
| 118 | |||||||||||
| 119 | L<Finance::CoinbasePro::API::CLI::Util::DateUtil> | ||||||||||
| 120 | |||||||||||
| 121 | L<Finance::CoinbasePro::API::CLI::Util::CurrencyUtil> | ||||||||||
| 122 | |||||||||||
| 123 | L<Mouse> | ||||||||||
| 124 | |||||||||||
| 125 | |||||||||||
| 126 | =head1 METHODS | ||||||||||
| 127 | |||||||||||
| 128 | =head2 ago | ||||||||||
| 129 | |||||||||||
| 130 | ago(); | ||||||||||
| 131 | |||||||||||
| 132 | =head2 destination_currency | ||||||||||
| 133 | |||||||||||
| 134 | destination_currency(); | ||||||||||
| 135 | |||||||||||
| 136 | =head2 destination_offset | ||||||||||
| 137 | |||||||||||
| 138 | destination_offset(); | ||||||||||
| 139 | |||||||||||
| 140 | =head2 reformat_datetime | ||||||||||
| 141 | |||||||||||
| 142 | reformat_datetime(); | ||||||||||
| 143 | |||||||||||
| 144 | =head2 source_currency | ||||||||||
| 145 | |||||||||||
| 146 | source_currency(); | ||||||||||
| 147 | |||||||||||
| 148 | =head2 source_offset | ||||||||||
| 149 | |||||||||||
| 150 | source_offset(); | ||||||||||
| 151 | |||||||||||
| 152 | =head2 to_str | ||||||||||
| 153 | |||||||||||
| 154 | to_str(); | ||||||||||
| 155 | |||||||||||
| 156 | returns a string like '2018-06-13 11:14:11: buy BTC-USD: 10.00000000 BTC at $7,000.00, cost $70,000.00' | ||||||||||
| 157 | |||||||||||
| 158 | =cut | ||||||||||
| 159 | |||||||||||