| 1 | package Finance::GDAX::API::Report; | ||||||||||||||||||||
| 2 | 1 | our $VERSION = '0.02'; | |||||||||||||||||||
| 3 | 1 | ▶ | use 5.20.0; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use Finance::GDAX::API::TypeConstraints; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use Finance::GDAX::API; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 1 | extends 'Finance::GDAX::API'; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 1 | has 'type' => (is => 'rw', | |||||||||||||||||||
| 13 | isa => 'ReportType', | ||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||
| 15 | 1 | has 'start_date' => (is => 'rw', | |||||||||||||||||||
| 16 | isa => 'Str', | ||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||
| 18 | 1 | has 'end_date' => (is => 'rw', | |||||||||||||||||||
| 19 | isa => 'Str', | ||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||
| 21 | 1 | has 'product_id' => (is => 'rw', | |||||||||||||||||||
| 22 | isa => 'Str', | ||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||
| 24 | 1 | has 'account_id' => (is => 'rw', | |||||||||||||||||||
| 25 | isa => 'Str', | ||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||
| 27 | 1 | has 'format' => (is => 'rw', | |||||||||||||||||||
| 28 | isa => 'ReportFormat', | ||||||||||||||||||||
| 29 | default => 'pdf', | ||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||
| 31 | 1 | has 'email' => (is => 'rw', | |||||||||||||||||||
| 32 | isa => 'Str', | ||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | # For checking with "get" method | ||||||||||||||||||||
| 36 | 1 | has 'report_id' => (is => 'rw', | |||||||||||||||||||
| 37 | isa => 'Str', | ||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | sub get { | ||||||||||||||||||||
| 41 | 0 | ▶ | my ($self, $report_id) = @_; | ||||||||||||||||||
|
Subroutine
get: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 42 | 0 | ▶ | $report_id = $report_id || $self->report_id; | ||||||||||||||||||
|
Condition0%0/3
$report_id || $self->report_id
MC/DC0%0/2
$report_id || $self->report_id
$report_id
$self->report_id
Truth table0%0/3
A || B
A= $report_idB= $self->report_id
| |||||||||||||||||||||
| 43 | 0 | ▶ | die 'no report_id specified to get' unless $report_id; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 0 | $self->report_id($report_id); | |||||||||||||||||||
| 45 | 0 | my $path = "/reports/$report_id"; | |||||||||||||||||||
| 46 | 0 | $self->path($path); | |||||||||||||||||||
| 47 | 0 | $self->method('GET'); | |||||||||||||||||||
| 48 | 0 | return $self->send; | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | sub create { | ||||||||||||||||||||
| 52 | 2 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
create: called CC=9 SCAR=28.5
Pod
documented
| |||||||||||||||||||||
| 53 | 2 | ▶ | die 'report type is required' unless $self->type; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | 2 | ▶ | die 'report start date is required' unless $self->start_date; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | 2 | ▶ | die 'report end date is required' unless $self->end_date; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 2 | my %body = ( type => $self->type, | |||||||||||||||||||
| 57 | start_date => $self->start_date, | ||||||||||||||||||||
| 58 | end_date => $self->end_date, | ||||||||||||||||||||
| 59 | format => $self->format ); | ||||||||||||||||||||
| 60 | 2 | ▶ | if ($self->type eq 'fills') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 1 | ▶ | die 'product_id is required for fills report' unless $self->product_id; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | 0 | $body{product_id} = $self->product_id; | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | 1 | ▶ | if ($self->type eq 'account') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | 1 | ▶ | die 'account_id is required for account report' unless $self->account_id; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | 0 | $body{account_id} = $self->account_id; | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | 0 | ▶ | $body{email} = $self->email if $self->email; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 69 | 0 | $self->method('POST'); | |||||||||||||||||||
| 70 | 0 | $self->body(\%body); | |||||||||||||||||||
| 71 | 0 | $self->path('/reports'); | |||||||||||||||||||
| 72 | 0 | return $self->send; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 76 | 1 | 1; | |||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | =head1 NAME | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | Finance::GDAX::API::Report - Generate GDAX Reports | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | =head1 SYNOPSIS | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | use Finance::GDAX::API::Report; | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | $report = Finance::GDAX::API::Report->new( | ||||||||||||||||||||
| 87 | start_date => '2017-06-01T00:00:00.000Z', | ||||||||||||||||||||
| 88 | end_date => '2017-06-15T00:00:00.000Z', | ||||||||||||||||||||
| 89 | type => 'fills'); | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | $report->product_id('BTC-USD'); | ||||||||||||||||||||
| 92 | $result = $report->create; | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | $report_id = $$result{id}; | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | # After you create the report, you check if it's generated yet | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | $report = Finance::GDAX::API::Report->new; | ||||||||||||||||||||
| 99 | $result = $report->get($report_id); | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | if ($$result{status} eq 'ready') { | ||||||||||||||||||||
| 102 | `wget $$result{file_url}`; | ||||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | =head2 DESCRIPTION | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | Generating reports at GDAX is a 2-step process. First you must tell | ||||||||||||||||||||
| 108 | GDAX to create the report, then you must check to see if the report is | ||||||||||||||||||||
| 109 | ready for download at a URL. You can also specify and email address to | ||||||||||||||||||||
| 110 | have it mailed. | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | Reports can be "fills" or "account". If fills, then a product_id is | ||||||||||||||||||||
| 113 | needed. If account then an account_id is needed. | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | The format can be "pdf" or "csv" and defaults to "pdf". | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | =head1 ATTRIBUTES | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | =head2 C<type> $string | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | Report type, either "fills" or "account". This must be set before | ||||||||||||||||||||
| 122 | calling the "create" method. | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | =head2 C<start_date> $datetime_string | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | Start of datetime range of report in the format | ||||||||||||||||||||
| 127 | "2014-11-01T00:00:00.000Z" (required for create) | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | =head2 C<end_date> $datetime_string | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | End of datetime range of report in the format | ||||||||||||||||||||
| 132 | "2014-11-01T00:00:00.000Z" (required for create) | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | =head2 C<product_id> $string | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | The product ID, eg 'BTC-USD'. Required for fills type. | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | =head2 C<account_id> $string | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | The account ID. Required for account type. | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | =head2 C<format> $string | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | Output format of report, either "pdf" or "csv" (default "pdf") | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | =head2 C<email> $string | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | Email address to send the report to (optional) | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | =head2 C<report_id> $string | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | This is used for the "get" method only, and can also be passed as a | ||||||||||||||||||||
| 153 | parameter to the "get" method. | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | It is the report id as returned by the "create" method. | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | =head1 METHODS | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | =head2 C<create> | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | Creates the GDAX report based upon the attributes set and returns a | ||||||||||||||||||||
| 162 | hash result as documented in the API: | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | { | ||||||||||||||||||||
| 165 | "id": "0428b97b-bec1-429e-a94c-59232926778d", | ||||||||||||||||||||
| 166 | "type": "fills", | ||||||||||||||||||||
| 167 | "status": "pending", | ||||||||||||||||||||
| 168 | "created_at": "2015-01-06T10:34:47.000Z", | ||||||||||||||||||||
| 169 | "completed_at": undefined, | ||||||||||||||||||||
| 170 | "expires_at": "2015-01-13T10:35:47.000Z", | ||||||||||||||||||||
| 171 | "file_url": undefined, | ||||||||||||||||||||
| 172 | "params": { | ||||||||||||||||||||
| 173 | "start_date": "2014-11-01T00:00:00.000Z", | ||||||||||||||||||||
| 174 | "end_date": "2014-11-30T23:59:59.000Z" | ||||||||||||||||||||
| 175 | } | ||||||||||||||||||||
| 176 | } | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | =head2 C<get> [$report_id] | ||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | Returns a hash representing the status of the report created with the | ||||||||||||||||||||
| 181 | "create" method. | ||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | The parameter $report_id is optional - if it is passed to the method, | ||||||||||||||||||||
| 184 | it overrides the object's report_id attribute. | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | The result when first creating the report might look like this: | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | { | ||||||||||||||||||||
| 189 | "id": "0428b97b-bec1-429e-a94c-59232926778d", | ||||||||||||||||||||
| 190 | "type": "fills", | ||||||||||||||||||||
| 191 | "status": "creating", | ||||||||||||||||||||
| 192 | "created_at": "2015-01-06T10:34:47.000Z", | ||||||||||||||||||||
| 193 | "completed_at": undefined, | ||||||||||||||||||||
| 194 | "expires_at": "2015-01-13T10:35:47.000Z", | ||||||||||||||||||||
| 195 | "file_url": undefined, | ||||||||||||||||||||
| 196 | "params": { | ||||||||||||||||||||
| 197 | "start_date": "2014-11-01T00:00:00.000Z", | ||||||||||||||||||||
| 198 | "end_date": "2014-11-30T23:59:59.000Z" | ||||||||||||||||||||
| 199 | } | ||||||||||||||||||||
| 200 | } | ||||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | While the result when GDAX finishes generating the report might look | ||||||||||||||||||||
| 203 | like this: | ||||||||||||||||||||
| 204 | |||||||||||||||||||||
| 205 | { | ||||||||||||||||||||
| 206 | "id": "0428b97b-bec1-429e-a94c-59232926778d", | ||||||||||||||||||||
| 207 | "type": "fills", | ||||||||||||||||||||
| 208 | "status": "ready", | ||||||||||||||||||||
| 209 | "created_at": "2015-01-06T10:34:47.000Z", | ||||||||||||||||||||
| 210 | "completed_at": "2015-01-06T10:35:47.000Z", | ||||||||||||||||||||
| 211 | "expires_at": "2015-01-13T10:35:47.000Z", | ||||||||||||||||||||
| 212 | "file_url": "https://example.com/0428b97b.../fills.pdf", | ||||||||||||||||||||
| 213 | "params": { | ||||||||||||||||||||
| 214 | "start_date": "2014-11-01T00:00:00.000Z", | ||||||||||||||||||||
| 215 | "end_date": "2014-11-30T23:59:59.000Z" | ||||||||||||||||||||
| 216 | } | ||||||||||||||||||||
| 217 | } | ||||||||||||||||||||
| 218 | |||||||||||||||||||||
| 219 | =cut | ||||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | |||||||||||||||||||||
| 222 | =head1 AUTHOR | ||||||||||||||||||||
| 223 | |||||||||||||||||||||
| 224 | Mark Rushing <mark@orbislumen.net> | ||||||||||||||||||||
| 225 | |||||||||||||||||||||
| 226 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 227 | |||||||||||||||||||||
| 228 | This software is copyright (c) 2017 by Home Grown Systems, SPC. | ||||||||||||||||||||
| 229 | |||||||||||||||||||||
| 230 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 231 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 232 | |||||||||||||||||||||
| 233 | =cut | ||||||||||||||||||||
| 234 | |||||||||||||||||||||