Nadex/Position.pm

filter: Statementstmt 70.7% 46 / 65 Branchbran 41.6% 10 / 24 Conditioncond 21.2% 10 / 47 MC/DCmcdc 0.0% 0 / 25 Subroutinesub 100% 12 / 12 Podpod 100% 8 / 8 totaltotal 47.5% 86 / 181 CC 34 SCAR 44.3
CC
34
Cov
49%
_new
165.4
direction
16.7
bid
2.1
CRAP 83.8
↑ Summary Nadex/Order.pm »
1 package Finance::Nadex::Position;
2  
3 14 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶sub bid {
Subroutine bid: called CC=2 SCAR=7.6
Pod documented
8  
9 1 my $self = shift;
10  
11 1 ▶ if ( exists $self->{bid} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"bid"}) 1 0 1
12 1 return $self->{bid};
13 }
14  
15 0 return;
16 }
17  
18 1 ▶sub contract {
Subroutine contract: called CC=2 SCAR=7.6
Pod documented
19  
20 1 my $self = shift;
21  
22 1 ▶ if ( exists $self->{contract} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"contract"}) 1 0 1
23 1 return $self->{contract};
24 }
25  
26 0 return;
27 }
28  
29 1 ▶sub direction {
Subroutine direction: called CC=6 SCAR=28.1
Pod documented
30  
31 1 my $self = shift;
32  
33 1 ▶ if ( exists $self->{direction} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"direction"}) 1 0 1
34 return 'buy'
35 1 ▶ if $self->{direction} eq '+' || $self->{direction} eq 'buy';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"direction"} eq "+" or $self->{"direction"} eq "buy" 1 0 1
Condition33%1/3
$self->{"direction"} eq "+" or $self->{"direction"} eq "buy"
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"direction"} eq "+" or $self->{"direction"} eq "buy"
$self->{"direction"} eq "+" $self->{"direction"} eq "buy"
Truth table33%1/3
A or B
A= $self->{"direction"} eq "+"B= $self->{"direction"} eq "buy"
ABresult
1X1
011
000
36 return 'sell'
37 0 ▶ if $self->{direction} eq '-' || $self->{direction} eq 'sell';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"direction"} eq "-" or $self->{"direction"} eq "sell" 0 0 0
Condition0%0/3
$self->{"direction"} eq "-" or $self->{"direction"} eq "sell"
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"direction"} eq "-" or $self->{"direction"} eq "sell"
$self->{"direction"} eq "-" $self->{"direction"} eq "sell"
Truth table0%0/3
A or B
A= $self->{"direction"} eq "-"B= $self->{"direction"} eq "sell"
ABresult
1X1
011
000
38 0 return undef;
39 }
40  
41 0 return;
42 }
43  
44 1 ▶sub epic {
Subroutine epic: called CC=2 SCAR=7.6
Pod documented
45  
46 1 my $self = shift;
47  
48 1 ▶ if ( exists $self->{epic} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"epic"}) 1 0 1
49 1 return $self->{epic};
50 }
51  
52 0 return;
53  
54 }
55  
56 1 ▶sub id {
Subroutine id: called CC=2 SCAR=7.6
Pod documented
57  
58 1 my $self = shift;
59  
60 1 ▶ if ( exists $self->{id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"id"}) 1 0 1
61 1 return $self->{id};
62 }
63  
64 0 return;
65 }
66  
67 1 ▶sub offer {
Subroutine offer: called CC=2 SCAR=7.6
Pod documented
68  
69 1 my $self = shift;
70  
71 1 ▶ if ( exists $self->{offer} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"offer"}) 1 0 1
72 1 return $self->{offer};
73 }
74  
75 0 return;
76 }
77  
78 1 ▶sub price {
Subroutine price: called CC=2 SCAR=7.6
Pod documented
79  
80 1 my $self = shift;
81  
82 1 ▶ if ( exists $self->{price} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"price"}) 1 0 1
83 1 return $self->{price};
84 }
85  
86 0 return;
87  
88 }
89  
90 1 ▶sub size {
Subroutine size: called CC=2 SCAR=7.6
Pod documented
91  
92 1 my $self = shift;
93  
94 1 ▶ if ( exists $self->{size} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"size"}) 1 0 1
95 1 return $self->{size};
96 }
97  
98 0 return;
99 }
100  
101 2 ▶sub _new {
Subroutine _new: called CC=22 SCAR=51.1
102  
103 2 my $hashref = shift;
104  
105 2 my $self = {};
106  
107 2 ▶ if ( exists $hashref->{'market'} && exists $hashref->{'position'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $hashref->{'market'} and exists $hashref->{'position'}) { } 2 0 2
elsif (exists $hashref->{'order'} and exists $hashref->{'instrument'} and $hashref->{'marketSnapshot'}) { } 0 0 0
Condition33%1/3
exists $hashref->{"market"} and exists $hashref->{"position"}
!ll&&!rl&&r
002
MC/DC0%0/2
exists $hashref->{"market"} and exists $hashref->{"position"}
exists $hashref->{"market"} exists $hashref->{"position"}
Truth table33%1/3
A and B
A= exists $hashref->{"market"}B= exists $hashref->{"position"}
ABresult
0X0
100
111
108 2 ▶ $self->{direction} = $hashref->{'position'}->{'direction'} || undef;
Condition50%1/2
$hashref->{'position'}{'direction'} || undef
l!l
20
MC/DC0%0/1
$hashref->{'position'}{'direction'} || undef
$hashref->{'position'}{'direction'}
Truth table50%1/2
A
A= $hashref->{'position'}{'direction'}
Aresult
11
00
109 2 ▶ $self->{price} = $hashref->{'position'}->{'openLevel'} || undef;
Condition50%1/2
$hashref->{'position'}{'openLevel'} || undef
l!l
20
MC/DC0%0/1
$hashref->{'position'}{'openLevel'} || undef
$hashref->{'position'}{'openLevel'}
Truth table50%1/2
A
A= $hashref->{'position'}{'openLevel'}
Aresult
11
00
110 2 ▶ $self->{id} = $hashref->{'position'}->{'dealId'} || undef;
Condition50%1/2
$hashref->{'position'}{'dealId'} || undef
l!l
20
MC/DC0%0/1
$hashref->{'position'}{'dealId'} || undef
$hashref->{'position'}{'dealId'}
Truth table50%1/2
A
A= $hashref->{'position'}{'dealId'}
Aresult
11
00
111 2 ▶ $self->{epic} = $hashref->{'position'}->{'epic'} || undef;
Condition50%1/2
$hashref->{'position'}{'epic'} || undef
l!l
20
MC/DC0%0/1
$hashref->{'position'}{'epic'} || undef
$hashref->{'position'}{'epic'}
Truth table50%1/2
A
A= $hashref->{'position'}{'epic'}
Aresult
11
00
112 2 ▶ $self->{contract} = $hashref->{'market'}->{'instrumentName'} || undef;
Condition50%1/2
$hashref->{'market'}{'instrumentName'} || undef
l!l
20
MC/DC0%0/1
$hashref->{'market'}{'instrumentName'} || undef
$hashref->{'market'}{'instrumentName'}
Truth table50%1/2
A
A= $hashref->{'market'}{'instrumentName'}
Aresult
11
00
113 2 ▶ $self->{bid} = $hashref->{'market'}->{'displayBid'} || 'NoBid';
Condition50%1/2
$hashref->{'market'}{'displayBid'} || 'NoBid'
l!l
20
MC/DC0%0/1
$hashref->{'market'}{'displayBid'} || 'NoBid'
$hashref->{'market'}{'displayBid'}
Truth table50%1/2
A
A= $hashref->{'market'}{'displayBid'}
Aresult
11
00
114 2 ▶ $self->{offer} = $hashref->{'market'}->{'displayOffer'} || 'NoOffer';
Condition50%1/2
$hashref->{'market'}{'displayOffer'} || 'NoOffer'
l!l
20
MC/DC0%0/1
$hashref->{'market'}{'displayOffer'} || 'NoOffer'
$hashref->{'market'}{'displayOffer'}
Truth table50%1/2
A
A= $hashref->{'market'}{'displayOffer'}
Aresult
11
00
115 2 ▶ $self->{size} = $hashref->{'position'}->{'dealSize'} || undef;
Condition50%1/2
$hashref->{'position'}{'dealSize'} || undef
l!l
20
MC/DC0%0/1
$hashref->{'position'}{'dealSize'} || undef
$hashref->{'position'}{'dealSize'}
Truth table50%1/2
A
A= $hashref->{'position'}{'dealSize'}
Aresult
11
00
116 }
117 ▶ elsif (exists $hashref->{'order'}
Condition0%0/6
exists $hashref->{"order"} and exists $hashref->{"instrument"} and $hashref->{"marketSnapshot"}
!ll&&!rl&&r
000
exists $hashref->{"order"} and exists $hashref->{"instrument"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $hashref->{"order"} and exists $hashref->{"instrument"} and $hashref->{"marketSnapshot"}
exists $hashref->{"order"} exists $hashref->{"instrument"} $hashref->{"marketSnapshot"}
Truth table0%0/4
A and B and C
A= exists $hashref->{"order"}B= exists $hashref->{"instrument"}C= $hashref->{"marketSnapshot"}
ABCresult
0XX0
10X0
1100
1111
118 && exists $hashref->{'instrument'}
119 && $hashref->{'marketSnapshot'} )
120 {
121 0 ▶ $self->{direction} = $hashref->{'order'}->{'direction'} || undef;
Condition0%0/2
$hashref->{'order'}{'direction'} || undef
l!l
00
MC/DC0%0/1
$hashref->{'order'}{'direction'} || undef
$hashref->{'order'}{'direction'}
Truth table0%0/2
A
A= $hashref->{'order'}{'direction'}
Aresult
11
00
122 0 ▶ $self->{price} = $hashref->{'order'}->{'openingLevel'} || undef;
Condition0%0/2
$hashref->{'order'}{'openingLevel'} || undef
l!l
00
MC/DC0%0/1
$hashref->{'order'}{'openingLevel'} || undef
$hashref->{'order'}{'openingLevel'}
Truth table0%0/2
A
A= $hashref->{'order'}{'openingLevel'}
Aresult
11
00
123 0 ▶ $self->{id} = $hashref->{'order'}->{'id'} || undef;
Condition0%0/2
$hashref->{'order'}{'id'} || undef
l!l
00
MC/DC0%0/1
$hashref->{'order'}{'id'} || undef
$hashref->{'order'}{'id'}
Truth table0%0/2
A
A= $hashref->{'order'}{'id'}
Aresult
11
00
124 0 ▶ $self->{epic} = $hashref->{'instrument'}->{'epic'} || undef;
Condition0%0/2
$hashref->{'instrument'}{'epic'} || undef
l!l
00
MC/DC0%0/1
$hashref->{'instrument'}{'epic'} || undef
$hashref->{'instrument'}{'epic'}
Truth table0%0/2
A
A= $hashref->{'instrument'}{'epic'}
Aresult
11
00
125 0 ▶ $self->{contract} = $hashref->{'instrument'}->{'marketName'} || undef;
Condition0%0/2
$hashref->{'instrument'}{'marketName'} || undef
l!l
00
MC/DC0%0/1
$hashref->{'instrument'}{'marketName'} || undef
$hashref->{'instrument'}{'marketName'}
Truth table0%0/2
A
A= $hashref->{'instrument'}{'marketName'}
Aresult
11
00
126 0 ▶ $self->{bid} = $hashref->{'marketSnapshot'}->{'displayBid'} || 'NoBid';
Condition0%0/2
$hashref->{'marketSnapshot'}{'displayBid'} || 'NoBid'
l!l
00
MC/DC0%0/1
$hashref->{'marketSnapshot'}{'displayBid'} || 'NoBid'
$hashref->{'marketSnapshot'}{'displayBid'}
Truth table0%0/2
A
A= $hashref->{'marketSnapshot'}{'displayBid'}
Aresult
11
00
127 $self->{offer} =
128 0 ▶ $hashref->{'marketSnapshot'}->{'displayOffer'} || 'NoOffer';
Condition0%0/2
$hashref->{'marketSnapshot'}{'displayOffer'} || 'NoOffer'
l!l
00
MC/DC0%0/1
$hashref->{'marketSnapshot'}{'displayOffer'} || 'NoOffer'
$hashref->{'marketSnapshot'}{'displayOffer'}
Truth table0%0/2
A
A= $hashref->{'marketSnapshot'}{'displayOffer'}
Aresult
11
00
129 0 ▶ $self->{size} = $hashref->{'order'}->{'size'} || undef;
Condition0%0/2
$hashref->{'order'}{'size'} || undef
l!l
00
MC/DC0%0/1
$hashref->{'order'}{'size'} || undef
$hashref->{'order'}{'size'}
Truth table0%0/2
A
A= $hashref->{'order'}{'size'}
Aresult
11
00
130 }
131 0 else { return undef }
132  
133 2 return bless $self, __PACKAGE__;
134 }
135  
136 =head1 NAME
137  
138 Finance::Nadex::Position - Retrieve details about an open position(a filled order) on the North American Derivatives Exchange
139  
140 =head1 VERSION
141  
142 Version 0.01
143  
144 =cut
145  
146 14 our $VERSION = '0.01';
147  
148 =head1 SYNOPSIS
149  
150 Container for information about positions; used by L<Finance::Nadex>; not meant to be instantiated
151 directly in client code; certain methods in L<Finance::Nadex> return an instance or list of Finance::Nadex::Position
152 objects; given an instance of Finance::Nadex::Position, the following methods can be used to access
153 information in the instance; see L<Finance::Nadex> for information on the methods used to retrieve positions
154  
155 =head1 ACCESSORS
156  
157 =head2 bid
158  
159 Retrieves the current high bid for the contract
160  
161 =head2 contract
162  
163 Retrieves the name of the contract
164  
165 =head2 direction
166  
167 Retrieves the direction of the position: either 'buy' or 'sell'
168  
169 =head2 epic
170  
171 Retrieves the unique identifier for the contract associated with the position
172  
173 =head2 id
174  
175 The id created by the exchange for the position
176  
177 =head2 offer
178  
179 Retrieves the current low offer for the contract
180  
181 =head2 price
182  
183 Retrieves the price level at which the position was entered (either bought or sold)
184  
185 =head2 size
186  
187 Retrieves the number of contracts bought or sold to create the position
188  
189  
190 =head1 AUTHOR
191  
192 mhandisi, C<< <mhandisi at cpan.org> >>
193  
194 =head1 BUGS
195  
196 Please report any bugs or feature requests to C<bug-nadex-api at rt.cpan.org>, or through
197 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Nadex-API>. I will be notified, and then you'll
198 automatically be notified of progress on your bug as I make changes.
199  
200  
201  
202  
203 =head1 SUPPORT
204  
205 You can find documentation for this module with the perldoc command.
206  
207 perldoc Finance::Nadex::Position
208  
209  
210 You can also look for information at:
211  
212 =over 4
213  
214 =item * RT: CPAN's request tracker (report bugs here)
215  
216 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Nadex-API>
217  
218 =item * AnnoCPAN: Annotated CPAN documentation
219  
220 L<http://annocpan.org/dist/Nadex-API>
221  
222 =item * CPAN Ratings
223  
224 L<http://cpanratings.perl.org/d/Nadex-API>
225  
226 =item * Search CPAN
227  
228 L<http://search.cpan.org/dist/Nadex-API/>
229  
230 =back
231  
232  
233 =head1 ACKNOWLEDGEMENTS
234  
235  
236 =head1 LICENSE AND COPYRIGHT
237  
238 Copyright 2015 mhandisi.
239  
240 This program is free software; you can redistribute it and/or modify it
241 under the terms of the the Artistic License (2.0). You may obtain a
242 copy of the full license at:
243  
244 L<http://www.perlfoundation.org/artistic_license_2_0>
245  
246 Any use, modification, and distribution of the Standard or Modified
247 Versions is governed by this Artistic License. By using, modifying or
248 distributing the Package, you accept this license. Do not use, modify,
249 or distribute the Package, if you do not accept this license.
250  
251 If your Modified Version has been derived from a Modified Version made
252 by someone other than you, you are nevertheless required to ensure that
253 your Modified Version complies with the requirements of this license.
254  
255 This license does not grant you the right to use any trademark, service
256 mark, tradename, or logo of the Copyright Holder.
257  
258 This license includes the non-exclusive, worldwide, free-of-charge
259 patent license to make, have made, use, offer to sell, sell, import and
260 otherwise transfer the Package with respect to any patent claims
261 licensable by the Copyright Holder that are necessarily infringed by the
262 Package. If you institute patent litigation (including a cross-claim or
263 counterclaim) against any party alleging that the Package constitutes
264 direct or contributory patent infringement, then this Artistic License
265 to you shall terminate on the date that such litigation is filed.
266  
267 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
268 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
269 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
270 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
271 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
272 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
273 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
274 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
275  
276  
277 =cut
278  
279 14 42; # End of Finance::Nadex::Position
↑ Summary Nadex/Order.pm »