opentick/OTClient.pm

filter: Statementstmt 21.1% 36 / 170 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 11.2% 10 / 89 Podpod 100% 69 / 69 totaltotal 29.5% 115 / 389 CC 23 SCAR 21.0
CC
23
Cov
16%
initialize
56.0
_ot_on_data
42.0
_cancel_request
12.0
CRAP 8.2
↑ Summary opentick.pm »
1 package POE::Component::Client::opentick::OTClient;
2 #
3 # opentick.com POE client, otFeed Standard API facade class.
4 #
5 # infi/2008
6 #
7 # $Id: OTClient.pm 56 2009-01-08 16:51:14Z infidel $
8 #
9 # Full POD documentation after __END__
10 #
11  
12 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Time::HiRes qw( time );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # Ours.
21 1 ▶use POE::Component::Client::opentick::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use POE::Component::Client::opentick;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 ###
25 ### Variables
26 ###
27  
28 1 ▶use vars qw( $VERSION $TRUE $FALSE $poe_kernel );
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 1 ($VERSION) = q$Revision: 56 $ =~ /(\d+)/;
31 1 *TRUE = \1;
32 1 *FALSE = \0;
33  
34 1 my $dispatch_cmd = {
35 OTConstant( 'OT_REQUEST_LIST_EXCHANGES' ) => 'onListExchanges',
36 OTConstant( 'OT_REQUEST_LIST_SYMBOLS' ) => 'onListSymbols',
37 OTConstant( 'OT_REQUEST_LIST_SYMBOLS_EX' ) => 'onListSymbols',
38 OTConstant( 'OT_REQUEST_SPLITS' ) => 'onSplit',
39 OTConstant( 'OT_REQUEST_DIVIDENDS' ) => 'onDividend',
40 OTConstant( 'OT_REQUEST_OPTION_INIT' ) => 'onOptionInit',
41 OTConstant( 'OT_REQUEST_EQUITY_INIT' ) => 'onEquityInit',
42 OTConstant( 'OT_REQUEST_TICK_STREAM' ) => 'onRealtime',
43 OTConstant( 'OT_REQUEST_TICK_STREAM_EX' ) => 'onRealtime',
44 OTConstant( 'OT_REQUEST_TICK_SNAPSHOT' ) => 'onRealtime',
45 OTConstant( 'OT_REQUEST_HIST_DATA' ) => 'onHist',
46 OTConstant( 'OT_REQUEST_HIST_TICKS' ) => 'onHist',
47 OTConstant( 'OT_REQUEST_OPTION_CHAIN' ) => 'onRealtime',
48 OTConstant( 'OT_REQUEST_OPTION_CHAIN_EX' ) => 'onRealtime',
49 OTConstant( 'OT_REQUEST_BOOK_STREAM' ) => 'onBook',
50 OTConstant( 'OT_REQUEST_BOOK_STREAM_EX' ) => 'onBook',
51 OTConstant( 'OT_REQUEST_HIST_BOOKS' ) => 'onHistBook',
52 OTConstant( 'OT_REQUEST_OPTION_CHAIN' ) => 'onRealtime',
53 OTConstant( 'OT_REQUEST_OPTION_CHAIN_EX' ) => 'onRealtime',
54 OTConstant( 'OT_REQUEST_OPTION_CHAIN_U' ) => 'onRealtime',
55 OTConstant( 'OT_REQUEST_OPTION_CHAIN_SNAPSHOT' ) => 'onRealtime',
56 };
57  
58 1 my $dispatch_dt = {
59 OTConstant( 'OT_DATATYPE_QUOTE' ) => 'Quote',
60 OTConstant( 'OT_DATATYPE_MMQUOTE' ) => 'MMQuote',
61 OTConstant( 'OT_DATATYPE_TRADE' ) => 'Trade',
62 OTConstant( 'OT_DATATYPE_BBO' ) => 'BBO',
63 OTConstant( 'OT_DATATYPE_OHLC' ) => 'OHLC',
64 OTConstant( 'OT_DATATYPE_CANCEL' ) => 'Cancel',
65 OTConstant( 'OT_DATATYPE_CHANGE' ) => 'Change',
66 OTConstant( 'OT_DATATYPE_DELETE' ) => 'Delete',
67 OTConstant( 'OT_DATATYPE_EXECUTE' ) => 'Execute',
68 OTConstant( 'OT_DATATYPE_ORDER' ) => 'Order',
69 OTConstant( 'OT_DATATYPE_PRICELEVEL' ) => 'PriceLevel',
70 OTConstant( 'OT_DATATYPE_PURGE' ) => 'Purge',
71 OTConstant( 'OT_DATATYPE_REPLACE' ) => 'Replace',
72 OTConstant( 'OT_DATATYPE_OHL_TODAY' ) => 'onTodaysOHL',
73 };
74  
75 ########################################################################
76 ### Public methods ###
77 ########################################################################
78  
79 # Create the object
80 sub new
81 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
82 0 my( $class, $username, $password, @args ) = @_;
83 0 ▶ croak( "$class requires an even number of parameters" ) if( @args & 1 );
Branch: 1 branch
BranchTrueFalseTotal
if @args & 1 0 0 0
84  
85 # Set our default variables
86 0 my $self = {
87 alias => 'otFeed-' . time, # our alias
88 opentick => undef, # opentick object
89 session_id => undef, # POE session pointer
90 requests => {}, # outstanding requests
91 hosts => [], # host list
92 };
93  
94 0 bless( $self, $class );
95  
96 0 $self->initialize( $username, $password, @args );
97  
98 0 return( $self );
99 }
100  
101 # Initialize this object instance
102 sub initialize
103 0 ▶{
Subroutine initialize: not called CC=7 SCAR=40.3
Pod documented
104 0 my( $self, $username, $password, %args ) = @_;
105  
106 $args{username} = $username or $ENV{OPENTICK_USER} or
107 0 ▶ croak( "OTClient requires a \$username argument" );
Branch: 1 branch
BranchTrueFalseTotal
$args{"username"} = $username or $ENV{"OPENTICK_USER"} or croak("OTClient requires a \$username argument") 0 0 0
Condition0%0/3
$args{"username"} = $username or $ENV{"OPENTICK_USER"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"username"} = $username or $ENV{"OPENTICK_USER"}
$args{"username"} = $username $ENV{"OPENTICK_USER"}
Truth table0%0/3
A or B
A= $args{"username"} = $usernameB= $ENV{"OPENTICK_USER"}
ABresult
1X1
011
000
108 $args{password} = $password or $ENV{OPENTICK_PASS} or
109 0 ▶ croak( "OTClient requires a \$password argument" );
Branch: 1 branch
BranchTrueFalseTotal
$args{"password"} = $password or $ENV{"OPENTICK_PASS"} or croak("OTClient requires a \$password argument") 0 0 0
Condition0%0/3
$args{"password"} = $password or $ENV{"OPENTICK_PASS"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"password"} = $password or $ENV{"OPENTICK_PASS"}
$args{"password"} = $password $ENV{"OPENTICK_PASS"}
Truth table0%0/3
A or B
A= $args{"password"} = $passwordB= $ENV{"OPENTICK_PASS"}
ABresult
1X1
011
000
110  
111 0 ▶ $self->{hosts} = $args{Hosts} if( $args{Hosts} );
Branch: 1 branch
BranchTrueFalseTotal
if $args{"Hosts"} 0 0 0
112 0 ▶ $self->{hosts} = $args{hosts} if( $args{hosts} );
Branch: 1 branch
BranchTrueFalseTotal
if $args{"hosts"} 0 0 0
113  
114 # Create our own POE session here
115 0 $self->{session_id} = POE::Session->create(
116 object_states => [
117 $self => {
118 _start => '_poe_started',
119 ot_on_login => '_ot_on_login',
120 ot_status_changed => '_ot_status_changed',
121 ot_on_data => '_ot_on_data',
122 ot_on_error => '_ot_on_error',
123 ot_request_complete => '_ot_request_complete',
124 ot_request_cancelled => '_ot_request_cancelled',
125 # Not needed for this interface.
126 # ot_connect_failed => '_ot_connect_failed',
127 # ot_on_logout => '_ot_on_logout',
128 },
129 ],
130 heap => $self,
131 )->ID();
132  
133 # Create main object POE session here, passing args along
134 $self->{opentick} = POE::Component::Client::opentick->spawn(
135 Notifyee => $self->{alias}, # our alias
136 0 Events => [ 'all' ], # events to catch
137 ReconnRetries => 0, # unlimited
138 # Debug => 1, # TALK LOTS
139 Quiet => 1, # Hush.
140 AutoLogin => 0, # manual login.
141 %args,
142 );
143  
144 0 $self->startup();
145  
146 0 return;
147 }
148  
149 #######################################################################
150 ### otFeed Standard API methods ###
151 #######################################################################
152  
153 sub requestTickStream
154 0 ▶{
Subroutine requestTickStream: not called CC=1 SCAR=6.9
Pod documented
155 0 my( $self, @args ) = @_;
156  
157 0 return( $self->_issue_request( 'requestTickStreamEx', @args ) );
158 }
159  
160 sub requestBookStream
161 0 ▶{
Subroutine requestBookStream: not called CC=2 SCAR=17.9
Pod documented
162 0 my( $self, $exch, $sym, $mask ) = @_;
163  
164 0 ▶ my $req_id = $mask
Branch: 1 branch
BranchTrueFalseTotal
$mask ? : 0 0 0
165 ? $self->_issue_request( 'requestBookStreamEx', $exch, $sym, $mask )
166 : $self->_issue_request( 'requestBookStream', $exch, $sym );
167  
168 0 return( $req_id );
169 }
170  
171 # Duplicates functionality from API interface
172 sub requestMarketDepth
173 0 ▶{
Subroutine requestMarketDepth: not called CC=2 SCAR=17.9
Pod documented
174 0 my( $self, $exch, $sym ) = @_;
175  
176 0 my $book_exchanges = { ar => 1, at => 1, br => 1, bt => 1,
177 is => 1, no => 1, cm => 1, em => 1,
178 ct => 1, ec => 1 };
179  
180 0 ▶ if( exists( $book_exchanges->{$exch} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $book_exchanges->{$exch}) { } 0 0 0
181 {
182 0 return( $self->_issue_request( 'requestBookStream', $exch, $sym ) );
183 }
184 else
185 {
186 0 return( $self->_issue_request( 'requestTickStreamEx', $exch, $sym,
187 OTConstant( 'OT_TICK_TYPE_LEVEL2' ) ) );
188 }
189 }
190  
191 sub requestOptionChain
192 0 ▶{
Subroutine requestOptionChain: not called CC=1 SCAR=6.9
Pod documented
193 0 my( $self, @args ) = @_;
194  
195 0 return( $self->_issue_request( 'requestOptionChainEx', @args ) );
196 }
197  
198 sub requestEquityInit
199 0 ▶{
Subroutine requestEquityInit: not called CC=1 SCAR=6.9
Pod documented
200 0 my( $self, @args ) = @_;
201  
202 0 return( $self->_issue_request( 'requestEqInit', @args ) );
203 }
204  
205 sub requestHistData
206 0 ▶{
Subroutine requestHistData: not called CC=1 SCAR=6.9
Pod documented
207 0 my( $self, @args ) = @_;
208  
209 0 return( $self->_issue_request( 'requestHistData', @args ) );
210 }
211  
212 sub requestHistTicks
213 0 ▶{
Subroutine requestHistTicks: not called CC=1 SCAR=6.9
Pod documented
214 0 my( $self, @args ) = @_;
215  
216 0 return( $self->_issue_request( 'requestHistTicks', @args ) );
217 }
218  
219 sub requestTodaysOHL
220 0 ▶{
Subroutine requestTodaysOHL: not called CC=1 SCAR=6.9
Pod documented
221 0 my( $self, $exchange, $symbol ) = @_;
222  
223 0 return( $self->_issue_request( 'requestHistData',
224 $exchange,
225 $symbol,
226 0,
227 0,
228 OTConstant( 'OT_HIST_OHL_TODAY' ),
229 0,
230 ) );
231  
232 0 return;
233 }
234  
235 # Don't store a request id
236 sub requestListExchanges
237 0 ▶{
Subroutine requestListExchanges: not called CC=1 SCAR=6.9
Pod documented
238 0 my( $self, @args ) = @_;
239  
240 0 $self->{opentick}->yield( 'requestListExchanges', @args );
241  
242 0 return;
243 }
244  
245 # Don't store a request id
246 sub requestListSymbols
247 0 ▶{
Subroutine requestListSymbols: not called CC=1 SCAR=6.9
Pod documented
248 0 my( $self, @args ) = @_;
249  
250 0 $self->{opentick}->yield( 'requestListSymbolsEx', @args );
251  
252 0 return;
253 }
254  
255 sub requestHistBooks
256 0 ▶{
Subroutine requestHistBooks: not called CC=1 SCAR=6.9
Pod documented
257 0 my( $self, @args ) = @_;
258  
259 0 return( $self->_issue_request( 'requestHistBooks', @args ) );
260 }
261  
262 sub requestOptionInit
263 0 ▶{
Subroutine requestOptionInit: not called CC=1 SCAR=6.9
Pod documented
264 0 my( $self, @args ) = @_;
265  
266 0 return( $self->_issue_request( 'requestOptionInit', @args ) );
267 }
268  
269 sub requestSplits
270 0 ▶{
Subroutine requestSplits: not called CC=1 SCAR=6.9
Pod documented
271 0 my( $self, @args ) = @_;
272  
273 0 return( $self->_issue_request( 'requestSplits', @args ) );
274 }
275  
276 sub requestDividends
277 0 ▶{
Subroutine requestDividends: not called CC=1 SCAR=6.9
Pod documented
278 0 my( $self, @args ) = @_;
279  
280 0 return( $self->_issue_request( 'requestDividends', @args ) );
281 }
282  
283 sub requestTickSnapshot
284 0 ▶{
Subroutine requestTickSnapshot: not called CC=2 SCAR=17.9
Pod documented
285 0 my( $self, $exch, $sym, $mask ) = @_;
286  
287 0 ▶ $mask ||= OTConstant( 'OT_MASK_TYPE_QUOTE' ) |
Condition0%0/3
$mask ||= OTConstant("OT_MASK_TYPE_QUOTE") | OTConstant("OT_MASK_TYPE_MMQUOTE") | OTConstant("OT_MASK_TYPE_TRADE") | OTConstant("OT_MASK_TYPE_BBO")
l!l&&r!l&&!r
000
MC/DC0%0/2
$mask ||= OTConstant("OT_MASK_TYPE_QUOTE") | OTConstant("OT_MASK_TYPE_MMQUOTE") | OTConstant("OT_MASK_TYPE_TRADE") | OTConstant("OT_MASK_TYPE_BBO")
$mask OTConstant("OT_MASK_TYPE_QUOTE") | OTConstant("OT_MASK_TYPE_MMQUOTE") | OTConstant("OT_MASK_TYPE_TRADE") | OTConstant("OT_MASK_TYPE_BBO")
Truth table0%0/3
A ||= B
A= $maskB= OTConstant("OT_MASK_TYPE_QUOTE") | OTConstant("OT_MASK_TYPE_MMQUOTE") | OTConstant("OT_MASK_TYPE_TRADE") | OTConstant("OT_MASK_TYPE_BBO")
ABresult
1X1
011
000
288 OTConstant( 'OT_MASK_TYPE_MMQUOTE' ) |
289 OTConstant( 'OT_MASK_TYPE_TRADE' ) |
290 OTConstant( 'OT_MASK_TYPE_BBO' );
291  
292 0 return( $self->_issue_request( 'requestTickSnapshot', $exch, $sym, $mask ));
293 }
294  
295 sub requestOptionChainSnapshot
296 0 ▶{
Subroutine requestOptionChainSnapshot: not called CC=1 SCAR=6.9
Pod documented
297 0 my( $self, @args ) = @_;
298  
299 0 return( $self->_issue_request( 'requestOptionChainSnapshot', @args ) );
300 }
301  
302 # Cancellation
303 sub cancelTickStream
304 0 ▶{
Subroutine cancelTickStream: not called CC=1 SCAR=6.9
Pod documented
305 0 my( $self, $req_id ) = @_;
306  
307 0 return( $self->_cancel_request( 'cancelTickStream', $req_id ) );
308 }
309  
310 sub cancelOptionChain
311 0 ▶{
Subroutine cancelOptionChain: not called CC=1 SCAR=6.9
Pod documented
312 0 my( $self, $req_id ) = @_;
313  
314 0 return( $self->_cancel_request( 'cancelOptionChain', $req_id ) );
315 }
316  
317 sub cancelBookStream
318 0 ▶{
Subroutine cancelBookStream: not called CC=1 SCAR=6.9
Pod documented
319 0 my( $self, $req_id ) = @_;
320  
321 0 return( $self->_cancel_request( 'cancelBookStream', $req_id ) );
322 }
323  
324 sub cancelMarketDepth
325 0 ▶{
Subroutine cancelMarketDepth: not called CC=1 SCAR=6.9
Pod documented
326 0 my( $self, $req_id ) = @_;
327  
328 # leave command undef, and let _cancel_request resolve it.
329 0 return( $self->_cancel_request( undef, $req_id ) );
330 }
331  
332 sub cancelHistData
333 0 ▶{
Subroutine cancelHistData: not called CC=1 SCAR=6.9
Pod documented
334 0 my( $self, $req_id ) = @_;
335  
336 0 return( $self->_cancel_request( 'cancelHistData', $req_id ) );
337 }
338  
339 ########################################################################
340 ### otFeed Standard API Auxiliary Functions ###
341 ########################################################################
342  
343 # Halfassed workaround.
344 sub addHost
345 0 ▶{
Subroutine addHost: not called CC=2 SCAR=17.9
Pod documented
346 0 my( $self, $host, $port ) = @_;
347  
348 0 push( @{ $self->{hosts} }, $host );
349 0 $self->{opentick}->set_hosts( $self->{hosts} );
350 0 ▶ $self->{opentick}->set_port( $port ) if( $port );
Branch: 1 branch
BranchTrueFalseTotal
if $port 0 0 0
351  
352 0 return;
353 }
354  
355 # Halfassed workaround.
356 sub clearHosts
357 0 ▶{
Subroutine clearHosts: not called CC=1 SCAR=6.9
Pod documented
358 0 my( $self ) = @_;
359  
360 0 $self->{hosts} = [];
361 0 $self->{opentick}->set_hosts( $self->{hosts} );
362  
363 0 return;
364 }
365  
366 sub login
367 0 ▶{
Subroutine login: not called CC=1 SCAR=6.9
Pod documented
368 0 my( $self ) = @_;
369  
370 0 $self->{opentick}->call( 'connect' );
371  
372 0 return;
373 }
374  
375 sub logout
376 0 ▶{
Subroutine logout: not called CC=1 SCAR=6.9
Pod documented
377 0 my( $self ) = @_;
378  
379 0 $self->{opentick}->call( 'disconnect' );
380  
381 0 return;
382 }
383  
384 sub isLoggedIn
385 0 ▶{
Subroutine isLoggedIn: not called CC=1 SCAR=6.9
Pod documented
386 0 my( $self ) = @_;
387  
388 0 return( $self->{opentick}->ready() );
389 }
390  
391 sub getStatus
392 0 ▶{
Subroutine getStatus: not called CC=1 SCAR=6.9
Pod documented
393 0 my( $self ) = @_;
394  
395 0 return( $self->{opentick}->get_status() );
396 }
397  
398 sub setPlatformId
399 0 ▶{
Subroutine setPlatformId: not called CC=1 SCAR=6.9
Pod documented
400 0 my( $self, $id, $pass ) = @_;
401  
402 0 $self->{opentick}->set_platform_id( $id, $pass );
403  
404 0 return;
405 }
406  
407 sub getEntityById
408 0 ▶{
Subroutine getEntityById: not called CC=1 SCAR=6.9
Pod documented
409 0 my( $self, $req_id ) = @_;
410  
411 0 my $req = $self->{requests}->{$req_id};
412 0 my $exchange = $req->{exchange};
413 0 my $symbol = $req->{symbol};
414  
415 0 return( $exchange, $symbol );
416 }
417  
418 ########################################################################
419 ### Event Handlers ###
420 ########################################################################
421  
422 ### NOTE: These do nothing by default. You are to subclass this module
423 # and override these methods to do something useful in your
424 # application.
425  
426 # Local extension
427 0 ▶sub startup {}
Subroutine startup: not called CC=1 SCAR=0.0
Pod documented
428  
429 # From API
430 0 ▶sub onLogin {}
Subroutine onLogin: not called CC=1 SCAR=0.0
Pod documented
431 0 ▶sub onRestoreConnection {}
Subroutine onRestoreConnection: not called CC=1 SCAR=0.0
Pod documented
432 0 ▶sub onStatusChanged {}
Subroutine onStatusChanged: not called CC=1 SCAR=0.0
Pod documented
433 0 ▶sub onError {}
Subroutine onError: not called CC=1 SCAR=0.0
Pod documented
434 0 ▶sub onMessage {}
Subroutine onMessage: not called CC=1 SCAR=0.0
Pod documented
435 0 ▶sub onListExchanges {}
Subroutine onListExchanges: not called CC=1 SCAR=0.0
Pod documented
436 0 ▶sub onListSymbols {}
Subroutine onListSymbols: not called CC=1 SCAR=0.0
Pod documented
437 0 ▶sub onRealtimeTrade {}
Subroutine onRealtimeTrade: not called CC=1 SCAR=0.0
Pod documented
438 0 ▶sub onRealtimeQuote {}
Subroutine onRealtimeQuote: not called CC=1 SCAR=0.0
Pod documented
439 0 ▶sub onRealtimeBBO {}
Subroutine onRealtimeBBO: not called CC=1 SCAR=0.0
Pod documented
440 0 ▶sub onRealtimeMMQuote {}
Subroutine onRealtimeMMQuote: not called CC=1 SCAR=0.0
Pod documented
441 0 ▶sub onTodaysOHL {}
Subroutine onTodaysOHL: not called CC=1 SCAR=0.0
Pod documented
442 0 ▶sub onEquityInit {}
Subroutine onEquityInit: not called CC=1 SCAR=0.0
Pod documented
443 0 ▶sub onBookCancel {}
Subroutine onBookCancel: not called CC=1 SCAR=0.0
Pod documented
444 0 ▶sub onBookChange {}
Subroutine onBookChange: not called CC=1 SCAR=0.0
Pod documented
445 0 ▶sub onBookDelete {}
Subroutine onBookDelete: not called CC=1 SCAR=0.0
Pod documented
446 0 ▶sub onBookExecute {}
Subroutine onBookExecute: not called CC=1 SCAR=0.0
Pod documented
447 0 ▶sub onBookOrder {}
Subroutine onBookOrder: not called CC=1 SCAR=0.0
Pod documented
448 0 ▶sub onBookPriceLevel {}
Subroutine onBookPriceLevel: not called CC=1 SCAR=0.0
Pod documented
449 0 ▶sub onBookPurge {}
Subroutine onBookPurge: not called CC=1 SCAR=0.0
Pod documented
450 0 ▶sub onBookReplace {}
Subroutine onBookReplace: not called CC=1 SCAR=0.0
Pod documented
451 0 ▶sub onHistQuote {}
Subroutine onHistQuote: not called CC=1 SCAR=0.0
Pod documented
452 0 ▶sub onHistMMQuote {}
Subroutine onHistMMQuote: not called CC=1 SCAR=0.0
Pod documented
453 0 ▶sub onHistTrade {}
Subroutine onHistTrade: not called CC=1 SCAR=0.0
Pod documented
454 0 ▶sub onHistBBO {}
Subroutine onHistBBO: not called CC=1 SCAR=0.0
Pod documented
455 0 ▶sub onHistOHLC {}
Subroutine onHistOHLC: not called CC=1 SCAR=0.0
Pod documented
456 0 ▶sub onHistBookCancel {}
Subroutine onHistBookCancel: not called CC=1 SCAR=0.0
Pod documented
457 0 ▶sub onHistBookChange {}
Subroutine onHistBookChange: not called CC=1 SCAR=0.0
Pod documented
458 0 ▶sub onHistBookDelete {}
Subroutine onHistBookDelete: not called CC=1 SCAR=0.0
Pod documented
459 0 ▶sub onHistBookExecute {}
Subroutine onHistBookExecute: not called CC=1 SCAR=0.0
Pod documented
460 0 ▶sub onHistBookOrder {}
Subroutine onHistBookOrder: not called CC=1 SCAR=0.0
Pod documented
461 0 ▶sub onHistBookPriceLevel {}
Subroutine onHistBookPriceLevel: not called CC=1 SCAR=0.0
Pod documented
462 0 ▶sub onHistBookPurge {}
Subroutine onHistBookPurge: not called CC=1 SCAR=0.0
Pod documented
463 0 ▶sub onHistBookReplace {}
Subroutine onHistBookReplace: not called CC=1 SCAR=0.0
Pod documented
464 0 ▶sub onSplit {}
Subroutine onSplit: not called CC=1 SCAR=0.0
Pod documented
465 0 ▶sub onDividend {}
Subroutine onDividend: not called CC=1 SCAR=0.0
Pod documented
466 0 ▶sub onOptionInit {}
Subroutine onOptionInit: not called CC=1 SCAR=0.0
Pod documented
467  
468 ########################################################################
469 ### Private methods ###
470 ########################################################################
471  
472 sub _issue_request
473 0 ▶{
Subroutine _issue_request: not called CC=1 SCAR=6.9
474 0 my( $self, $command, @args ) = @_;
475  
476 # Call opentick to issue the request and get a ReqID
477 0 my $req_id = $self->{opentick}->call( $command, @args );
478  
479 # Stash the ReqID and issue time
480 0 $self->{requests}->{$req_id} = {
481 cmd_id => OTAPItoCommand( $command ),
482 stamp => time,
483 # FIXME: These won't always be valid; will fix later.
484 exchange => $args[0],
485 symbol => $args[1],
486 };
487  
488 0 return( $req_id );
489 }
490  
491 sub _cancel_request
492 0 ▶{
Subroutine _cancel_request: not called CC=3 SCAR=24.8
493 0 my( $self, $command, $req_id ) = @_;
494  
495 # Resolve command for requestMarketDepth
496 $command =
497 0 ▶ OTCommandtoAPI( OTCanceller( $self->{requests}->{$req_id}->{cmd_id} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless $command 0 0 0
498 unless( $command );
499  
500 # Just return boolean; handle req deletion in _ot_on_data
501 0 ▶ return( $self->{opentick}->call( $command, $req_id ) ? $TRUE : $FALSE );
Branch: 1 branch
BranchTrueFalseTotal
$self->{'opentick'}->call($command, $req_id) ? : 0 0 0
502 }
503  
504 sub _delete_request
505 0 ▶{
Subroutine _delete_request: not called CC=1 SCAR=6.9
506 0 my( $self, $req_id ) = @_;
507  
508 0 return( delete( $self->{requests}->{$req_id} ) );
509 }
510  
511 ########################################################################
512 ### POE event handlers ###
513 ########################################################################
514  
515 # Happens very early, so we'll call started() from initialize() instead.
516 sub _poe_started
517 0 ▶{
Subroutine _poe_started: not called CC=1 SCAR=6.9
518 0 my( $self ) = @_;
519  
520 0 $poe_kernel->alias_set( $self->{alias} );
521  
522 0 return;
523 }
524  
525 sub _ot_on_login
526 0 ▶{
Subroutine _ot_on_login: not called CC=3 SCAR=24.8
527 0 my( $self ) = @_;
528  
529 0 my( $wasloggedin ) = $self->{wasloggedin};
530 0 $self->{wasloggedin} = $TRUE;
531  
532 # Why do there need to be two of these? The semantics are confused.
533 0 ▶ $wasloggedin && $self->onRestoreConnection() || $self->onLogin();
Branch: 1 branch
BranchTrueFalseTotal
$wasloggedin and $self->onRestoreConnection or $self->onLogin 0 0 0
Condition0%0/3
$wasloggedin and $self->onRestoreConnection
!ll&&!rl&&r
000
MC/DC0%0/2
$wasloggedin and $self->onRestoreConnection
$wasloggedin $self->onRestoreConnection
Truth table0%0/3
A and B
A= $wasloggedinB= $self->onRestoreConnection
ABresult
0X0
100
111
534  
535 0 return;
536 }
537  
538 sub _ot_status_changed
539 0 ▶{
Subroutine _ot_status_changed: not called CC=1 SCAR=6.9
540 0 my( $self, $state ) = @_[OBJECT,ARG0];
541  
542 0 $self->onStatusChanged( $state );
543  
544 0 return;
545 }
546  
547 # Dispatch to the appropriate request handler.
548 sub _ot_on_data
549 0 ▶{
Subroutine _ot_on_data: not called CC=6 SCAR=37.4
550 0 my( $self, $req_id, $cmd_id, $object ) = @_[OBJECT,ARG0..ARG2];
551  
552 0 ▶ return unless( ref( $object ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $object 0 0 0
553 0 my $datatype = $object->get_datatype();
554  
555 # Ugly as sin. Works like a charm.
556 0 my $method;
557 0 ▶ if( ( $datatype >= OTConstant('OT_DATATYPE_QUOTE') &&
Branch: 2 branches
BranchTrueFalseTotal
if ($datatype >= OTConstant('OT_DATATYPE_QUOTE') and $datatype <= OTConstant('OT_DATATYPE_REPLACE') or $datatype == OTConstant('OT_DATATYPE_OHLC')) { } 0 0 0
elsif ($datatype == OTConstant('OT_DATATYPE_OHL_TODAY')) { } 0 0 0
Condition0%0/6
$datatype >= OTConstant("OT_DATATYPE_QUOTE") and $datatype <= OTConstant("OT_DATATYPE_REPLACE") or $datatype == OTConstant("OT_DATATYPE_OHLC")
l!l&&r!l&&!r
000
$datatype >= OTConstant("OT_DATATYPE_QUOTE") and $datatype <= OTConstant("OT_DATATYPE_REPLACE")
!ll&&!rl&&r
000
MC/DC0%0/3
$datatype >= OTConstant("OT_DATATYPE_QUOTE") and $datatype <= OTConstant("OT_DATATYPE_REPLACE") or $datatype == OTConstant("OT_DATATYPE_OHLC")
$datatype >= OTConstant("OT_DATATYPE_QUOTE") $datatype <= OTConstant("OT_DATATYPE_REPLACE") $datatype == OTConstant("OT_DATATYPE_OHLC")
Truth table0%0/5
A and B or C
A= $datatype >= OTConstant("OT_DATATYPE_QUOTE")B= $datatype <= OTConstant("OT_DATATYPE_REPLACE")C= $datatype == OTConstant("OT_DATATYPE_OHLC")
ABCresult
11X1
0X11
1011
0X00
1000
558 $datatype <= OTConstant('OT_DATATYPE_REPLACE') ) ||
559 $datatype == OTConstant('OT_DATATYPE_OHLC') )
560 {
561 0 $method = $dispatch_cmd->{ $cmd_id } . $dispatch_dt->{ $datatype };
562 }
563 elsif( $datatype == OTConstant( 'OT_DATATYPE_OHL_TODAY' ) )
564 {
565 0 $method = $dispatch_dt->{ $datatype };
566 }
567 else
568 {
569 0 $method = $dispatch_cmd->{ $cmd_id };
570 }
571  
572 0 $self->$method( $req_id, $cmd_id, $object );
573  
574 0 return;
575 }
576  
577 sub _ot_on_error
578 0 ▶{
Subroutine _ot_on_error: not called CC=1 SCAR=6.9
579 0 my( $self, @args ) = @_[OBJECT,ARG0..$#_];
580  
581 0 $self->onError( @args );
582  
583 0 return;
584 }
585  
586 sub _ot_request_complete
587 0 ▶{
Subroutine _ot_request_complete: not called CC=2 SCAR=17.9
588 0 my( $self, $req_id, $cmd_id, $obj ) = @_[OBJECT,ARG0..$#_];
589  
590 0 ▶ $self->_delete_request( $req_id ) if( $req_id );
Branch: 1 branch
BranchTrueFalseTotal
if $req_id 0 0 0
591  
592 0 $self->onMessage( $req_id,
593 $cmd_id,
594 OTConstant( 'OT_MSG_END_OF_DATA' ),
595 "Request $req_id completed." );
596  
597 0 return;
598 }
599  
600 sub _ot_request_cancelled
601 0 ▶{
Subroutine _ot_request_cancelled: not called CC=2 SCAR=17.9
602 0 my( $self, $req_id, $cmd_id, $obj ) = @_[OBJECT,ARG0..$#_];
603  
604 0 ▶ $self->_delete_request( $req_id ) if( $req_id );
Branch: 1 branch
BranchTrueFalseTotal
if $req_id 0 0 0
605  
606 0 $self->onMessage( $req_id,
607 $cmd_id,
608 OTConstant( 'OT_MSG_END_OF_REQUEST' ),
609 "Request $req_id cancelled." );
610  
611 0 return;
612 }
613  
614 1 1;
615  
616 __END__
↑ Summary opentick.pm »