File Coverage

blib/lib/Finance/Nadex/Order.pm
Criterion Covered Total %
statement 44 62 70.9
branch 10 24 41.6
condition 10 47 21.2
subroutine 12 12 100.0
pod 8 8 100.0
total 84 153 54.9


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