lib/Finance/IG.pm

filter: Statementstmt 41.7% 285 / 683 Branchbran 22.5% 72 / 320 Conditioncond 30.5% 43 / 141 MC/DCmcdc 7.2% 6 / 83 Subroutinesub 55.0% 22 / 40 Podpod 100% 26 / 26 totaltotal 35.1% 454 / 1293 CC 231 SCAR 54.4
CC
231
Cov
35%
flatten_withunder
702.0
prices
506.0
printpos
381.8
CRAP 231.2
↑ Summary lib/Finance/IG/Record/REST/Client.pm »
1 package Finance::IG;
2  
3 # use 5.010000; I cannot get this to work, trying to say it should run with perl 5.10 or greater and should be fine with 5.32
4 # but get message ! Installing the dependencies failed: Your Perl (5.032001) is not in the range '5.10'
5 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =encoding utf8
10  
11 =head1 NAME
12  
13 Finance::IG - - Module for doing useful stuff with IG Markets REST API.
14  
15 =head1 DESCRIPTION
16  
17 This is very much a first draft, but will enable you to get simple arrays of positions, print them out possily some simple trading.
18  
19 Its proof of concept in perl beyond anything else, extend it as you need to.
20  
21 I have only used it for spreadbet accounts, it would be simple to extend to CFD's but I dont have CFD data or an interest in CFD's so have not done this.
22  
23 You will need an API key to use this module, available free from IG Markets.
24  
25 =head1 VERSION
26  
27 Version 0.103
28  
29 =cut
30  
31 5 our $VERSION = '0.103';
32  
33  
34 =head1 SYNOPSIS
35  
36 use Finance::IG;
37 use strict;
38 no strict 'refs';
39 use warnings;
40  
41 my $ig=iFinance::IG->new(
42 username=> "demome",
43 password=> "mypassword",
44 apikey=> "4398232394029341776153276512736icab",
45 isdemo=>0,
46 );
47
48 my $p=$ig->positions(); # Get a list of positions
49 $p=$ig->agg($p,$sortlist); # Aggregate them, so one item per instrument.
50  
51 my $format="%-41sinstrumentName %+6.2fsize %-9.2flevel ".
52 "%-9.2fbid £%-8.2fprofit %5.1fprofitpc%% £%10.2fatrisk\n",
53  
54 $ig->printpos("stdout" , [], $format);
55  
56 for my $position (@$p)
57 {
58 $ig-> printpos("stdout" ,$position,$format);
59 }
60  
61 =head1 UTILITIES
62  
63 The utility igdisp.pl is installed with this module and may be used to list your positions on IG. A help message can be obtained with igdisp.pl -h
64  
65 =head1 SUBROUTINES/METHODS
66  
67 This is a list of currently implemented methods
68  
69 =head2 new
70
71 Normal parameters, as above.
72  
73 col=>1
74  
75 Causes Finance::IG to try to use Term::Chrome to do some simple coloration of output.
76 If Term::Chrome is not installed, it will be silently ignored. See printpos.
77  
78 =head2 login
79  
80 Originally needed to be called once after new and before other calls. Now this is done automatically,
81 so you do not need to use this or be aware of it. Look for a 401 error if your password is
82 wrong.
83  
84  
85 No Parameters.
86  
87 =head2 printpos print out a formatted hash as one line
88  
89 Parameters
90
91 file - can be a file handle or the string stdout or the glob *STDOUT
92 A position of other shallow hash,
93 A format string. The format string is similar to a printf format string, for example %s says print out a string
94 however, the name of the item to be printed follows the letter, eg %sinstrumentName print the string instrument name.
95 optional up
96 optional down
97  
98 A title line can be printed by either passing an array ref instead of a position, in which case the array ref can contain
99 the titles to print. If the array is empty then the titles will be generated from the format string.
100  
101 up and down can be provided and represent negative and posite limits on dbid element by default.
102 Alternatively, provide up only and make it a subroutine ref.
103  
104 The subroutime takes parameter a position, and should return escape characters (from Term::Chrome to colorise the line.
105  
106 =head2 transactions - retrieve transactions history
107  
108 transactions(++$page,Time::Piece->strptime("2020-01-01","%Y-%m-%d-%H.%M"),scalar localtime)
109  
110 Parameters
111  
112 Paging number, start at 1
113 Start time, can be a string or a Time::Piece
114 Endtime
115  
116 return a reference to an array of transactions for that time span. Each transaction is a hash of data.
117  
118 =cut
119  
120 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
121 5 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
122 5 ▶use REST::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
123 #use Data::Dump qw(dump); # used in some commented out debug statements
124 #use Scalar::Util;
125 5 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
126  
127 5 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.6
128 5 ▶ if (eval("require Term::Chrome"))
Branch: 1 branch
BranchTrueFalseTotal
if (eval 'require Term::Chrome') { } 0 5 5
129 {
130 0 Term::Chrome->import();
131 }
132 else
133 {
134 5 ▶ map { eval ("sub $_ {}") } qw(Red Blue Bold Reset Underline Green color); # need these to avoid compile time errors.
Subroutine Blue: not called CC=1 SCAR=0.0
Subroutine Bold: not called CC=1 SCAR=0.0
Subroutine Green: not called CC=1 SCAR=0.0
Subroutine Red: not called CC=1 SCAR=0.0
Subroutine Reset: not called CC=1 SCAR=0.0
Subroutine Underline: not called CC=1 SCAR=0.0
Subroutine color: not called CC=1 SCAR=0.0
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
135 }
136 }
137 5 has 'apikey' => (
138 is=>'ro',
139 isa=>'Str',
140 required=>1,
141 );
142 5 has 'username' => (
143 is=>'ro',
144 isa=>'Str',
145 required=>1,
146 );
147 5 has 'password' => (
148 is=>'ro',
149 isa=>'Str',
150 required=>1,
151 );
152 5 has 'isdemo' => (
153 is=>'ro',
154 isa=>'Bool',
155 required=>1,
156 );
157 5 has 'CST' => (
158 is=>'rw',
159 isa=>'Str',
160 );
161 5 has 'XSECURITYTOKEN' => (
162 is=>'rw',
163 isa=>'Str',
164 );
165  
166 5 has 'XSTTIME' => (
167 is=>'rw',
168 isa=>'Int',
169 );
170 5 has 'col' => ( # set to 1 to use Term::Chrome for coloration.
171 is=>'rw',
172 isa=>'Bool',
173 default=>0,
174 );
175 5 has 'uds' => (
176 is=>'rw',
177 isa=>'Str',
178 default=>'',
179 );
180  
181 3 ▶around 'new' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
182 3 my $orig = shift;
183 3 my $self = shift;
184 3 my $r;
185
186 3 $r=$self->$orig(@_);
187 3 $r->login;
188 3 return $r;
189 5 };
190 sub _url
191 23 ▶{
Subroutine _url: called CC=2 SCAR=7.1
192 23 my ($self) = @_;
193 23 ▶ return 'https://demo-api.ig.com/gateway/deal' if ( $self->isdemo);
Branch: 1 branch
BranchTrueFalseTotal
if $self->isdemo 0 23 23
194 23 return 'https://api.ig.com/gateway/deal';
195 }
196  
197  
198 ##########################################################################
199 =head2 login - loginto the account.
200  
201 Parameters - none
202  
203 login to the object, using the parameters provided to new.
204  
205 You should call this just once per object after calling new.
206  
207 =cut
208 ##########################################################################
209 5 ▶sub login {
Subroutine login: called CC=4 SCAR=14.0
Pod documented
210 5 my ($self) = @_;
211 5 my $headers =
212 {
213 'Content-Type' => 'application/json; charset=UTF-8',
214 'Accept' => 'application/json; charset=UTF-8',
215 VERSION => 2,
216 'X-IG-API-KEY'=> $self->apikey
217 };
218 5 my $data = {
219 identifier => $self->username,
220 password => $self->password,
221 };
222 # my $jdata = encode_json($data);
223 5 my $jdata=JSON->new->canonical->encode($data);
224  
225 5 my $client = REST::Client->new();
226 5 $client->setHost($self->_url);
227  
228  
229 5 $client->POST (
230 '/session',
231 $jdata,
232 $headers
233 );
234 5 my $code=$client->responseCode();
235 5 ▶ die "response code from login $code" if ($code!=200);
Branch: 1 branch
BranchTrueFalseTotal
if $code != 200 0 5 5
236 5 ▶ $self->CST($client->responseHeader('CST') // die "No CST header in login response");
Condition50%1/2
$client->responseHeader("CST") // die("No CST header in login response")
l!l
50
MC/DC0%0/1
$client->responseHeader("CST") // die("No CST header in login response")
$client->responseHeader("CST")
Truth table50%1/2
A
A= $client->responseHeader("CST")
Aresult
11
00
237 5 ▶ $self->XSECURITYTOKEN($client->responseHeader('X-SECURITY-TOKEN') // die "No X-SECURITY-TOKEN in login response header");
Condition50%1/2
$client->responseHeader("X-SECURITY-TOKEN") // die("No X-SECURITY-TOKEN in login response header")
l!l
50
MC/DC0%0/1
$client->responseHeader("X-SECURITY-TOKEN") // die("No X-SECURITY-TOKEN in login response header")
$client->responseHeader("X-SECURITY-TOKEN")
Truth table50%1/2
A
A= $client->responseHeader("X-SECURITY-TOKEN")
Aresult
11
00
238 5 $self->XSTTIME(time());
239 5 return;
240 }
241 ##########################################################################
242  
243 =head2 flatten
244  
245 Parameters
246 1 Ref to array of hashes to flatten or a ref to a hash to flatten
247 2 ref to an array of items to flatten, or just a single item name.
248  
249 Typical use of this is for a position that as it comes back from IG contains a market and a position
250 byut we would prefer all items at the top level. This would moves all the keys of position and market up one level and
251 would remove the keys market and position.
252  
253 $self->flatten($hash, [qw(market position)]);
254  
255 =cut
256 ##########################################################################
257 sub flatten
258 1 ▶{
Subroutine flatten: called CC=10 SCAR=24.1
Pod documented
259 1 my ($self)=shift;
260 1 my ($hash)=shift;
261 1 my ($toflatten)=shift;
262  
263 1 ▶ $hash=[$hash] if (ref($hash) ne 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $hash ne "ARRAY" 0 1 1
264 1 ▶ $toflatten=[$toflatten] if (ref($toflatten) ne 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $toflatten ne "ARRAY" 0 1 1
265  
266 1 for my $h (@$hash)
267 {
268 132 for my $key (@$toflatten)
269 {
270 264 ▶ if (exists($h->{$key}))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $h->{$key}) 264 0 264
271 {
272 264 ▶ if (defined($h->{$key}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $h->{$key}) 264 0 264
273 {
274 264 ▶ die "key $key to flatten is not a hash" if (ref($h->{$key}) ne 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $h->{$key} ne "HASH" 0 264 264
275 264 for my $subkey (keys %{$h->{$key}})
276 {
277 4224 ▶ die "subkey exists $subkey" if (exists($h->{$subkey}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $h->{$subkey} 0 4224 4224
278 4224 $h->{$subkey}=$h->{$key}->{$subkey};
279 }
280 }
281 264 delete $h->{$key};
282 }
283 }
284 }
285 }
286 sub transactions
287 16 ▶{
Subroutine transactions: called CC=15 SCAR=29.1
Pod documented
288  
289 16 my ($self) = shift;
290 16 my ($pageNumber)=shift;
291 16 my ($from) =shift;
292 16 my ($to)=shift;
293  
294 16 my $pageSize=50;
295  
296 16 ▶ $from//='';
Condition50%1/2
$from //= ""
l!l
160
MC/DC0%0/1
$from //= ""
$from
Truth table50%1/2
A
A= $from
Aresult
11
00
297 16 ▶ $to//='';
Condition50%1/2
$to //= ""
l!l
160
MC/DC0%0/1
$to //= ""
$to
Truth table50%1/2
A
A= $to
Aresult
11
00
298  
299 16 ▶ if (ref($to) eq 'Time::Piece')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $to eq "Time::Piece") 0 16 16
300 {
301 0 $to=$to->strftime("%Y-%m-%dT%H:%M:%S");
302 }
303 16 ▶ if (ref($from) eq 'Time::Piece')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $from eq "Time::Piece") 16 0 16
304 {
305 16 $from=$from->strftime("%Y-%m-%dT%H:%M:%S");
306 }
307 16 ▶ $to=~m/^[-0-9T:]*$/ or die "Invalid date format for 'to' $to, is a ".ref(\$to);
Branch: 1 branch
BranchTrueFalseTotal
$to =~ /^[-0-9T:]*$/ or die "Invalid date format for 'to' $to, is a " . ref(\$to) 16 0 16
308 16 ▶ $from=~m/^[-0-9T:]*$/ or die "Invalid date format for 'from' $from";
Branch: 1 branch
BranchTrueFalseTotal
$from =~ /^[-0-9T:]*$/ or die "Invalid date format for 'from' $from" 16 0 16
309  
310 16 my $headers = {
311 'Content-Type' => 'application/json; charset=UTF-8',
312 'Accept' => 'application/json; charset=UTF-8',
313 VERSION => 2,
314 CST=>$self->CST,
315 'X-SECURITY-TOKEN'=> $self->XSECURITYTOKEN,
316 'X-IG-API-KEY'=> $self->apikey,
317 };
318 #my $jheaders = encode_json($headers);
319 16 my $jheaders=JSON->new->canonical->encode($headers);
320  
321 16 my $client = REST::Client->new();
322 16 $client->setHost($self->_url);
323  
324 16 ▶ $from and $from="from=$from";
Branch: 1 branch
BranchTrueFalseTotal
$from and $from = "from=$from" 16 0 16
325 16 ▶ $to and $to="to=$to";
Branch: 1 branch
BranchTrueFalseTotal
$to and $to = "to=$to" 16 0 16
326 16 my $rpage=$pageNumber; # requested page number as integer, 1 is first
327 16 ▶ $pageNumber and $pageNumber="pageNumber=$pageNumber";
Branch: 1 branch
BranchTrueFalseTotal
$pageNumber and $pageNumber = "pageNumber=$pageNumber" 16 0 16
328 16 ▶ $pageSize and $pageSize="pageSize=$pageSize";
Branch: 1 branch
BranchTrueFalseTotal
$pageSize and $pageSize = "pageSize=$pageSize" 16 0 16
329  
330 16 ▶ my $url=join '', map { $_?'&'.$_:'' } ($from,$to,$pageNumber,$pageSize);
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 64 0 64
331 16 $url=~s/^&//;
332 16 ▶ $url='?'.$url if ($url);
Branch: 1 branch
BranchTrueFalseTotal
if $url 16 0 16
333  
334 16 $url='/history/transactions'.$url;
335 16 $client->GET (
336 $url,
337 $headers
338 );
339  
340 16 my $code=$client->responseCode();
341 16 ▶ if ($code==200)
Branch: 1 branch
BranchTrueFalseTotal
if ($code == 200) { } 16 0 16
342 {
343 16 my $resp=decode_json($client->responseContent());
344 # $resp=$self->flatten($resp,[qw/transactions metadata/]);
345 #die encode_json($resp);
346  
347 16 my @activities=@{$resp->{transactions}};
348 # pncerint encode_json( $resp->{metadata} );
349 # {"pageData":{"totalPages":11,"pageNumber":11,"pageSize":50},"size":534}***** 34
350 16 ▶ return undef if ($rpage > $resp->{metadata}->{pageData}->{pageNumber});
Branch: 1 branch
BranchTrueFalseTotal
if $rpage > $resp->{"metadata"}{"pageData"}{"pageNumber"} 1 15 16
351 # return undef if (@activities==0);
352 15 return \@activities;
353 }
354 else
355 {
356 0 print "failed $code: ".$client->responseContent()."\n";
357 0 return undef;
358 }
359 }
360  
361 # example from/ to sting format:
362 # 2020-10-28
363 # 2020-10-28T15:30
364  
365 # keys in retirn, when called with detailed=1
366 # type, goodTillDate, actions(ARRAY) , epic, direction, level, channel, marketName, date, dealReference, guaranteedStop, stopLevel, size, currency, stopDistance, trailingStep, status, trailingStopDistance, limitLevel, description, dealId, period, limitDistance
367 # without:
368 # period, details, date, dealId, epic, description, channel, status, type
369  
370 sub history
371 0 ▶{
Subroutine history: not called CC=18 SCAR=58.3
Pod documented
372 0 my ($self) = shift;
373 0 my ($detailed)=shift; ## undef, not detailed, 1 for detailed.
374 0 my ($pageNumber)=shift;
375  
376  
377 0 my ($from) = shift;
378 0 my ($to) = shift;
379  
380 0 ▶ $pageNumber//='';
Condition0%0/2
$pageNumber //= ""
l!l
00
MC/DC0%0/1
$pageNumber //= ""
$pageNumber
Truth table0%0/2
A
A= $pageNumber
Aresult
11
00
381 0 my $pageSize=50;
382  
383 0 ▶ $from//='';
Condition0%0/2
$from //= ""
l!l
00
MC/DC0%0/1
$from //= ""
$from
Truth table0%0/2
A
A= $from
Aresult
11
00
384 0 ▶ $to//='';
Condition0%0/2
$to //= ""
l!l
00
MC/DC0%0/1
$to //= ""
$to
Truth table0%0/2
A
A= $to
Aresult
11
00
385  
386 0 ▶ if (ref($to) eq 'Time::Piece')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $to eq "Time::Piece") 0 0 0
387 {
388 0 $to=$to->strftime("%Y-%m-%dT%H:%M:%S");
389 }
390 0 ▶ if (ref($from) eq 'Time::Piece')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $from eq "Time::Piece") 0 0 0
391 {
392 0 $from=$from->strftime("%Y-%m-%dT%H:%M:%S");
393 }
394  
395 0 ▶ $to=~m/^[-0-9T:]*$/ or die "Invalid date format for 'to' $to";
Branch: 1 branch
BranchTrueFalseTotal
$to =~ /^[-0-9T:]*$/ or die "Invalid date format for 'to' $to" 0 0 0
396 0 ▶ $from=~m/^[-0-9T:]*$/ or die "Invalid date format for 'from' $from";
Branch: 1 branch
BranchTrueFalseTotal
$from =~ /^[-0-9T:]*$/ or die "Invalid date format for 'from' $from" 0 0 0
397  
398 0 my $headers = {
399 'Content-Type' => 'application/json; charset=UTF-8',
400 'Accept' => 'application/json; charset=UTF-8',
401 VERSION => 2,
402 CST=>$self->CST,
403 'X-SECURITY-TOKEN'=> $self->XSECURITYTOKEN,
404 'X-IG-API-KEY'=> $self->apikey,
405 };
406 #my $jheaders = encode_json($headers);
407 0 my $jheaders=JSON->new->canonical->encode($headers);
408  
409 0 my $client = REST::Client->new();
410 0 $client->setHost($self->_url);
411 0 ▶ $from="from=$from" if ($from ne '');
Branch: 1 branch
BranchTrueFalseTotal
if $from ne "" 0 0 0
412 0 ▶ $to="to=$to" if ($to ne '');
Branch: 1 branch
BranchTrueFalseTotal
if $to ne "" 0 0 0
413 0 ▶ if ($detailed)
Branch: 1 branch
BranchTrueFalseTotal
if ($detailed) { } 0 0 0
414 {
415 0 $detailed="detailed=true"
416 }
417 else
418 {
419 0 $detailed='';
420 }
421  
422 0 ▶ $pageNumber="pageNumber=$pageNumber" if ($pageNumber);
Branch: 1 branch
BranchTrueFalseTotal
if $pageNumber 0 0 0
423 0 ▶ $pageSize//='';
Condition0%0/2
$pageSize //= ""
l!l
00
MC/DC0%0/1
$pageSize //= ""
$pageSize
Truth table0%0/2
A
A= $pageSize
Aresult
11
00
424 0 ▶ $pageSize="pageSize=$pageSize" if ($pageSize);
Branch: 1 branch
BranchTrueFalseTotal
if $pageSize 0 0 0
425  
426 # my $sep='?';
427 # map { $_ eq '' or $_=$sep.$_ and $sep='&'} ($from,$to,$detailed,$pageNumber,$pageSize);
428  
429 0 ▶ my $url=join '', map { $_?'&'.$_:'' } ($from,$to,$detailed,$pageNumber,$pageSize);
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 0 0 0
430 0 $url=~s/^&//;
431 0 ▶ $url='?'.$url if ($url);
Branch: 1 branch
BranchTrueFalseTotal
if $url 0 0 0
432  
433 0 $url='/history/activity'.$url;
434  
435 # die $url;
436  
437 0 $client->GET (
438 $url,
439 $headers
440 );
441  
442 0 my $code=$client->responseCode();
443  
444 0 ▶ if ($code==200)
Branch: 1 branch
BranchTrueFalseTotal
if ($code == 200) { } 0 0 0
445 {
446 0 my $resp=decode_json($client->responseContent());
447 0 my @activities=@{$resp->{activities}};
448 0 ▶ return undef if (@activities==0);
Branch: 1 branch
BranchTrueFalseTotal
if @activities == 0 0 0 0
449 0 $self->flatten(\@activities,'details');
450 0 return \@activities;
451 }
452 else
453 {
454 0 print "failed $code: ".$client->responseContent()."\n";
455 0 return undef;
456 }
457 }
458 # example response:
459 #{"metadata":{"paging":{"size":50,"next":"/history/activity?version=3&from=2020-10-28T00:00:00&to=2020-10-29T16:41:45&detailed=false&pageSize=50"}}
460 # "activities": [.... ]
461 # }
462 # each activity looks like:
463 #{
464 # details=>null,
465 # dealId=>"DIAAAAFRS39HJAK",
466 # period=>"DFB",
467 # type=>"POSITION",
468 # epic=>"UA.D.ATVI.DAILY.IP",
469 # description=>"Position partially closed=> J6GK8WA9",
470 # date=>"2020-10-29T17:47:46",
471 # status=>"ACCEPTED",
472 # channel=>"SYSTEM"
473 #
474 # or with detail
475 # {"activities":
476 # [
477 # [
478 # {"date":"2020-11-19T18:41:04",
479 # "epic":"UC.D.MU.DAILY.IP",
480 # "period":"DFB",
481 # "dealId":"DIAAAAFVXZV5LA5",
482 # "channel":"WEB",
483 # "type":"POSITION",
484 # "status":"ACCEPTED",
485 # "description":"Position opened: VXZV5LA5",
486 # "details":
487 # {
488 # "dealReference":"6XQESB1EQGWY4FR2",
489 # "actions":
490 # [
491 # {"actionType":"POSITION_OPENED",
492 # "affectedDealId":"DIAAAAFVXZV5LA5"
493 # }
494 # ],
495 # "marketName":"Micron Technology Inc (All Sessions)",
496 # "goodTillDate":null,
497 # "currency":"GBP",
498 # "size":0.4,
499 # "direction":"BUY",
500 # "level":6123,
501 # "stopLevel":null,
502 # "stopDistance":null,
503 # "guaranteedStop":false,
504 # "trailingStopDistance":null,
505 # "trailingStep":null,
506 # "limitLevel":null,
507 # "limitDistance":null
508 # }
509 # },
510 # {"date":"2020-11-17T11:33:52",
511 #"epic":"KA.D.FSTA.DAILY.IP",
512 #"period":"DFB",
513 #"dealId":"DIAAAAFVEFD4GAG",
514 #"channel":"WEB",
515 #"type":"POSITION",
516 #"status":"ACCEPTED",
517 #"description":"Position/s closed: HH93GXAZ",
518 #"details":{"dealReference":"6XQESB1EQAZNR6V3",
519 #"actions":[{"actionType":"POSITION_CLOSED",
520 #"affectedDealId":"DIAAAAFHH93GXAZ"}],
521 #"marketName":"Fuller Smith & Turner",
522 #"goodTillDate":null,
523 #"currency":"GBP",
524 #"size":1,
525 #"direction":"SELL",
526 #"level":726.2,
527 #"stopLevel":null,
528 #"stopDistance":null,
529 #"guaranteedStop":false,
530 #"trailingStopDistance":null,
531 #"trailingStep":null,
532 #"limitLevel":null,
533 #"limitDistance":null}},
534 #}
535  
536 # with detailed=1
537  
538 #{
539 # "activities": [
540 # {
541 # "date": "2020-11-19T18:41:04",
542 # "epic": "UC.D.MU.DAILY.IP",
543 # "period": "DFB",
544 # "dealId": "DIAAAAFVXZV5LA5",
545 # "channel": "WEB",
546 # "type": "POSITION",
547 # "status": "ACCEPTED",
548 # "description": "Position opened: VXZV5LA5",
549 # "details": {
550 # "dealReference": "6XQESB1EQGWY4FR2",
551 # "actions": [
552 # {
553 # "actionType": "POSITION_OPENED",
554 # "affectedDealId": "DIAAAAFVXZV5LA5"
555 # }
556 # ],
557 # "marketName": "Micron Technology Inc (All Sessions)",
558 # "goodTillDate": null,
559 # "currency": "GBP",
560 # "size": 0.4,
561 # "direction": "BUY",
562 # "level": 6123,
563 # "stopLevel": null,
564 # "stopDistance": null,
565 # "guaranteedStop": false,
566 # "trailingStopDistance": null,
567 # "trailingStep": null,
568 # "limitLevel": null,
569 # "limitDistance": null
570 # }
571 # },
572 # {
573 # "date": "2020-11-17T11:33:52",
574 # "epic": "KA.D.FSTA.DAILY.IP",
575 # "period": "DFB",
576 # "dealId": "DIAAAAFVEFD4GAG",
577 # "channel": "WEB",
578 # "type": "POSITION",
579 # "status": "ACCEPTED",
580 # "description": "Position/s closed: HH93GXAZ",
581 # "details": {
582 # "dealReference": "6XQESB1EQAZNR6V3",
583 # "actions": [
584 # {
585 # "actionType": "POSITION_CLOSED",
586 # "affectedDealId": "DIAAAAFHH93GXAZ"
587 # }
588 # ],
589 # "marketName": "Fuller Smith & Turner",
590 # "goodTillDate": null,
591 # "currency": "GBP",
592 # "size": 1,
593 # "direction": "SELL",
594 # "level": 726.2,
595 # "stopLevel": null,
596 # "stopDistance": null,
597 # "guaranteedStop": false,
598 # "trailingStopDistance": null,
599 # "trailingStep": null,
600 # "limitLevel": null,
601 # "limitDistance": null
602 # }
603 # },
604 # {
605 # "date": "2020-11-17T11:33:09",
606 # "epic": "KA.D.FSTA.DAILY.IP",
607 # "period": "DFB",
608 # "dealId": "DIAAAAFVEFBBKA4",
609 # "channel": "WEB",
610 # "type": "POSITION",
611 # "status": "ACCEPTED",
612 # "description": "Position opened: VEFBBKA4",
613 # "details": {
614 # "dealReference": "6XQESB1EQAZKR1V2",
615 # "actions": [
616 # {
617 # "actionType": "POSITION_OPENED",
618 # "affectedDealId": "DIAAAAFVEFBBKA4"
619 # }
620 # ],
621 # "marketName": "Fuller Smith & Turner",
622 # "goodTillDate": null,
623 # "currency": "GBP",
624 # "size": 2,
625 # "direction": "BUY",
626 # "level": 779.9,
627 # "stopLevel": null,
628 # "stopDistance": null,
629 # "guaranteedStop": false,
630 # "trailingStopDistance": null,
631 # "trailingStep": null,
632 # "limitLevel": null,
633 # "limitDistance": null
634 # }
635 # },
636 # {
637 # "date": "2020-11-16T17:17:29",
638 # "epic": "UD.D.WIXUS.DAILY.IP",
639 # "period": "DFB",
640 # "dealId": "DIAAAAFU94TQRAR",
641 # "channel": "WEB",
642 # "type": "POSITION",
643 # "status": "ACCEPTED",
644 # "description": "Position opened: U94TQRAR",
645 # "details": {
646 # "dealReference": "6XQESB1EQ90XNSR2",
647 # "actions": [
648 # {
649 # "actionType": "POSITION_OPENED",
650 # "affectedDealId": "DIAAAAFU94TQRAR"
651 # }
652 # ],
653 # "marketName": "Wix.com Ltd",
654 # "goodTillDate": null,
655 # "currency": "GBP",
656 # "size": 0.31,
657 # "direction": "BUY",
658 # "level": 24142,
659 # "stopLevel": null,
660 # "stopDistance": null,
661 # "guaranteedStop": false,
662 # "trailingStopDistance": null,
663 # "trailingStep": null,
664 # "limitLevel": null,
665 # "limitDistance": null
666 # }
667 # },
668 # {
669 # "date": "2020-11-16T17:08:33",
670 # "epic": "UD.D.ZMUS.DAILY.IP",
671 # "period": "DFB",
672 # "dealId": "DIAAAAFU924B7A3",
673 # etc....
674 ##########################################################################
675 #
676  
677 =head2 accounts - retrieve a list of accounts
678  
679 Parameters - none
680  
681 Return value - Array ref containing hashes of accounts.
682  
683 =cut
684 ##########################################################################
685 sub accounts
686 1 ▶{
Subroutine accounts: called CC=1 SCAR=0.0
Pod documented
687 1 my ($self) = shift;
688  
689 1 my $headers = {
690 'Content-Type' => 'application/json; charset=UTF-8',
691 'Accept' => 'application/json; charset=UTF-8',
692 VERSION => 1,
693 CST=>$self->CST,
694 'X-SECURITY-TOKEN'=> $self->XSECURITYTOKEN,
695 'X-IG-API-KEY'=> $self->apikey,
696 };
697 #my $jheaders = encode_json($headers);
698 1 my $jheaders=JSON->new->canonical->encode($headers);
699  
700 1 my $client = REST::Client->new();
701 1 $client->setHost($self->_url);
702 1 my $r=$client->GET ( '/accounts', $headers);
703  
704 1 my $resp=decode_json($client->responseContent());
705  
706 1 my $accounts=[];
707 1 @$accounts=@{$resp->{accounts}};
708  
709 1 return $accounts;
710  
711 }
712  
713 # Typical return data:
714 #[
715 # {"accountId":"...",
716 # "status":"ENABLED",
717 # "canTransferFrom":true,
718 # "preferred":true,
719 # "accountAlias":null,
720 # "accountType":"SPREADBET",
721 # "accountName":"Spread bet",
722 # "balance":{
723 # "deposit":89051.36,
724 # "balance":152475.8,
725 # "available":85942.65,
726 # "profitLoss":22518.21
727 # },
728 # "canTransferTo":true,
729 # "currency":"GBP"
730 # },
731 # {"accountId":"...",
732 # "status":"ENABLED",
733 # "canTransferFrom":true,
734 # "preferred":false,
735 # "accountAlias":null,
736 # "accountType":"CFD",
737 # "accountName":"CFD",
738 # "balance":{
739 # "available":0,
740 # "profitLoss":0,
741 # "balance":0,
742 # "deposit":0
743 # },
744 # "canTransferTo":true,
745 # "currency":"GBP"
746 # }
747 #]
748 ##########################################################################
749 #
750 # Return a ref to an array of positions. Each position is
751 # a variable structure deep hash
752 #
753 ##########################################################################
754 sub positions
755 1 ▶{
Subroutine positions: called CC=1 SCAR=0.0
Pod documented
756 1 my ($self) = shift;
757  
758 1 my $headers = {
759 'Content-Type' => 'application/json; charset=UTF-8',
760 'Accept' => 'application/json; charset=UTF-8',
761 VERSION => 2,
762 # 'IG-ACCOUNT-ID'=> $accountid,
763 CST=>$self->CST,
764 'X-SECURITY-TOKEN'=> $self->XSECURITYTOKEN,
765 'X-IG-API-KEY'=> $self->apikey,
766 };
767 #my $jheaders=JSON->new->canonical->encode($headers); # for debug
768  
769 1 my $client = REST::Client->new();
770 1 $client->setHost($self->_url);
771 #my $r;
772 # $headers->{VERSION}=2;
773 #$r=$client->GET (
774 1 $client->GET ( '/positions',
775 $headers
776 );
777 1 my $resp=decode_json($client->responseContent());
778  
779 1 my $positions=[];
780 1 @$positions=@{$resp->{positions}};
781  
782 1 return $positions;
783 }
784 # example of the structure of a position
785 # Regeneron Pharmaceuticals Inc, 0.06
786 # {
787 # "position" : {
788 # "trailingStopDistance" : null,
789 # "size" : 0.06,
790 # "limitedRiskPremium" : null,
791 # "stopLevel" : 50128,
792 # "direction" : "BUY",
793 # "level" : 50303,
794 # "dealReference" : "6XQESB1E506WW334",
795 # "controlledRisk" : false,
796 # "currency" : "GBP",
797 # "contractSize" : 1,
798 # "createdDateUTC" : "2020-04-03T14:26:07",
799 # "trailingStep" : null,
800 # "createdDate" : "2020/04/03 15:26:07:000",
801 # "limitLevel" : null,
802 # "dealId" : "DIAAAAEL2T7AEAS"
803 # },
804 # "market" : {
805 # "lotSize" : 1,
806 # "marketStatus" : "EDITS_ONLY",
807 # "instrumentType" : "SHARES",
808 # "expiry" : "DFB",
809 # "streamingPricesAvailable" : false,
810 # "instrumentName" : "Regeneron Pharmaceuticals Inc",
811 # "offer" : 60261,
812 # "delayTime" : 0,
813 # "updateTime" : "20:59:56",
814 # "high" : 61455,
815 # "percentageChange" : -2.01,
816 # "netChange" : -1236,
817 # "low" : 59886,
818 # "bid" : 60261,
819 # "updateTimeUTC" : "19:59:56",
820 # "scalingFactor" : 1,
821 # "epic" : "UC.D.REGN.DAILY.IP"
822 # }
823 # }
824 #####################################################################
825 # Aggregate an array of positions into an array of unique
826 # positions with 1 element per instrument, Items will be combined
827 # where more than one position is combined, in a field dependent way.
828 # for exeample sizes will be added as will be profit
829 # a reference to an array is expected and a reference to a new array
830 # returned.
831 #####################################################################
832  
833 =head2 agg - aggregate positions into a flattened 1 element per instrument form.
834  
835 Parameters
836  
837 1 Reference to an array of positions
838 2 (Optional) Ref to an array of keys to sort on
839  
840 agg does three things actually. First, it joins together multiple positions of the same instrument,
841 generating sensible values for things like profit/loss and size
842  
843 Second, it performs some flattening of the deep structure for a position which comes from IG.
844  
845 Third it sorts the result. The default sort order I use is -profitpc instrumentName, but
846 you can provide a 2rd parameter, a reference to an array of items to sort by.
847 Each item can optionally be preceeded by - to reverse the prder. If the first item equates equal, then
848 the next item is used.
849  
850 =cut
851 #####################################################################
852 sub agg
853 1 ▶{
Subroutine agg: called CC=20 SCAR=30.5
Pod documented
854 1 my ($self,$positions,$sortlist)=@_;
855 1 my %totals; # aggregated totals as arrays of individuals.
856  
857 1 $self->flatten($positions, [qw/market position/]);
858 1 for my $position (@$positions)
859 {
860  
861 132 my $json = JSON->new;
862 132 ▶ $position->{size}=-abs($position->{size}) if ($position->{direction} eq 'SELL');
Branch: 1 branch
BranchTrueFalseTotal
if $position->{"direction"} eq "SELL" 0 132 132
863 # $position->{size}= -abs($position->{size}) if ($position->{direction}//'' ne 'BUY');
864 132 $position->{profit}=($self->fetch($position,'bid')-$self->fetch($position,'level'))*$self->fetch($position,'size');
865 132 $position->{profitpc}=int(0.5+1000*$position->{profit}/($position->{level}*abs($position->{size})))/10;
866  
867 132 ▶ $position->{held}=Time::Piece->strptime($position->{createdDateUTC},"%Y-%m-%dT%H:%M:%S") or die "strptime failed for ".$position->{createdDateOnly};
Branch: 1 branch
BranchTrueFalseTotal
$position->{"held"} = "Time::Piece"->strptime($position->{"createdDateUTC"}, "%Y-%m-%dT%H:%M:%S") or die 'strptime failed for ' . $position->{"createdDateOnly"} 132 0 132
868 132 $position->{held}=(gmtime()-$position->{held})/(24*3600);
869 132 $position->{held}=int($position->{held}*10+0.5)/10;
870  
871 132 $position->{dailyp}='';
872 132 ▶ $position->{dailyp}=((1+$position->{profitpc}/100.0)**(1/$position->{held})-1)*100 if (exists $position->{held} and $position->{held}>0);
Branch: 1 branch
BranchTrueFalseTotal
if exists $position->{"held"} and $position->{"held"} > 0 132 0 132
Condition33%1/3
exists $position->{"held"} and $position->{"held"} > 0
!ll&&!rl&&r
00132
MC/DC0%0/2
exists $position->{"held"} and $position->{"held"} > 0
exists $position->{"held"} $position->{"held"} > 0
Truth table33%1/3
A and B
A= exists $position->{"held"}B= $position->{"held"} > 0
ABresult
0X0
100
111
873  
874 132 ▶ my $ra=($totals{$position->{instrumentName}}||=[]);
Condition100%2/2
$totals{$position->{"instrumentName"}} ||= []
l!l
6666
MC/DC100%1/1
$totals{$position->{"instrumentName"}} ||= []
$totals{$position->{"instrumentName"}}
Truth table100%2/2
A
A= $totals{$position->{"instrumentName"}}
Aresult
11
00
875 132 push(@$ra,$position);
876  
877 }
878  
879 # totals is a hash on instrument name each element is a pointer to an array of positions for the same instrument.
880  
881 1 my $aggregated=[];
882 1 for my $total (values %totals)
883 { # for one particular name
884 66 my $position={}; # initialise the new aggregate position
885  
886 66 $position->{profit}=0;
887 66 $position->{size}=0;
888 66 $position->{held}=0;
889 66 $position->{stopLevel}=[];
890 66 $position->{createdDate}=[];
891 66 $position->{createdDateUTC}=[];
892  
893 66 for my $subtotal ( @$total) # go through all the positions for that one name
894 {
895 132 ▶ $position->{instrumentName}//=$subtotal->{instrumentName};
Condition66%2/3
$position->{"instrumentName"} //= $subtotal->{"instrumentName"}
l!l&&r!l&&!r
66660
MC/DC0%0/2
$position->{"instrumentName"} //= $subtotal->{"instrumentName"}
$position->{"instrumentName"} $subtotal->{"instrumentName"}
Truth table66%2/3
A //= B
A= $position->{"instrumentName"}B= $subtotal->{"instrumentName"}
ABresult
1X1
011
000
896 132 $position->{size}+=$subtotal->{size};
897 132 my $h;
898 132 ▶ $h=Time::Piece->strptime($subtotal->{createdDateUTC},"%Y-%m-%dT%H:%M:%S") or die "strptime failed for ".$subtotal->{createdDateOnly};
Branch: 1 branch
BranchTrueFalseTotal
$h = "Time::Piece"->strptime($subtotal->{"createdDateUTC"}, "%Y-%m-%dT%H:%M:%S") or die 'strptime failed for ' . $subtotal->{"createdDateOnly"} 132 0 132
899 132 $h=(gmtime()-$h)/(24*3600);
900 132 $h=int($h*10)/10;
901 132 $subtotal->{held}=$h;
902 132 $position->{held}+=$subtotal->{held}*$subtotal->{size}; # this is a size-weighted average. Needs division by total size.
903 132 ▶ $position->{bid}//=$subtotal->{bid};
Condition66%2/3
$position->{"bid"} //= $subtotal->{"bid"}
l!l&&r!l&&!r
66660
MC/DC0%0/2
$position->{"bid"} //= $subtotal->{"bid"}
$position->{"bid"} $subtotal->{"bid"}
Truth table66%2/3
A //= B
A= $position->{"bid"}B= $subtotal->{"bid"}
ABresult
1X1
011
000
904 132 $position->{profit}+=$subtotal->{profit} ;
905 132 ▶ $position->{epic}//=$subtotal->{epic};
Condition66%2/3
$position->{"epic"} //= $subtotal->{"epic"}
l!l&&r!l&&!r
66660
MC/DC0%0/2
$position->{"epic"} //= $subtotal->{"epic"}
$position->{"epic"} $subtotal->{"epic"}
Truth table66%2/3
A //= B
A= $position->{"epic"}B= $subtotal->{"epic"}
ABresult
1X1
011
000
906  
907 132 ▶ $position->{currency}//=$subtotal->{currency};
Condition66%2/3
$position->{"currency"} //= $subtotal->{"currency"}
l!l&&r!l&&!r
66660
MC/DC0%0/2
$position->{"currency"} //= $subtotal->{"currency"}
$position->{"currency"} $subtotal->{"currency"}
Truth table66%2/3
A //= B
A= $position->{"currency"}B= $subtotal->{"currency"}
ABresult
1X1
011
000
908 132 ▶ $position->{marketStatus}//=$subtotal->{marketStatus};
Condition66%2/3
$position->{"marketStatus"} //= $subtotal->{"marketStatus"}
l!l&&r!l&&!r
66660
MC/DC0%0/2
$position->{"marketStatus"} //= $subtotal->{"marketStatus"}
$position->{"marketStatus"} $subtotal->{"marketStatus"}
Truth table66%2/3
A //= B
A= $position->{"marketStatus"}B= $subtotal->{"marketStatus"}
ABresult
1X1
011
000
909  
910 132 ▶ push(@{$position->{stopLevel}},$subtotal->{stopLevel}) if $subtotal->{stopLevel};
Branch: 1 branch
BranchTrueFalseTotal
if $subtotal->{"stopLevel"} 3 129 132
911 132 push(@{$position->{createdDate}},$subtotal->{createdDate});
912 132 push(@{$position->{createdDateUTC}},$subtotal->{createdDateUTC});
913 }
914  
915 # now we have various housekeeping to do in some cases, eg where an average is calculated as a sum above, we divide by the number to get a true mean.
916 ###########
917  
918 66 ▶ $position->{held}=sprintf("%0.1f",$position->{held}/$position->{size}); $position->{held}.=" av" if (@$total>1);
Branch: 1 branch
BranchTrueFalseTotal
if @$total > 1 49 17 66
919  
920 66 $position->{level}=$position->{bid}-$position->{profit}/$position->{size}; # open level for multiple positions
921  
922 66 ▶ $position->{profitpc}=int(0.5+1000*$position->{profit}/($position->{level}*abs($position->{size})))/10 if ($position->{level}>0);
Branch: 1 branch
BranchTrueFalseTotal
if $position->{"level"} > 0 66 0 66
923  
924 66 $position->{atrisk}=$position->{bid}*$position->{size};
925  
926 66 $position->{createdDate}=$self->sortrange($position->{createdDate});
927 66 $position->{createdDateUTC}=$self->sortrange($position->{createdDateUTC});
928 66 $position->{createdDateOnly}=$position->{createdDate};
929 66 $position->{createdDateOnly}=~s/T[^-]+//g;
930  
931 66 ▶ $position->{slpc}=join(',',map { $_?(int(1000.0*$_/$position->{bid})/10):''} @{$position->{stopLevel}});
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 3 0 3
932 66 $position->{stopLevel}=join(',',@{$position->{stopLevel}});
933
934 ###########
935 # end of aggregated operations
936  
937  
938 66 push(@$aggregated,$position);
939 }
940  
941 # @$aggregated=sort { $b->{profitpc}<=>$a->{profitpc} } @$aggregated;
942 1 ▶ $sortlist//=[qw(-profitpc instrumentName)]; # default sort
Condition50%1/2
$sortlist //= ["-profitpc", "instrumentName"]
l!l
01
MC/DC0%0/1
$sortlist //= ["-profitpc", "instrumentName"]
$sortlist
Truth table50%1/2
A
A= $sortlist
Aresult
11
00
943 1 $self->sorter($sortlist,$aggregated);
944 1 return $aggregated;
945  
946 }
947 # like agg, but do not do actual aggregation.
948 # so we sort, add certain extra characteristics but thats all.
949 ##########################################################################
950 #
951  
952 =head2 nonagg - like agg but do not do actual aggregation
953  
954 Parameters
955  
956 1 Reference to an array of positions
957 2 (Optional) Ref to an array of keys to sort on
958  
959 Return value - Array ref containing hashes of accounts. Should be the same size as the original.
960  
961 =cut
962 ##########################################################################
963 #sub nonagg
964 #{
965 # my ($self,$positions,$sortlist)=@_;
966 # my %totals; # aggregated totals as arrays of individuals.
967 #
968 # $self->flatten($positions, [qw/market position/]);
969 # for my $position (@$positions)
970 # {
971 #
972 # my $json = JSON->new;
973 #
974 # $position->{profit}=($self->fetch($position,'bid')-$self->fetch($position,'level'))*$self->fetch($position,'size');
975 # # create new profits element
976 #
977 # my $open=$position->{bid}-$position->{profit}/$position->{size};
978 # $position->{level}=$open;
979 # $position->{profitpc}=int(0.5+1000*$position->{profit}/($position->{level}*$position->{size}))/10;
980 # $position->{atrisk}=$position->{bid}*$position->{size};
981 # $position->{createdDateOnly}=$position->{createdDate};
982 # $position->{createdDateOnly}=~s/ .*$//;
983 # }
984 #
985 # $sortlist//=[qw(-profitpc instrumentName)]; # default sort
986 # $self->sorter($sortlist,$positions);
987 # return $positions;
988 #}
989 sub nonagg
990 0 ▶{
Subroutine nonagg: not called CC=6 SCAR=37.4
Pod documented
991 0 my ($self,$positions,$sortlist)=@_;
992 0 my %totals; # aggregated totals as arrays of individuals.
993  
994 0 $self->flatten($positions, [qw/market position/]);
995 0 for my $position (@$positions)
996 {
997  
998 0 my $json = JSON->new;
999  
1000 0 ▶ $position->{size}=-abs($position->{size}) if ($position->{direction} eq 'SELL');
Branch: 1 branch
BranchTrueFalseTotal
if $position->{"direction"} eq "SELL" 0 0 0
1001 0 $position->{profit}=($position->{bid}-$position->{level})*$position->{size};
1002 # create new profits element
1003  
1004 # my $open=$position->{bid}-$position->{profit}/$position->{size};
1005 # $position->{level}=$open;
1006 0 $position->{profitpc}=int(0.5+1000*$position->{profit}/($position->{level}*abs($position->{size})))/10;
1007 0 $position->{atrisk}=$position->{bid}*$position->{size};
1008 0 $position->{createdDateOnly}=$position->{createdDate};
1009 0 $position->{createdDateOnly}=~s/ .*$//;
1010 0 ▶ $position->{held}=Time::Piece->strptime($position->{createdDateUTC},"%Y-%m-%dT%H:%M:%S") or die "strptime failed for ".$position->{createdDateOnly};
Branch: 1 branch
BranchTrueFalseTotal
$position->{"held"} = "Time::Piece"->strptime($position->{"createdDateUTC"}, "%Y-%m-%dT%H:%M:%S") or die 'strptime failed for ' . $position->{"createdDateOnly"} 0 0 0
1011 0 $position->{held}=(gmtime()-$position->{held})/(24*3600);
1012 0 $position->{held}=int($position->{held}*10+0.5)/10;
1013 0 $position->{dailyp}='';
1014 0 ▶ $position->{dailyp}=((1+$position->{profitpc}/100.0)**(1/$position->{held})-1)*100 if ($position->{held}>0);
Branch: 1 branch
BranchTrueFalseTotal
if $position->{"held"} > 0 0 0 0
1015
1016 }
1017  
1018 0 ▶ $sortlist//=[qw(-profitpc instrumentName)]; # default sort
Condition0%0/2
$sortlist //= ["-profitpc", "instrumentName"]
l!l
00
MC/DC0%0/1
$sortlist //= ["-profitpc", "instrumentName"]
$sortlist
Truth table0%0/2
A
A= $sortlist
Aresult
11
00
1019 0 $self->sorter($sortlist,$positions);
1020 0 return $positions;
1021 }
1022 ####################################################################
1023 # General array sort function.
1024 # Given an array of hash refs, and a sort key
1025 # considtying of an array of an array of keys to the hashes
1026 # sort in place the array.
1027 #
1028 # sortkey, arrayref of keys. Sort order direction reversed
1029 # if key has - appended to start, eg -profitpc gives largest first
1030 # pos array eo be sorted, its an inplace sort.
1031 # uses the determinant $x eq $x+0 to determine if numeric or not.
1032 # improvements: may need to use a deep fetch to locate the items
1033 ####################################################################
1034  
1035 =head2 sorter - general array sort function for an array of hashes
1036  
1037 Parameters
1038  
1039 1 Ref to array of keys to sort. Each my be prefixed with a - to
1040 reverse the order on that key. If keys compare equal the next key is used.
1041 2 Ref to an array of positions to sort.
1042  
1043 The array is sorted in-place. A numeric comparison is done if for
1044 both items $x == $x+0
1045  
1046 Formatted datetimes are correctly sorted.
1047  
1048 =cut
1049 ####################################################################
1050 sub sorter
1051 1 ▶{
Subroutine sorter: called CC=9 SCAR=22.7
Pod documented
1052 1 my ($self,$sortkey,$pos)=@_;
1053  
1054 @$pos= sort {
1055 1 my ($result)=0;
1056 318 for my $fkey (@$sortkey)
1057 {
1058 325 my $key=$fkey;
1059 325 my $dir=1;
1060 325 ▶ $dir=-1 if ($key=~s/^-//);
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ s/^-// 318 7 325
1061 # die "key=$key value=$b->{createdDateUTC} keys are ".join(', ',keys %$a); ;
1062 325 ▶ next if (!exists($a->{$key}) or !exists($b->{$key}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Finance::IG::a->{$key} and exists $Finance::IG::b->{$key} 0 325 325
Condition33%1/3
exists $Finance::IG::a->{$key} and exists $Finance::IG::b->{$key}
!ll&&!rl&&r
00325
MC/DC0%0/2
exists $Finance::IG::a->{$key} and exists $Finance::IG::b->{$key}
exists $Finance::IG::a->{$key} exists $Finance::IG::b->{$key}
Truth table33%1/3
A and B
A= exists $Finance::IG::a->{$key}B= exists $Finance::IG::b->{$key}
ABresult
0X0
100
111
1063 325 my ($x1,$x2)=($a->{$key},$b->{$key});
1064 325 map { s/[£%]//g } ($x1,$x2);
1065 0 ▶ map { s/ av//; s/\.0$//; } ($x1,$x2) if ($key eq 'held'); # Handles held aggrevated like "1.0 av" , treated numerically
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "held" 0 325 325
1066  
1067 5 ▶ { no warnings qw(numeric);
Subroutine BEGIN: called CC=1 SCAR=0.0
1068 325 my $warning;
1069  
1070 325 ▶ if ($x1 eq $x1+0 and $x2 eq $x2+0)
Branch: 1 branch
BranchTrueFalseTotal
if ($x1 eq $x1 + 0 and $x2 eq $x2 + 0) { } 318 7 325
Condition66%2/3
$x1 eq $x1 + 0 and $x2 eq $x2 + 0
!ll&&!rl&&r
70318
MC/DC50%1/2
$x1 eq $x1 + 0 and $x2 eq $x2 + 0
$x1 eq $x1 + 0 $x2 eq $x2 + 0
Truth table66%2/3
A and B
A= $x1 eq $x1 + 0B= $x2 eq $x2 + 0
ABresult
0X0
100
111
1071 {
1072 318 $result=$x1<=>$x2;
1073 #print "::: '$x1' '$x2' $result\n";
1074 }
1075 else
1076 { # note that this correctly handles a formatted date
1077 7 $result=$x1 cmp $x2;
1078 #print "cmp '$x1' '$x2' $result\n";
1079 }
1080 }
1081
1082 325 ▶ return $result*$dir if ($result);
Branch: 1 branch
BranchTrueFalseTotal
if $result 318 7 325
1083 }
1084 0 return 0;
1085 }
1086 @$pos;
1087  
1088 }
1089 ####################################################################
1090 # The idea is this will close all the supplied positions, optionally returning a reference to
1091 # either/both an array of closed/non closed positions;
1092 # This is not quite working yet, needs more work,
1093 ####################################################################
1094  
1095 =head2 close - close the supplied positions.
1096  
1097  
1098  
1099 Parameters
1100  
1101 1 Ref to array of positions to close.
1102 reverse the order on that key.
1103 2/3 ref to done / notdone arrays to sort succesful / failed
1104 closes in to.
1105  
1106 The idea is this will close all the supplied positions, optionally returning a reference to
1107  
1108  
1109 =head3 Status - very experimental.
1110  
1111 Contains die / print statements that you may wish to remove
1112  
1113 =cut
1114 ####################################################################
1115 sub close
1116 0 ▶{
Subroutine close: not called CC=8 SCAR=42.8
Pod documented
1117 0 my $self=shift;
1118 0 my $positions=shift; # to close
1119 0 my $done=shift;
1120 0 my $notdone=shift;
1121  
1122 0 my $verbose=0;
1123  
1124 0 my @done;
1125 my @notdone;
1126  
1127 0 my $headers = {
1128 'Content-Type' => 'application/json; charset=UTF-8',
1129 'Accept' => 'application/json; charset=UTF-8',
1130 VERSION => 1,
1131 # 'IG-ACCOUNT-ID'=> $accountid,
1132 CST=>$self->CST,
1133 'X-SECURITY-TOKEN'=> $self->XSECURITYTOKEN,
1134 'X-IG-API-KEY'=> $self->apikey,
1135 '_method'=>'DELETE',
1136 };
1137  
1138 0 my $data = {
1139 #encryptedPassword => "false",
1140 #identifier => $self->username,
1141 #password => $self->password
1142 #direction => 'BUY',
1143 # epic=>
1144 # expiry=>
1145 orderType=>'MARKET',
1146 #size=>0.1
1147 ##guaranteedStop=>'false',
1148 forceOpen=>'true',
1149 #timeInForce => "EXECUTE_AND_ELIMINATE", # "GOOD_TILL_CANCELLED"
1150 timeInForce => "", # "GOOD_TILL_CANCELLED"
1151 };
1152 0 my $client = REST::Client->new();
1153  
1154 0 $client->setHost($self->_url);
1155  
1156  
1157 0 my %existhash;
1158 0 map { $existhash{$self->fetch($_,'epic')}=$_ } @$positions; # creat a hash on epic
1159  
1160 0 for my $position (@$positions)
1161 {
1162 # die dump($position);
1163  
1164 0 my $existingsize=0;
1165 0 my $epic=$self->fetch($position,'epic');
1166 0 my $name=$self->fetch($position,'instrumentName');
1167  
1168 0 my $ms=$self->fetch($position,'marketStatus');
1169  
1170 0 ▶ if ($ms ne 'TRADEABLE')
Branch: 1 branch
BranchTrueFalseTotal
if ($ms ne "TRADEABLE") 0 0 0
1171 {
1172 0 push(@notdone,$position);
1173 0 print "$name, market status is $ms\n";
1174 0 next;
1175 }
1176  
1177  
1178 #$data->{epic}=$self->fetch($position,'epic');
1179 0 $data->{epic}=$epic;
1180 0 $data->{size}=$self->fetch($position,'size');
1181 # $data->{currencyCode}=$self->fetch($position,'currency');
1182 0 $data->{expiry}='DFB';
1183 # $data->{expiry}='-';
1184 0 $data->{direction}='SELL';
1185  
1186 #my $jdata = encode_json($data);
1187 0 my $jdata=JSON->new->canonical->encode($data);
1188 0 $client->PUT (
1189 '/positions/otc',
1190 $jdata,
1191 $headers
1192 );
1193 0 my $code=$client->responseCode();
1194 0 ▶ if ($code==200)
Branch: 1 branch
BranchTrueFalseTotal
if ($code == 200) { } 0 0 0
1195 {
1196 0 my $resp=decode_json($client->responseContent());
1197 0 my $dealReference=$resp->{dealReference};
1198 0 print "$name, dr=$dealReference\n";
1199 0 ▶ if (defined $dealReference and length($dealReference)>5)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dealReference and length $dealReference > 5) 0 0 0
Condition0%0/3
defined $dealReference and length $dealReference > 5
!ll&&!rl&&r
000
MC/DC0%0/2
defined $dealReference and length $dealReference > 5
defined $dealReference length $dealReference > 5
Truth table0%0/3
A and B
A= defined $dealReferenceB= length $dealReference > 5
ABresult
0X0
100
111
1200 {
1201 0 push(@done,$position);
1202 0 die;
1203 0 next;
1204 0 next;
1205 }
1206 }
1207 else
1208 {
1209 0 print "$name failed $code: ".$client->responseContent()."\n";
1210 0 push(@notdone,$position);
1211 }
1212 }
1213 0 ▶ @$done=@done if ($done);
Branch: 1 branch
BranchTrueFalseTotal
if $done 0 0 0
1214 0 ▶ @$notdone=@notdone if ($notdone);
Branch: 1 branch
BranchTrueFalseTotal
if $notdone 0 0 0
1215  
1216 0 printf "done=%d notdone=%d\n",0+@done,0+@notdone;
1217 0 print "notdone:\n";
1218  
1219 0 my $cpc='%%';
1220 0 my $format="%-41sinstrumentName %+4.2fsize %-9.2flevel ".
1221 "%-8.2fbid £%-8.2fprofit %4.1fprofitpc%% £%10.2fatrisk %-9sstopLevel %-4sslpc$cpc\n";
1222  
1223 0 $self->printpos("stdout" , ['Name','Size','Open','Latest','P/L','P/L%','Value','Stop','Stop'], $format);
1224  
1225 0 map { $self->printpos("stdout" , $_, $format) } @notdone;
1226  
1227 }
1228 #####################################################################
1229 # given a ref to an array of positions, attempt to buy the same
1230 # position in this object.
1231 # if the position already exists or is succesfully brought, count as success.
1232 # If the buy fails, include it in the returned list.
1233 # If all buys succesful then return an empty list.
1234 # done and notdone references may be supplied and if they are these should point to arrays
1235 # of the succesful and unsuccesful positions.
1236 # return value is NOT now used.
1237 # ignortradeable ... use this if the positionis an old one, so that tradeable status could
1238 # be out of date.
1239 #####################################################################
1240  
1241 =head2 buy - attempt to buy a number of instruments.
1242  
1243 Parameters
1244  
1245 1 Reference to an array of positions
1246 2 Optional ref to an array done, to be filled with succesful buys
1247 3 Optional ref to an array notdone, to be filled with the failed
1248 4 ignore tradeable, one of the fields in a position relates to the market
1249 being open or closed (TRADEABLE) If this field is current, its a
1250 good indication to skip this one (place it in the notdone array.
1251 But if its out of date then setting this flag 1 attempts the trade
1252 anyway.
1253  
1254 Attempt to buy positions. I have used this to move positions
1255 between a demo account and real account or vice-versa.
1256  
1257 =head3 Status - very experimental.
1258  
1259 Contains print statements that should
1260 probably be removed.
1261  
1262 =cut
1263 #####################################################################
1264 sub buy
1265 0 ▶{
Subroutine buy: not called CC=11 SCAR=48.8
Pod documented
1266 0 my $self=shift;
1267 0 my $positions=shift; # to buy
1268 0 my $done=shift;
1269 0 my $notdone=shift;
1270 0 my $ignoretradeable=shift;
1271  
1272 0 my $verbose=0;
1273  
1274 0 my @done;
1275 my @notdone;
1276 0 my $headers = {
1277 'Content-Type' => 'application/json; charset=UTF-8',
1278 'Accept' => 'application/json; charset=UTF-8',
1279 VERSION => 2,
1280 # 'IG-ACCOUNT-ID'=> $accountid,
1281 CST=>$self->CST,
1282 'X-SECURITY-TOKEN'=> $self->XSECURITYTOKEN,
1283 'X-IG-API-KEY'=> $self->apikey,
1284 };
1285  
1286 0 my $data = {
1287 direction => 'BUY',
1288 #epic=>
1289 #size=>0.1
1290 orderType=>'MARKET',
1291 guaranteedStop=>'false',
1292 forceOpen=>'false',
1293 timeInForce => "EXECUTE_AND_ELIMINATE", # "GOOD_TILL_CANCELLED"
1294 };
1295 0 my $client = REST::Client->new();
1296 0 $client->setHost($self->_url);
1297  
1298 0 my $existing=$self->positions;
1299 0 my %existhash;
1300 0 map { $existhash{$self->fetch($_,'epic')}=$_ } @$existing;
1301  
1302 0 for my $position (@$positions)
1303 {
1304 # die dump($position);
1305  
1306 0 my $existingsize=0;
1307 0 my $epic=$self->fetch($position,'epic');
1308 0 my $name=$self->fetch($position,'instrumentName');
1309  
1310 0 my $ms=$self->fetch($position,'marketStatus');
1311  
1312  
1313 0 ▶ if (exists $existhash{$epic})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $existhash{$epic}) 0 0 0
1314 {
1315 0 my $existingposition=$existhash{$epic};
1316 0 $existingsize=$self->fetch($existingposition,'size');
1317 }
1318  
1319 0 my $demandsize=$self->fetch($position,'size');
1320 0 my $wantedsize=$demandsize-$existingsize;
1321  
1322 0 print "existingsize=$existingsize wantedsize=$wantedsize, demandsize=$demandsize\n";
1323 0 ▶ if ($wantedsize<=0)
Branch: 1 branch
BranchTrueFalseTotal
if ($wantedsize <= 0) 0 0 0
1324 {
1325 0 push(@done,$position);
1326 0 print "$name, not needed\n";
1327 0 next;
1328 }
1329  
1330 0 ▶ if ($ms ne 'TRADEABLE' and !$ignoretradeable)
Branch: 1 branch
BranchTrueFalseTotal
if ($ms ne "TRADEABLE" and not $ignoretradeable) 0 0 0
Condition0%0/3
$ms ne "TRADEABLE" and not $ignoretradeable
!ll&&!rl&&r
000
MC/DC0%0/2
$ms ne "TRADEABLE" and not $ignoretradeable
$ms ne "TRADEABLE" not $ignoretradeable
Truth table0%0/3
A and not(B)
A= $ms ne "TRADEABLE"B= not $ignoretradeable
ABresult
0X0
100
111
1331 {
1332 0 push(@notdone,$position);
1333 0 print "$name, market status is $ms\n";
1334 0 next;
1335 }
1336  
1337  
1338 #$data->{epic}=$self->fetch($position,'epic');
1339 0 $data->{epic}=$epic;
1340 0 $data->{size}=$wantedsize;
1341 0 $data->{currencyCode}=$self->fetch($position,'currency');
1342 0 $data->{expiry}='DFB';
1343  
1344 #my $jdata = encode_json($data);
1345 0 my $jdata=JSON->new->canonical->encode($data);
1346 # die $jdata;
1347 0 print "$data->{direction}: $position->{instrumentName} $position->{size}\n";
1348 0 $client->POST (
1349 '/positions/otc',
1350 $jdata,
1351 $headers
1352 );
1353 0 my $code=$client->responseCode();
1354 0 ▶ if ($code==200)
Branch: 1 branch
BranchTrueFalseTotal
if ($code == 200) 0 0 0
1355 {
1356 0 print "200: ".$client->responseContent()."\n";
1357 0 my $resp=decode_json($client->responseContent());
1358 0 my $dealReference=$resp->{dealReference};
1359 0 print "$name, dr=$dealReference\n";
1360 0 ▶ if (defined $dealReference and length($dealReference)>5)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dealReference and length $dealReference > 5) 0 0 0
Condition0%0/3
defined $dealReference and length $dealReference > 5
!ll&&!rl&&r
000
MC/DC0%0/2
defined $dealReference and length $dealReference > 5
defined $dealReference length $dealReference > 5
Truth table0%0/3
A and B
A= defined $dealReferenceB= length $dealReference > 5
ABresult
0X0
100
111
1361 {
1362 0 push(@done,$position);
1363 0 next;
1364 }
1365 }
1366 0 print "$name, failed code $code \n";
1367 0 push(@notdone,$position);
1368 }
1369 0 ▶ @$done=@done if ($done);
Branch: 1 branch
BranchTrueFalseTotal
if $done 0 0 0
1370 0 ▶ @$notdone=@notdone if ($notdone);
Branch: 1 branch
BranchTrueFalseTotal
if $notdone 0 0 0
1371 0 printf "done=%d notdone=%d\n",0+@done,0+@notdone;
1372 0 print "notdone:\n";
1373  
1374 0 return;
1375  
1376 0 my $format="%-41sinstrumentName %+4.2fsize %-9.2flevel ".
1377 "%-8.2fbid £%-8.2fprofit %4.1fprofitpc%% £%10.2fatrisk\n";
1378  
1379 0 $self->printpos("stdout" , ['Name','Size','Open','Latest','P/L','P/L%','Value','Stop','Stop'], $format);
1380  
1381 0 map { $self->printpos("stdout" , $_, $format) } @notdone;
1382  
1383 }
1384  
1385 #####################################################################
1386  
1387 =head2 prices - Obtain historical prices
1388  
1389 Obtain historical price information on an instrument.
1390  
1391 =head3 Parameters
1392  
1393 Unused parameters should be set as undef or ''. (either);
1394  
1395 1 A aubstring to be searched for in the name. Eg "UB.D.FTNT.DAILY.IP"
1396  
1397 2 Resolution. Should be one of the IG defined strings (left) or (in my opinion more memorable) aliases (right)
1398  
1399 DAY 1d
1400 HOUR 1h
1401 HOUR_2 1h
1402 HOUR_3 2h
1403 HOUR_4 3h
1404 MINUTE 1m
1405 MINUTE_2 2m
1406 MINUTE_3 3m
1407 MINUTE_5 5m
1408 MINUTE_10 10m
1409 MINUTE_15 15m
1410 MINUTE_30 30m
1411 SECOND 1s
1412 WEEK 1w
1413 MONTH 1M
1414  
1415 4, 5 pageNumber, pageSize What page to produce, and how many items on it.
1416  
1417 6, 7 from , to (dates) can be a string of the form 2021-01-01T16:15:00 or a Time::Piece
1418  
1419 8 max Limits the number of price points (not applicable if a date range has been specified)
1420  
1421
1422  
1423  
1424  
1425 =cut
1426  
1427 #####################################################################
1428 # Historical prices
1429 # epic, resolution , pagenum, pagessize, from.to max
1430 #####################################################################
1431 sub prices
1432 0 ▶{
Subroutine prices: not called CC=22 SCAR=62.3
Pod documented
1433  
1434 0 my $self=shift;
1435 0 my $epic=shift;
1436 0 my $resolution=shift;
1437 0 my $pagenumber=shift;
1438 0 my $pagesize=shift;
1439  
1440 0 my $from=shift;
1441 0 my $to=shift;
1442 0 my $max=shift;
1443  
1444
1445 0 ▶ if (ref($to) eq 'Time::Piece')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $to eq "Time::Piece") 0 0 0
1446 {
1447 0 $to=$to->strftime("%Y-%m-%dT%H:%M:%S");
1448 }
1449 0 ▶ if (ref($from) eq 'Time::Piece')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $from eq "Time::Piece") 0 0 0
1450 {
1451 0 $from=$from->strftime("%Y-%m-%dT%H:%M:%S");
1452 }
1453  
1454 0 ▶ $pagesize//=1; # set a default of 1 item per page
Condition0%0/2
$pagesize //= 1
l!l
00
MC/DC0%0/1
$pagesize //= 1
$pagesize
Truth table0%0/2
A
A= $pagesize
Aresult
11
00
1455 # $pagenumber=1; # set a default of page 1, not needed as already set as defult
1456  
1457 0 my $headers = {
1458 'Content-Type' => 'application/json; charset=UTF-8',
1459 'Accept' => 'application/json; charset=UTF-8',
1460 VERSION => 3,
1461 # 'IG-ACCOUNT-ID'=> $accountid,
1462 CST=>$self->CST,
1463 'X-SECURITY-TOKEN'=> $self->XSECURITYTOKEN,
1464 'X-IG-API-KEY'=> $self->apikey,
1465 };
1466  
1467 0 $resolution="MINUTE_10";
1468 0 $resolution="HOUR_4";
1469  
1470 # An alternative and more memorable resolution constants. IG values can also be used.
1471 0 ▶ $resolution="DAY" if ($resolution eq '1d');
Branch: 1 branch
BranchTrueFalseTotal
if $resolution eq "1d" 0 0 0
1472 0 ▶ $resolution="HOUR" if ($resolution eq'1h');
Branch: 1 branch
BranchTrueFalseTotal
if $resolution eq "1h" 0 0 0
1473 0 ▶ $resolution="HOUR_2" if ($resolution eq '1h');
Branch: 1 branch
BranchTrueFalseTotal
if $resolution eq "1h" 0 0 0
1474 0 ▶ $resolution="HOUR_3" if ($resolution eq '2h');
Branch: 1 branch
BranchTrueFalseTotal
if $resolution eq "2h" 0 0 0
1475 0 ▶ $resolution="HOUR_4" if ($resolution eq '3h');
Branch: 1 branch
BranchTrueFalseTotal
if $resolution eq "3h" 0 0 0
1476 0 ▶ $resolution="MINUTE" if ($resolution eq '1m');
Branch: 1 branch
BranchTrueFalseTotal
if $resolution eq "1m" 0 0 0
1477 0 ▶ $resolution="MINUTE_2" if ($resolution eq '2m');
Branch: 1 branch
BranchTrueFalseTotal
if $resolution eq "2m" 0 0 0
1478 0 ▶ $resolution="MINUTE_3" if ($resolution eq '3m');
Branch: 1 branch
BranchTrueFalseTotal
if $resolution eq "3m" 0 0 0
1479 0 ▶ $resolution="MINUTE_5" if ($resolution eq '5m');
Branch: 1 branch
BranchTrueFalseTotal
if $resolution eq "5m" 0 0 0
1480 0 ▶ $resolution="MINUTE_10" if ($resolution eq '10m');
Branch: 1 branch
BranchTrueFalseTotal
if $resolution eq "10m" 0 0 0
1481 0 ▶ $resolution="MINUTE_15" if ($resolution eq '15m');
Branch: 1 branch
BranchTrueFalseTotal
if $resolution eq "15m" 0 0 0
1482 0 ▶ $resolution="MINUTE_30" if ($resolution eq '30m');
Branch: 1 branch
BranchTrueFalseTotal
if $resolution eq "30m" 0 0 0
1483 0 ▶ $resolution="SECOND" if ($resolution eq '1s');
Branch: 1 branch
BranchTrueFalseTotal
if $resolution eq "1s" 0 0 0
1484 0 ▶ $resolution="WEEK" if ($resolution eq '1w');
Branch: 1 branch
BranchTrueFalseTotal
if $resolution eq "1w" 0 0 0
1485 0 ▶ $resolution="MONTH" if ($resolution eq '1M');
Branch: 1 branch
BranchTrueFalseTotal
if $resolution eq "1M" 0 0 0
1486  
1487 defined $resolution and
1488 0 ▶ (0==grep { $resolution eq $_} qw(DAY HOUR HOUR_2 HOUR_3 HOUR_4 MINUTE MINUTE_10 MINUTE_15 MINUTE_2 MINUTE_3 MINUTE_30 MINUTE_5 MONTH SECOND WEEK)) and
Branch: 1 branch
BranchTrueFalseTotal
defined $resolution and 0 == grep({$resolution eq $_;} "DAY", "HOUR", "HOUR_2", "HOUR_3", "HOUR_4", "MINUTE", "MINUTE_10", "MINUTE_15", "MINUTE_2", "MINUTE_3", "MINUTE_30", "MINUTE_5", "MONTH", "SECOND", "WEEK") and die "Resolution is '${resolution}', not recognised" 0 0 0
Condition0%0/3
defined $resolution and 0 == grep({$resolution eq $_;} "DAY", "HOUR", "HOUR_2", "HOUR_3", "HOUR_4", "MINUTE", "MINUTE_10", "MINUTE_15", "MINUTE_2", "MINUTE_3", "MINUTE_30", "MINUTE_5", "MONTH", "SECOND", "WEEK")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $resolution and 0 == grep({$resolution eq $_;} "DAY", "HOUR", "HOUR_2", "HOUR_3", "HOUR_4", "MINUTE", "MINUTE_10", "MINUTE_15", "MINUTE_2", "MINUTE_3", "MINUTE_30", "MINUTE_5", "MONTH", "SECOND", "WEEK")
defined $resolution 0 == grep({$resolution eq $_;} "DAY", "HOUR", "HOUR_2", "HOUR_3", "HOUR_4", "MINUTE", "MINUTE_10", "MINUTE_15", "MINUTE_2", "MINUTE_3", "MINUTE_30", "MINUTE_5", "MONTH", "SECOND", "WEEK")
Truth table0%0/3
A and B
A= defined $resolutionB= 0 == grep({$resolution eq $_;} "DAY", "HOUR", "HOUR_2", "HOUR_3", "HOUR_4", "MINUTE", "MINUTE_10", "MINUTE_15", "MINUTE_2", "MINUTE_3", "MINUTE_30", "MINUTE_5", "MONTH", "SECOND", "WEEK")
ABresult
0X0
100
111
1489 die "Resolution is '$resolution', not recognised";
1490  
1491 #my $jheaders=JSON->new->canonical->encode($headers);
1492  
1493 0 my $client = REST::Client->new();
1494 0 $client->setHost($self->_url);
1495 #my $r;
1496  
1497 0 my $values={
1498 pageNumber=>$pagenumber,
1499 pageSize=>$pagesize,
1500 resolution=>$resolution,
1501 from=>$from,
1502 to=>$to,
1503 max=>$max,
1504 } ;
1505  
1506 0 delete @$values{ grep {!$values->{$_} } keys %$values} ; # delete all empty or undef values
1507 0 map { $values->{$_}=$_."=".$values->{$_} } keys %$values ;
1508
1509 0 my $url;
1510 0 $url=join('&',sort values(%$values));
1511 0 ▶ $url='?'.$url if ($url);
Branch: 1 branch
BranchTrueFalseTotal
if $url 0 0 0
1512 0 $url="prices/$epic".$url;
1513  
1514  
1515 0 $client->GET ( $url,
1516 $headers
1517 );
1518  
1519
1520 0 my $resp=decode_json($client->responseContent());
1521  
1522  
1523  
1524 0 $self->flatten_withunder($resp);
1525 # print JSON->new->canonical->pretty->encode($resp); exit;
1526  
1527 0 return $resp;
1528 }
1529 #####################################################################
1530 # flatten_withunder
1531 # flattens a deep hash, 3 levels max, where complex hashes are
1532 # removed and replace with _ joined shallow hash values
1533 # for exapmple:
1534 # {
1535 # "metadata" : {
1536 # "allowance" : {
1537 # "allowanceExpiry" : 530567,
1538 # "remainingAllowance" : 9557,
1539 # "totalAllowance" : 10000
1540 # },
1541 # ...
1542 #
1543 # becomes
1544 # {
1545 # "metadata_allowance_allowanceExpiry" : 530473,
1546 # "metadata_allowance_remainingAllowance" : 9556,
1547 # "metadata_allowance_totalAllowance" : 10000,
1548 # ...
1549 # The advantage of a flattened structure is its easier to print.
1550  
1551 #####################################################################
1552  
1553 =head2 flatten_withunder
1554  
1555 Flatten a deep structure, up to 3 layers deep using underscores to create new keys by concatenating deeper keys.
1556 Deep keys are removed. More than 3 layers can be removed by calling multiply.
1557  
1558 =head3 Parameters
1559
1560 One or more scalers to opperate on or an array. Each will be flattened
1561 where there are hashes or hashes or hashes of hashes of hashes
1562 to a single depth, with elements joined by underscores
1563  
1564 =head3 Example
1565  
1566 {
1567 "metadata" : {
1568 "allowance" : {
1569 "allowanceExpiry" : 530567,
1570 "remainingAllowance" : 9557,
1571 "totalAllowance" : 10000
1572 },
1573 ...
1574
1575 becomes
1576 {
1577 "metadata_allowance_allowanceExpiry" : 530473,
1578 "metadata_allowance_remainingAllowance" : 9556,
1579 "metadata_allowance_totalAllowance" : 10000,
1580 ...
1581  
1582 The advantage of a flattened structure is its easier to print with existing fuunctions like printpos
1583  
1584 =cut
1585  
1586 #####################################################################
1587 sub flatten_withunder
1588 0 ▶{
Subroutine flatten_withunder: not called CC=26 SCAR=65.5
Pod documented
1589 0 my ($self)=shift;
1590 0 my (@items)=@_;
1591 0 my $fudebug=0;
1592 0 ▶ $fudebug and printf "%d items to process\n",0+@items;
Branch: 1 branch
BranchTrueFalseTotal
$fudebug and printf "%d items to process\n", 0 + @items 0 0 0
1593 0 for my $item (@items)
1594 {
1595 0 ▶ $fudebug and print "item is a ".ref($item)."\n";
Branch: 1 branch
BranchTrueFalseTotal
$fudebug and print 'item is a ' . ref($item) . "\n" 0 0 0
1596 0 ▶ return if (ref($item)eq '');
Branch: 1 branch
BranchTrueFalseTotal
if ref $item eq "" 0 0 0
1597 0 ▶ if (ref($item) eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $item eq "HASH") 0 0 0
1598 {
1599 0 ▶ $fudebug and print "is a hash\n";
Branch: 1 branch
BranchTrueFalseTotal
$fudebug and print "is a hash\n" 0 0 0
1600 0 for my $key (keys %$item)
1601 {
1602 0 ▶ $fudebug and print "key1 $key\n";
Branch: 1 branch
BranchTrueFalseTotal
$fudebug and print "key1 $key\n" 0 0 0
1603 0 ▶ if (ref($item->{$key}) eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $item->{$key} eq "HASH") 0 0 0
1604 {
1605 0 for my $key2 (keys %{$item->{$key}})
1606 {
1607 0 ▶ $fudebug and print "keyr2 $key2\n";
Branch: 1 branch
BranchTrueFalseTotal
$fudebug and print "keyr2 $key2\n" 0 0 0
1608 0 $item->{$key."_".$key2}=$item->{$key}->{$key2};
1609 0 ▶ $fudebug and printf "creating $key"."_"."$key2 as a %s\n",ref($item->{$key}->{$key2});
Branch: 1 branch
BranchTrueFalseTotal
$fudebug and printf "creating $key" . '_' . "$key2 as a %s\n", ref $item->{$key}{$key2} 0 0 0
1610
1611 # $self->flatten_withunder($item->{$key}) if (ref($item->{$key}->{$key2}) eq 'HASH');
1612 0 ▶ if (ref($item->{$key}->{$key2}) eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $item->{$key}{$key2} eq "HASH") 0 0 0
1613 {
1614 0 for my $key3 (keys %{$item->{$key}->{$key2}})
1615 {
1616 0 ▶ $fudebug and print "key3 $key3\n";
Branch: 1 branch
BranchTrueFalseTotal
$fudebug and print "key3 $key3\n" 0 0 0
1617 0 $item->{$key."_".$key2."_".$key3}=$item->{$key}->{$key2}->{$key3};
1618 0 ▶ $fudebug and printf "creating $key"."_$key2"."_$key3 as a %s\n",ref($item->{$key}->{$key2}->{$key3});
Branch: 1 branch
BranchTrueFalseTotal
$fudebug and printf "creating $key" . "_$key2" . "_$key3 as a %s\n", ref $item->{$key}{$key2}{$key3} 0 0 0
1619 }
1620 0 ▶ $fudebug and print "deleting $key->$key2 and $key _$key2\n";
Branch: 1 branch
BranchTrueFalseTotal
$fudebug and print "deleting $key->$key2 and $key _$key2\n" 0 0 0
1621 0 delete $item->{$key}->{$key2};
1622 0 delete $item->{$key."_".$key2};
1623 }
1624 }
1625 0 ▶ $fudebug and print "deleting: $key\n";
Branch: 1 branch
BranchTrueFalseTotal
$fudebug and print "deleting: $key\n" 0 0 0
1626 0 delete $item->{$key};
1627 }
1628 0 ▶ if (ref($item->{$key}) eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $item->{$key} eq "ARRAY") 0 0 0
1629 {
1630 0 ▶ $fudebug and print "$key is array ref\n";
Branch: 1 branch
BranchTrueFalseTotal
$fudebug and print "$key is array ref\n" 0 0 0
1631 0 for (@{$item->{$key}})
1632 {
1633 0 $self->flatten_withunder($_);
1634 }
1635 }
1636 }
1637 }
1638 0 ▶ if (ref($item) eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $item eq "ARRAY") 0 0 0
1639 {
1640 0 ▶ $fudebug and print "is an array\n";
Branch: 1 branch
BranchTrueFalseTotal
$fudebug and print "is an array\n" 0 0 0
1641 0 for (@$item)
1642 {
1643 0 $self->flatten_withunder($_);
1644 }
1645 }
1646 }
1647 0 ▶ $fudebug and print "processed\n";
Branch: 1 branch
BranchTrueFalseTotal
$fudebug and print "processed\n" 0 0 0
1648 }
1649  
1650  
1651 #####################################################################
1652 # uses known structure of supplied deep hash to search for item
1653 # should probably replace with a more generalised deep fetch function.
1654 #####################################################################
1655  
1656 =head2 fetch
1657  
1658 This function is a way to hide the various structures a position may have
1659  
1660 Obsolete but still used sometimes.
1661  
1662 Parameters
1663  
1664 1 A position hash ref, $h
1665 2 The name of the item to be retrieved.
1666  
1667 Returns undef if not found, or the value of item if it is.
1668  
1669 The function looks first in $h->{item} then
1670 in $h->{position}=>{item} and then in $h->{market}->{item}
1671  
1672 Its only useful with positions, not hashes in general.
1673  
1674 =cut
1675 #####################################################################
1676 sub fetch
1677 396 ▶{
Subroutine fetch: called CC=6 SCAR=23.5
Pod documented
1678 396 my ($self,$position,$item)=@_;
1679  
1680 # return "NOT A HASREF $position"if (ref($position) ne 'HASH');
1681 396 ▶ die "supplied position $position to fetch() is not a HASHREF" if (ref($position) ne 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $position ne "HASH" 0 396 396
1682 396 ▶ defined $item or die "fetch, item undefined";
Branch: 1 branch
BranchTrueFalseTotal
defined $item or die "fetch, item undefined" 396 0 396
1683 396 my $p=$position->{position};
1684 396 my $m=$position->{market};
1685  
1686 396 ▶ if (exists $position->{$item}) { return $position->{$item}; }
Branch: 3 branches
BranchTrueFalseTotal
if (exists $position->{$item}) { } 396 0 396
elsif (exists $p->{$item}) { } 0 0 0
elsif (exists $m->{$item}) { } 0 0 0
1687 0 elsif (exists $p->{$item}) { return $p->{$item}; }
1688 0 elsif (exists $m->{$item}) { return $m->{$item}; }
1689 else {
1690 0 return undef;
1691 }
1692  
1693 }
1694  
1695 #####################################################################
1696 # given an instrument name in search, look for it inside the instrumentName, and return
1697 # the epic. Fail if result is not 1 item.
1698 # used for filling in the epic (a unique identifier) in old data files
1699 # where I forgot to store it.
1700 #####################################################################
1701  
1702 =head2 epicsearch
1703  
1704 Find the epic (unique identifier) for an instrument from the underlying share.
1705  
1706 This function calls IG's search API looking for a match to the name. If found
1707 the value of the epic is returned.
1708  
1709 =head3 Status - very experimental. Seems to work well.
1710  
1711 Contains print and die statements. Useful if you forgot to record the epic.
1712  
1713 =cut
1714  
1715 #####################################################################
1716 sub epicsearch
1717 0 ▶{
Subroutine epicsearch: not called CC=6 SCAR=37.4
Pod documented
1718 0 my ($self,$search)=@_;
1719 0 my $headers =
1720 {
1721 'Content-Type' => 'application/json; charset=UTF-8',
1722 'Accept' => 'application/json; charset=UTF-8',
1723 VERSION => 1,
1724 CST=>$self->CST,
1725 'X-SECURITY-TOKEN'=> $self->XSECURITYTOKEN,
1726 'X-IG-API-KEY'=> $self->apikey,
1727 };
1728 #my $jheaders = encode_json($headers);
1729 0 my $jheaders=JSON->new->canonical->encode($headers);
1730 0 my $client = REST::Client->new();
1731 0 $client->setHost($self->_url);
1732 0 $search=~s#/#%2F#g;
1733 0 my $url="/markets?searchTerm=$search";
1734 0 $search=~s#%2F#/#g;
1735 0 $url=~s/ /%20/g;
1736 0 my $r=$client->GET ( $url, $headers);
1737  
1738 # my $resp=decode_json($client->responseContent());
1739  
1740  
1741 #print "url=$url\n";
1742 0 my $code;
1743  
1744 0 $code=$client->responseCode();
1745  
1746 0 my $retried=0;
1747 0 ▶ while ($code==403 and $retried<4)
Branch: 1 branch
BranchTrueFalseTotal
if ($code == 403 and $retried < 4) 0 0 0
Condition0%0/3
$code == 403 and $retried < 4
!ll&&!rl&&r
000
MC/DC0%0/2
$code == 403 and $retried < 4
$code == 403 $retried < 4
Truth table0%0/3
A and B
A= $code == 403B= $retried < 4
ABresult
0X0
100
111
1748 {
1749 0 sleep 10;
1750 0 $retried++;
1751 0 $r=$client->GET ( $url, $headers);
1752 0 $code=$client->responseCode();
1753 # print "search retried\n";
1754 }
1755  
1756 0 ▶ die "response code from url='$url' code=$code retried $retried times" if ($code!=200);
Branch: 1 branch
BranchTrueFalseTotal
if $code != 200 0 0 0
1757  
1758 0 my $markets=decode_json($client->responseContent);
1759 # print JSON->new->ascii->pretty->encode($markets)."\n";
1760  
1761 0 my @wantedmarkets=grep { $_->{expiry} eq 'DFB' } @{$markets->{markets}};
1762 0 @wantedmarkets=grep { $self->_nothe($self->fetch($_,'instrumentName') , $search) } @wantedmarkets;
1763  
1764 0 @wantedmarkets=map { $_->{epic} } @wantedmarkets;
1765 0 ▶ die "Zero epics found for search $search" if (@wantedmarkets==0);
Branch: 1 branch
BranchTrueFalseTotal
if @wantedmarkets == 0 0 0 0
1766 0 ▶ die "Multiple epics found @wantedmarkets for search $search" if (@wantedmarkets!=1);
Branch: 1 branch
BranchTrueFalseTotal
if @wantedmarkets != 1 0 0 0
1767  
1768 0 return $wantedmarkets[0];
1769  
1770 }
1771 #####################################################
1772 # remove a trailing 'the'
1773 #####################################################
1774 sub _nothe
1775 0 ▶{
Subroutine _nothe: not called CC=1 SCAR=6.9
1776 0 my ($self,$x,$y)=@_;
1777  
1778 # print "comparing $x $y \n";
1779 0 $x=~s#/.*$##;
1780 0 $y=~s#/.*$##;
1781  
1782 0 return $x eq $y;
1783 }
1784 # so this is used to read one of my old data files.
1785 ##################################################################################
1786 # Reads am ascii file - older format and returns a list of positions,
1787 # a hashref keyed on epic.
1788 ##################################################################################
1789  
1790 =head2 readfile_oldformat
1791  
1792  
1793 Parameters
1794  
1795 1 Path to a file to read
1796  
1797 A file readable by this function may be generated by using printpos with format as follows:
1798 "%-41sinstrumentName %+6.2fsize %-9.2flevel ".
1799 "%-9.2fbid £%-8.2fprofit %5.1fprofitpc%% £%10.2fatrisk\n",
1800  
1801 This file was originally generated to be human readable so reading by machine is a stretch.
1802  
1803 =head3 Status - downright broken (for you). Sorry!
1804  
1805 May contains print and die statements. Contaions hardcoded paths that will need to be
1806 changed.
1807  
1808 =cut
1809 ##################################################################################
1810 sub readfile_oldformat
1811 0 ▶{
Subroutine readfile_oldformat: not called CC=11 SCAR=48.8
Pod documented
1812 0 my ($self, $f,$writenewfile)=@_;
1813 0 my $positions={};
1814 0 my $totalline;
1815 0 $f="/home/mark/igrec/results/$f";
1816 0 ▶ open(F,$f) or die "cannot open $f";
Branch: 1 branch
BranchTrueFalseTotal
open F, $f or die "cannot open $f" 0 0 0
1817 #Roku Inc +0.38 16501.00 21842.0 £2029.58 32.4% £ 8299.96
1818 0 my @fieldhashnames=qw(epic instrumentName size level bid profit profitpc atrisk);
1819 0 ▶ while (<F>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline F)) 0 0 0
1820 {
1821 0 my @fields;
1822 0 my @names=@fieldhashnames;
1823 0 my $position={};
1824  
1825 0 chomp;
1826 0 ▶ if (m/\|/)
Branch: 3 branches
BranchTrueFalseTotal
if (/\|/) { } 0 0 0
elsif (/^Name/) { } 0 0 0
elsif (/^Total/) { } 0 0 0
1827 {
1828 0 die;
1829 }
1830 elsif (m/^Name/)
1831 {
1832 0 s/[£%]//g;
1833 0 @fields=split(/ +/);
1834 0 unshift(@fields,'Epic');
1835 # print "#".join("\|",@fields)."\n";
1836 }
1837 elsif (m/^Total/)
1838 {
1839 0 $totalline=$_;
1840 }
1841 else
1842 {
1843 0 my $name=substr($_,0,42);
1844 0 my $line=substr($_,43);
1845 0 $name=~s/ +$//;
1846 0 $line=~s/[\$£%]//g;
1847 0 @fields=split(/ +/,$line);
1848 0 my $epic=$self->epicsearch($name);
1849 0 unshift(@fields,$epic,$name);
1850 #die "$line\n@fields\n@names";
1851 0 ▶ while (@names)
Branch: 1 branch
BranchTrueFalseTotal
if (@names) 0 0 0
1852 {
1853 0 $position->{shift(@names)}=shift(@fields);
1854 }
1855 0 $positions->{$epic}=$position;
1856 }
1857 }
1858 # close F;
1859 0 ▶ if ($writenewfile)
Branch: 1 branch
BranchTrueFalseTotal
if ($writenewfile) 0 0 0
1860 {
1861 0 $f=~s/results/r2/;
1862 0 ▶ if (! -e $f)
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $f) 0 0 0
1863 {
1864 0 ▶ open(my $g,">" , $f) or die "Cannot open $f for write";
Branch: 1 branch
BranchTrueFalseTotal
open my $g, ">", $f or die "Cannot open $f for write" 0 0 0
1865 0 my $format= "%sepic|%sinstrumentName|%0.2fsize|%-0.2flevel|".
1866 "%-0.2fbid|£%-0.2fprofit|%0.1fprofitpc%%|£%0.2fatrisk\n",
1867 print $g "Epic|Instrumentname|Size|Level|Bid|Profit£|Profitpc%|Atrisk£\n";
1868 0 my $a=$self->agg([values %$positions]);
1869 0 for (@$a)
1870 {
1871 0 $self->printpos($g,$_,$format);
1872 }
1873 0 print $g $totalline."\n";
1874 }
1875 }
1876 0 return $positions;
1877 }
1878 ##################################################################################
1879 # Reads am ascii file and returns a list of positions,
1880 # a hashref keyed on epic.
1881 ##################################################################################
1882  
1883 =head2 readfile
1884  
1885  
1886 Parameters
1887  
1888 1 Path to a file to read
1889  
1890 A file readable by this function may be generated by using printpos with format as follows:
1891 "%sepic|%sinstrumentName|%0.2fsize|%-0.2flevel|".
1892 "%-0.2fbid|£%-0.2fprofit|%0.1fprofitpc%%|£%0.2fatrisk|%smarketStatus\n",
1893  
1894 =head3 Status - downright broken (for you). Sorry!
1895  
1896 The function contains a hardcoded path for reading the files. You would need a
1897 crontab entry to generate them.
1898  
1899 May contain print and die statements. Contains hardcoded paths that will need to be
1900 changed.
1901  
1902 =cut
1903 ##################################################################################
1904 sub readfile
1905 0 ▶{
Subroutine readfile: not called CC=13 SCAR=52.0
Pod documented
1906 0 my ($self,$f)=@_;
1907 0 my $debug=1;
1908  
1909 0 my $positions={};
1910 0 $f="/home/mark/igrec/r2/$f";
1911 0 ▶ open(F,$f) or die "cannot open $f";
Branch: 1 branch
BranchTrueFalseTotal
open F, $f or die "cannot open $f" 0 0 0
1912 0 my @fieldhashnames=qw(epic instrumentName size level bid profit profitpc atrisk tradeable);
1913 0 my $ln=0;
1914 0 ▶ while (<F>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline F)) 0 0 0
1915 {
1916 0 my @fields;
1917 0 my @names=@fieldhashnames;
1918 0 my $position={};
1919  
1920 0 $ln++;
1921 0 chomp;
1922 0 ▶ if (m/^Total/)
Branch: 6 branches
BranchTrueFalseTotal
if (/^Total/) { } 0 0 0
elsif (/ Positions$/) { } 0 0 0
elsif (/^ *$/) { } 0 0 0
elsif (/#/) { } 0 0 0
elsif (not /\|/) { } 0 0 0
elsif (/Epic/) { } 0 0 0
1923 {
1924 0 next;
1925 }
1926 elsif (m/ Positions$/)
1927 {
1928 0 next;
1929 }
1930 elsif (m/^ *$/)
1931 {
1932 0 next;
1933 }
1934 elsif (m/#/)
1935 {
1936 0 next;
1937 }
1938 elsif (!m/\|/)
1939 {
1940 0 die "No | lin line $ln file $f";
1941 }
1942 elsif (m/Epic/)
1943 {
1944 0 next;
1945 }
1946 else
1947 {
1948 0 s/[£&]//g;
1949 0 @fields=split(/\|/);
1950 0 for my $fieldname (@fieldhashnames)
1951 {
1952 0 ▶ die if (!defined $names[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $names[0] 0 0 0
1953 #print "names[0]=$names[0]\n";
1954 0 $position->{$fieldname}=shift(@fields);
1955 }
1956 0 $positions->{$position->{epic}}=$position;
1957 0 ▶ $position->{marketStatus}//=''; # older files do not record this.
Condition0%0/2
$position->{"marketStatus"} //= ""
l!l
00
MC/DC0%0/1
$position->{"marketStatus"} //= ""
$position->{"marketStatus"}
Truth table0%0/2
A
A= $position->{"marketStatus"}
Aresult
11
00
1958 }
1959 }
1960 0 ▶ $debug and print "$ln lines read\n";
Branch: 1 branch
BranchTrueFalseTotal
$debug and print "$ln lines read\n" 0 0 0
1961 0 return $positions;
1962 }
1963 #####################################################################
1964 # format strings contained embedded printf specifiers followed by
1965 # a hash element name .
1966 #
1967 # eg "%sdate %sdescription %sepic %sstatus\n";
1968 # eg "%-20sdate %-30sdescription %-20sepic %-15sstatus\n";
1969 # eg
1970 # "%sepic|%sinstrumentName|%6.2fsize|%-9.2flevel|".
1971 # "%-9.2fbid|£%-8.2fprofit|%5.1fprofitpc%%|£%10.2fatrisk\n",
1972 #eg
1973 # "%-41sinstrumentName %+6.2fsize %-9.2flevel ".
1974 # "%-9.2fbid £%-8.2fprofit %5.1fprofitpc%% £%10.2fatrisk\n",
1975 # Arguments:
1976 # 1) An IG object ref. (self) Is not really used.
1977 # 2) Either "stdout" or an open writable file handle.
1978 # 3) A hash possibly deep, with items. Ig the item is not found directly in the hash,
1979 # the $self->fetch function is used for access. If still not found
1980 # then "UNDEF" is printed.
1981 # CHANGED to $self->uds
1982 # OR: If this is an array ref, then a title line is ptinted using the format string
1983 # and the referenced array of titles
1984 # OR: If empty dtring ort undef, derive titles from the format
1985 # string and print a title line.
1986 # 4) A formatting string. Can contain text, containing embedded
1987 # format instructions like %6.2fsize here %6.2f is a print f
1988 # specifier and size is the name of the item to retrieve from the hash.
1989 # 5,6) up /down can be percent gives green if > up, bold green if > 5*up.
1990 # can be a coloration function of position.
1991 # just one function, so no down ever.
1992 # function takes argument position, and returns optional colors
1993 #####################################################################
1994  
1995 =head2 printpos
1996  
1997 =head3 Parmeters
1998  
1999 A file handle or the word stdout, all output sent here.
2000  
2001 A hashref of items to print
2002 OR: If this is an array ref, then a title line is ptinted using the format string
2003 and the referenced array of titles
2004 OR: If empty string or undef, derive titles from the format
2005 string and print a title line.
2006  
2007 A formatting string. Can contain text, containing embedded
2008 format instructions like %6.2fsize here %6.2f is a print f
2009 specifier and size is the name of the item to retrieve from the hash.
2010  
2011 OPTIONAL up can be percent gives green if > up, bold green if > 5*up.
2012 can be a coloration function of position. Just one function, so no down ever if a function is given
2013 function takes argument position, and returns optional colors
2014  
2015 OPTIONAL down can be percent gives red if <down , bold red if < 5*down.
2016  
2017 =head3 Description
2018  
2019 This is a very general function will work with any hash.
2020  
2021 =cut
2022 #####################################################################
2023 sub printpos
2024 796 ▶{
Subroutine printpos: called CC=49 SCAR=59.4
Pod documented
2025  
2026 796 my ($self,$out,$position,$format,$up,$down)=@_;
2027  
2028 796 my $colsub;
2029  
2030 796 ▶ $out=*STDOUT if ($out eq "stdout");
Branch: 1 branch
BranchTrueFalseTotal
if $out eq "stdout" 728 68 796
2031  
2032 796 ▶ $down=-$up if (defined $up and ref($up) eq '' and !defined $down) ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $up and ref $up eq "" and not defined $down 0 796 796
Condition33%2/6
defined $up and ref $up eq "" and not defined $down
!ll&&!rl&&r
79600
defined $up and ref $up eq ""
!ll&&!rl&&r
79600
MC/DC0%0/3
defined $up and ref $up eq "" and not defined $down
defined $up ref $up eq "" not defined $down
Truth table25%1/4
A and B and not(C)
A= defined $upB= ref $up eq ""C= not defined $down
ABCresult
0XX0
10X0
1100
1111
2033  
2034 796 ▶ if (defined $up and ref($up) ne 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
if (defined $up and ref $up ne "CODE") 0 796 796
Condition33%1/3
defined $up and ref $up ne "CODE"
!ll&&!rl&&r
79600
MC/DC0%0/2
defined $up and ref $up ne "CODE"
defined $up ref $up ne "CODE"
Truth table33%1/3
A and B
A= defined $upB= ref $up ne "CODE"
ABresult
0X0
100
111
2035 {
2036 $colsub=sub
2037 0 ▶ {
Subroutine __ANON__: not called CC=9 SCAR=45.0
2038 0 my ($position)=shift;
2039 0 my $v1=$position->{dbid};
2040 0 my $col='';
2041 0 $v1=~s/%//;
2042 0 ▶ $col=Green if (defined $up and $v1>$up);
Branch: 1 branch
BranchTrueFalseTotal
if defined $up and $v1 > $up 0 0 0
Condition0%0/3
defined $up and $v1 > $up
!ll&&!rl&&r
000
MC/DC0%0/2
defined $up and $v1 > $up
defined $up $v1 > $up
Truth table0%0/3
A and B
A= defined $upB= $v1 > $up
ABresult
0X0
100
111
2043 0 ▶ $col=Red if (defined $down and $v1<$down);
Branch: 1 branch
BranchTrueFalseTotal
if defined $down and $v1 < $down 0 0 0
Condition0%0/3
defined $down and $v1 < $down
!ll&&!rl&&r
000
MC/DC0%0/2
defined $down and $v1 < $down
defined $down $v1 < $down
Truth table0%0/3
A and B
A= defined $downB= $v1 < $down
ABresult
0X0
100
111
2044 0 ▶ $col=Green+Bold if (defined $up and $v1>$up*5);
Branch: 1 branch
BranchTrueFalseTotal
if defined $up and $v1 > $up * 5 0 0 0
Condition0%0/3
defined $up and $v1 > $up * 5
!ll&&!rl&&r
000
MC/DC0%0/2
defined $up and $v1 > $up * 5
defined $up $v1 > $up * 5
Truth table0%0/3
A and B
A= defined $upB= $v1 > $up * 5
ABresult
0X0
100
111
2045 0 ▶ $col=Red+Bold if (defined $down and $v1<5*$down);
Branch: 1 branch
BranchTrueFalseTotal
if defined $down and $v1 < 5 * $down 0 0 0
Condition0%0/3
defined $down and $v1 < 5 * $down
!ll&&!rl&&r
000
MC/DC0%0/2
defined $down and $v1 < 5 * $down
defined $down $v1 < 5 * $down
Truth table0%0/3
A and B
A= defined $downB= $v1 < 5 * $down
ABresult
0X0
100
111
2046 0 return $col;
2047 0 };
2048 }
2049 796 ▶ $colsub=$up if (defined $up and ref($up) eq 'CODE');
Branch: 1 branch
BranchTrueFalseTotal
if defined $up and ref $up eq "CODE" 0 796 796
Condition33%1/3
defined $up and ref $up eq "CODE"
!ll&&!rl&&r
79600
MC/DC0%0/2
defined $up and ref $up eq "CODE"
defined $up ref $up eq "CODE"
Truth table33%1/3
A and B
A= defined $upB= ref $up eq "CODE"
ABresult
0X0
100
111
2050 796 ▶ $colsub=sub {''} if (!defined $up);
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
unless defined $up 796 0 796
2051  
2052  
2053 796 my $titles=$format;
2054 796 ▶ if (ref($position) eq 'ARRAY') # its titles to print!
Branch: 1 branch
BranchTrueFalseTotal
if (ref $position eq "ARRAY") 0 796 796
2055 {
2056 #$format=~s/%[-+]/%/g;
2057 #print "$format\n";
2058 0 ▶ while ($format=~m/[-+]?([0-9]+)\.([0-9]+)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($format =~ /[-+]?([0-9]+)\.([0-9]+)/) 0 0 0
2059 {
2060 0 my $x;
2061 0 $x=$1;
2062 0 ▶ abs($2)>abs($x) and $x=$2;
Branch: 1 branch
BranchTrueFalseTotal
abs $2 > abs $x and $x = $2 0 0 0
2063 0 $format=~s/%([-+]?)([0-9]+)\.([0-9]+)/%$1$x/;
2064 }
2065 #print "#1 $format\n";
2066 0 $format=~s/%\+\+/%+/g;
2067 #print "#2 $format\n";
2068 0 $format=~s/%([-\+]?[0-9]+)\.[0-9]+/%$1/g;
2069 #print "#3 $format\n";
2070 0 $format=~s/%([-\+]?[0-9]+)[fd]/%$1s/g;
2071 #print "#4 $format\n";
2072 0 $format=~s/%([-\+]?[0-9]*)([a-zA-Z_][a-zA-Z0-9_]*)/%$1s/g;
2073 #die $format;
2074 # print "$format\n"; exit;
2075 #$"=":"; print "@$position\n";
2076
2077  
2078 0 $format=~s/[\x82\x83\xc3]+//g; # so we get some strange characters like ÃÂ occuring in pairs. Not sure why. This removes them.
2079 #$format="%-41s %+7s %11s %-10s £%-10s %5s%% £%12s %-9s %-4s";
2080 #print "$format\n"; #exit;
2081 0 ▶ print $out Bold if ($self->col and defined $INC{'Term/Chrome.pm'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->col and defined $INC{"Term/Chrome.pm"} 0 0 0
Condition0%0/3
$self->col and defined $INC{"Term/Chrome.pm"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->col and defined $INC{"Term/Chrome.pm"}
$self->col defined $INC{"Term/Chrome.pm"}
Truth table0%0/3
A and B
A= $self->colB= defined $INC{"Term/Chrome.pm"}
ABresult
0X0
100
111
2082 # print "format='$format' @$position\n";
2083 0 printf $out $format,@$position;
2084 0 ▶ print $out Reset if ($self->col and defined $INC{'Term/Chrome.pm'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->col and defined $INC{"Term/Chrome.pm"} 0 0 0
Condition0%0/3
$self->col and defined $INC{"Term/Chrome.pm"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->col and defined $INC{"Term/Chrome.pm"}
$self->col defined $INC{"Term/Chrome.pm"}
Truth table0%0/3
A and B
A= $self->colB= defined $INC{"Term/Chrome.pm"}
ABresult
0X0
100
111
2085 0 return;
2086 }
2087  
2088 # auto generated title list from the names
2089 796 ▶ if (!defined $position or $position eq '')
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $position or $position eq "") 3 793 796
Condition100%3/3
not defined $position or $position eq ""
l!l&&r!l&&!r
21793
MC/DC100%2/2
not defined $position or $position eq ""
not defined $position $position eq ""
Truth table100%3/3
not(A) or B
A= not defined $positionB= $position eq ""
ABresult
1X1
011
000
2090 {
2091 3 $titles=~s/\n//g;
2092 3 $titles=~s/%([-+0-9.]*)([sfd])/%/g;
2093 3 $titles=~s/%%/__PC__/g;
2094 3 $titles=~s/%//; # just one
2095 3 $titles=~s/£%([a-zA-Z]+)/%$1£/g;
2096 3 my @titles=split(/%/,$titles);
2097 3 map {s/[|,]//g } @titles;
2098 3 map {s/ +//g } @titles;
2099 3 map { s/__PC__//g; } @titles;
2100 3 map { s/([\w']+)/\u\L$1/g; } @titles;
2101 3 ▶ while ($format=~m/%[-+]?([0-9]+)\.([0-9]+)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($format =~ /%[-+]?([0-9]+)\.([0-9]+)/) 13 3 16
2102 {
2103 13 my $x;
2104 #my $x=$1+$2;
2105 13 $x=$1;
2106 13 ▶ $2>$x and $x=$2;
Branch: 1 branch
BranchTrueFalseTotal
$2 > $x and $x = $2 0 13 13
2107 13 $format=~s/%([-+]?)([0-9]+)\.([0-9]+)/%$1$x/;
2108 }
2109 3 $format=~s/(%[-+0-9.]*)[a-zA-Z]+/$1s/g;
2110 #$format=~s/(%[-+0-9]+)\.[0-9]+/$1/g;
2111 3 $format=~s/£//g;
2112 #die "format=$format titles=@titles";
2113 3 $format=~s/[\x82\x83\xc3]+//g; # so we get some strange characters like ÃÂ occuring in pairs. Not sure why. This removes them.
2114 3 ▶ print $out Bold if ($self->col and defined $INC{'Term/Chrome.pm'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->col and defined $INC{"Term/Chrome.pm"} 0 3 3
Condition33%1/3
$self->col and defined $INC{"Term/Chrome.pm"}
!ll&&!rl&&r
300
MC/DC0%0/2
$self->col and defined $INC{"Term/Chrome.pm"}
$self->col defined $INC{"Term/Chrome.pm"}
Truth table33%1/3
A and B
A= $self->colB= defined $INC{"Term/Chrome.pm"}
ABresult
0X0
100
111
2115 3 printf $out $format, @titles;
2116 3 ▶ print $out Reset if ($self->col and defined $INC{'Term/Chrome.pm'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->col and defined $INC{"Term/Chrome.pm"} 0 3 3
Condition33%1/3
$self->col and defined $INC{"Term/Chrome.pm"}
!ll&&!rl&&r
300
MC/DC0%0/2
$self->col and defined $INC{"Term/Chrome.pm"}
$self->col defined $INC{"Term/Chrome.pm"}
Truth table33%1/3
A and B
A= $self->colB= defined $INC{"Term/Chrome.pm"}
ABresult
0X0
100
111
2117 3 return;
2118 }
2119  
2120  
2121  
2122 # $p=$position->{position};
2123 # $m=$position->{market};
2124  
2125 793 $format=~s/%%/##/g;
2126  
2127  
2128 # while (($format=~s/%([-+0-9]+\.[0-9]+)([a-z][a-zA-Z0-9]*)/%$1__S__/) || ($format=~s/%([-+0-9]*)([a-z][a-zA-Z0-9]*)/%$1__F__/))
2129 # {
2130 # my $s;
2131 # $s=$activity->{$2};
2132 # my $pos=$1;
2133 # $pos=~s/-//;
2134 # $s=substr($s,0,$pos) if (defined(pos) and $pos ne '' and $pos<length($s));
2135 # push(@args,$s);
2136 # }
2137  
2138 793 my $col='';
2139 793 ▶ while ($format=~s/%([-+0-9.]*[dsf])([a-zA-Z_][a-zA-Z0-9_]*)/%s/)
Branch: 1 branch
BranchTrueFalseTotal
if ($format =~ s/%([-+0-9.]*[dsf])([a-zA-Z_][a-zA-Z0-9_]*)/%s/) 6278 793 7071
2140 {
2141 6278 my $s;
2142  
2143 6278 my $item=$2;
2144 6278 ▶ my $len=$1//"";
Condition50%1/2
$1 // ""
l!l
62780
MC/DC0%0/1
$1 // ""
$1
Truth table50%1/2
A
A= $1
Aresult
11
00
2145 # die "item is UNDEF" if ($item eq 'UNDEF');
2146 # die "len is UNDEF" if ($len eq 'UNDEF');
2147 # $len='' if ($len eq 'UNDEF');
2148 6278 ▶ $len="%".$len if ($len);
Branch: 1 branch
BranchTrueFalseTotal
if $len 6278 0 6278
2149 6278 ▶ if (defined $item and $item ne '' and exists $position->{$item} and defined $position->{$item})
Branch: 2 branches
BranchTrueFalseTotal
if (defined $item and $item ne '' and exists $position->{$item} and defined $position->{$item}) { } 6278 0 6278
elsif (defined $self->fetch($position, $item)) { } 0 0 0
Condition33%3/9
defined $item and $item ne "" and exists $position->{$item} and defined $position->{$item}
!ll&&!rl&&r
006278
defined $item and $item ne "" and exists $position->{$item}
!ll&&!rl&&r
006278
defined $item and $item ne ""
!ll&&!rl&&r
006278
MC/DC0%0/4
defined $item and $item ne "" and exists $position->{$item} and defined $position->{$item}
defined $item $item ne "" exists $position->{$item} defined $position->{$item}
Truth table20%1/5
A and B and C and D
A= defined $itemB= $item ne ""C= exists $position->{$item}D= defined $position->{$item}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2150 {
2151 6278 $position->{$item}=~s/%//g;
2152 #$position->{$item}='0' if ($position->{$item} eq 'UNDEF');
2153 6278 $s=sprintf($len,$position->{$item});
2154 6278 ▶ if ($item eq 'dbid' and exists $INC{'Term/Chrome.pm'} and $self->col)
Branch: 1 branch
BranchTrueFalseTotal
if ($item eq "dbid" and exists $INC{"Term/Chrome.pm"} and $self->col) 0 6278 6278
Condition33%2/6
$item eq "dbid" and exists $INC{"Term/Chrome.pm"} and $self->col
!ll&&!rl&&r
627800
$item eq "dbid" and exists $INC{"Term/Chrome.pm"}
!ll&&!rl&&r
627800
MC/DC0%0/3
$item eq "dbid" and exists $INC{"Term/Chrome.pm"} and $self->col
$item eq "dbid" exists $INC{"Term/Chrome.pm"} $self->col
Truth table25%1/4
A and B and C
A= $item eq "dbid"B= exists $INC{"Term/Chrome.pm"}C= $self->col
ABCresult
0XX0
10X0
1100
1111
2155 {
2156 ##my $v1=$position->{dbid};
2157 ##$v1=~s/%//;
2158 ##$col=Green if (defined $up and $v1>$up);
2159 ##$col=Red if (defined $down and $v1<$down);
2160 ##$col=Green+Bold if (defined $up and $v1>$up*5);
2161 ##$col=Red+Bold if (defined $down and $v1<5*$down);
2162  
2163 # $col=&$colsub($position);
2164 }
2165 # $col=Yellow if (defined $up);
2166 # $col=&$colsub($position);
2167 }
2168 elsif (defined $self->fetch($position,$item))
2169 {
2170 #$s=sprintf($len,$self->fetch($position,$2)//"UNDEF");
2171 0 ▶ $s=sprintf($len,$self->fetch($position,$item)//$self->uds);
Condition0%0/3
$self->fetch($position, $item) // $self->uds
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->fetch($position, $item) // $self->uds
$self->fetch($position, $item) $self->uds
Truth table0%0/3
A // B
A= $self->fetch($position, $item)B= $self->uds
ABresult
1X1
011
000
2172 0 ▶ if ($item eq 'dbid' and defined $INC{'Term/Chrome.pm'} and $self->col)
Branch: 1 branch
BranchTrueFalseTotal
if ($item eq "dbid" and defined $INC{"Term/Chrome.pm"} and $self->col) 0 0 0
Condition0%0/6
$item eq "dbid" and defined $INC{"Term/Chrome.pm"} and $self->col
!ll&&!rl&&r
000
$item eq "dbid" and defined $INC{"Term/Chrome.pm"}
!ll&&!rl&&r
000
MC/DC0%0/3
$item eq "dbid" and defined $INC{"Term/Chrome.pm"} and $self->col
$item eq "dbid" defined $INC{"Term/Chrome.pm"} $self->col
Truth table0%0/4
A and B and C
A= $item eq "dbid"B= defined $INC{"Term/Chrome.pm"}C= $self->col
ABCresult
0XX0
10X0
1100
1111
2173 {
2174 #my $v1;
2175  
2176 #$v1=$self->fetch($position,'dbid');
2177 #$v1=~s/%//;
2178 #$v1=100*$v1/$self->fetch($position,'bid');
2179 ###$col=Green if (defined $up and $self->col and $self->fetch($position,'dbid')/$self->fetch($position,'bid')>$up/100);
2180 ###$col=Red if (defined $down and $self->col and $self->fetch($position,'dbid')/$self->fetch($position,'bid')<$down/100);
2181 #$col=Green if (defined $up and $self->col and $v1>$up);
2182 #$col=Red if (defined $down and $self->col and $v1<$down);
2183 #$col=Green+Bold if (defined $up and $self->col and $v1>$up*5);
2184 #$col=Red+Bold if (defined $down and $self->col and $v1<5*$down);
2185 #$col=&$colsub($position);
2186 }
2187 #$col=&$colsub($position);
2188  
2189 }
2190 else
2191 {
2192 0 $len=~s/[df]/s/;
2193 0 $len=~s/\.[0-9]+//;
2194 #$s=sprintf($len,"UNDEF");
2195 0 $s=sprintf($len,$self->uds);
2196 }
2197  
2198 6278 $col=&$colsub($position);
2199 6278 $len=~s/[dsf]$//;
2200 6278 ▶ if ($len ne '') # len can be something like 0.2
Branch: 1 branch
BranchTrueFalseTotal
if ($len ne "") 6278 0 6278
2201 {
2202 6278 $len=~s/%//;
2203 6278 ▶ $len=abs($len) if ($len ne '');
Branch: 1 branch
BranchTrueFalseTotal
if $len ne "" 5551 727 6278
2204 6278 ▶ $s=substr($s,0,$len) if ($len and $len<length($s) and $len>=1);
Branch: 1 branch
BranchTrueFalseTotal
if $len and $len < length $s and $len >= 1 367 5911 6278
Condition83%5/6
$len and $len < length $s and $len >= 1
!ll&&!rl&&r
59110367
$len and $len < length $s
!ll&&!rl&&r
7275184367
MC/DC66%2/3
$len and $len < length $s and $len >= 1
$len $len < length $s $len >= 1
Truth table75%3/4
A and B and C
A= $lenB= $len < length $sC= $len >= 1
ABCresult
0XX0
10X0
1100
1111
2205 }
2206  
2207 6278 $format=~s/%s/$s/;
2208 }
2209  
2210 793 ▶ $col=&$colsub($position) if ($self->col and defined $INC{'Term/Chrome.pm'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->col and defined $INC{"Term/Chrome.pm"} 0 793 793
Condition33%1/3
$self->col and defined $INC{"Term/Chrome.pm"}
!ll&&!rl&&r
79300
MC/DC0%0/2
$self->col and defined $INC{"Term/Chrome.pm"}
$self->col defined $INC{"Term/Chrome.pm"}
Truth table33%1/3
A and B
A= $self->colB= defined $INC{"Term/Chrome.pm"}
ABresult
0X0
100
111
2211 793 ▶ $col//='';
Condition50%1/2
$col //= ""
l!l
7930
MC/DC0%0/1
$col //= ""
$col
Truth table50%1/2
A
A= $col
Aresult
11
00
2212 793 $format=~s/##/%/g;
2213 793 $format=~s/£-/-£/g;
2214 793 $format=~s/[\x82\x83\xc3]+//g; # so we get some strange characters like ÃÂ occuring in pairs. Not sure why. This removes them.
2215 793 print $out $col, $format;
2216 793 ▶ if (ref($col) ne '')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $col ne "") 0 793 793
2217 0 { print $out Reset;
2218 }
2219  
2220 }
2221  
2222  
2223  
2224 =head2 sortrange
2225  
2226 =head3 Parameters
2227
2228 Ref to an array containing dates in printed ascii format.
2229  
2230 If there are no dates or an empty array, an empty string is returned.
2231  
2232 If there is one date, then that date is returned
2233  
2234 If there is more than one then the first and last after sorting is returned, with a dash between them.
2235  
2236 This is used in aggregation of positions and relates to creation dates with multiple positions
2237 in the same security purchased at different times.
2238  
2239 =cut
2240  
2241 sub sortrange
2242 132 ▶{
Subroutine sortrange: called CC=3 SCAR=11.0
Pod documented
2243 132 my ($self,$ar)=@_;
2244  
2245 132 my @dates=sort @$ar;
2246
2247 132 ▶ return '' if (@dates==0);
Branch: 1 branch
BranchTrueFalseTotal
if @dates == 0 0 132 132
2248 132 ▶ return $dates[0] if (@dates==1);
Branch: 1 branch
BranchTrueFalseTotal
if @dates == 1 34 98 132
2249 98 return $dates[0] . "-".$dates[-1];
2250 }
2251  
2252  
2253  
2254 =head2 Red Blue Bold Reset Underline Green color
2255  
2256 =head3 Description
2257  
2258 The above parameterless functions are provided if Term::Chrome is not available. They are "do nothing" subs provided to satisfy references only.
2259  
2260 =head1 DEPENDENCIES
2261  
2262 Moose
2263 Term::Chrom if available.
2264  
2265 =head1 UTILITIES
2266  
2267 A more complete position lister is given as igdisp.pl
2268  
2269 =head1 AUTHOR
2270  
2271 Mark Winder, C<< <markwin at cpan.org> >>
2272  
2273 =head1 BUGS
2274  
2275 Please report any bugs or feature requests to C<bug-finance-ig at rt.cpan.org>, or through
2276 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Finance-IG>. I will be notified, and then you'll
2277 automatically be notified of progress on your bug as I make changes.
2278  
2279  
2280  
2281  
2282 =head1 SUPPORT
2283  
2284 You can find documentation for this module with the perldoc command.
2285  
2286 perldoc Finance::IG
2287  
2288  
2289 You can also look for information at:
2290  
2291 =over 4
2292  
2293 =item * RT: CPAN's request tracker (report bugs here)
2294  
2295 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Finance-IG>
2296  
2297 =item * CPAN Ratings
2298  
2299 L<https://cpanratings.perl.org/d/Finance-IG>
2300  
2301 =item * Search CPAN
2302  
2303 L<https://metacpan.org/release/Finance-IG>
2304  
2305 =back
2306  
2307  
2308 =head1 ACKNOWLEDGEMENTS
2309  
2310 =head1 FURTHER READING
2311  
2312 IG REST API Reference https://labs.ig.com/rest-trading-api-reference
2313  
2314 =head1 LICENSE AND COPYRIGHT
2315  
2316 This software is Copyright (c) 2020 by Mark Winder.
2317  
2318 This is free software, licensed under:
2319  
2320 The Artistic License 2.0 (GPL Compatible)
2321  
2322  
2323 =cut
2324  
2325 5 1; # End of Finance::IG
↑ Summary lib/Finance/IG/Record/REST/Client.pm »