| 1 | package Finance::IBrokers::MooseCallback; | ||
| 2 | |||
| 3 | 1 | ▶ | use 5.006; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | #use warnings FATAL => 'all'; | ||
| 7 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | Finance::IBrokers::MooseCallback - Moose implemention of the Interactive Brokers callback. | ||
| 12 | |||
| 13 | =head1 VERSION | ||
| 14 | |||
| 15 | Version 0.01 | ||
| 16 | |||
| 17 | =cut | ||
| 18 | |||
| 19 | our $VERSION = '0.02'; | ||
| 20 | |||
| 21 | =head1 SYNOPSIS | ||
| 22 | |||
| 23 | This is a Perl Moose implementation of the sample callback described at | ||
| 24 | http://search.cpan.org/~jstrauss/Finance-InteractiveBrokers-TWS-0.1.1/lib/Finance/InteractiveBrokers/TWS.pm#EXAMPLE | ||
| 25 | |||
| 26 | It provides variable names that are descriptive of what gets passed to each method. It is a generalization of code | ||
| 27 | I wrote for my own purposes. You will likely want to override it with your own methods. Updates are welcome. | ||
| 28 | |||
| 29 | Using this module is very similar to the sample described within Finance::InteractiveBrokers::TWS | ||
| 30 | |||
| 31 | use Finance::InteractiveBrokers; | ||
| 32 | use Finance::IBrokers::MooseCallback; | ||
| 33 | |||
| 34 | my $callback = Finance::IBrokers::MooseCallback->new(debug => 1); | ||
| 35 | my $tws = Finance::InteractiveBrokers::TWS->new($callback); | ||
| 36 | |||
| 37 | my $tick_type = $tws->TickType->new(); | ||
| 38 | $callback->{tickType} = $tick_type; | ||
| 39 | |||
| 40 | # Host Port Client_ID | ||
| 41 | # ---- ---- --------- | ||
| 42 | my @tws_GUI_location = qw/ 127.0.0.1 7496 15 /; | ||
| 43 | |||
| 44 | $tws->eclient->eConnect(@tws_GUI_location); | ||
| 45 | |||
| 46 | do { $tws->read_messages_for_x_sec() } until $tws->eclient->isConnected(); | ||
| 47 | |||
| 48 | my $orderid = $callback->getNextID; # For the next ID available | ||
| 49 | |||
| 50 | # Create a contract | ||
| 51 | # | ||
| 52 | my $contract = $tws->Contract->new(); | ||
| 53 | |||
| 54 | ... | ||
| 55 | |||
| 56 | $tws->eclient->reqContractDetails( '1', $contract ); | ||
| 57 | |||
| 58 | |||
| 59 | do { | ||
| 60 | $tws->read_messages_for_x_sec(); | ||
| 61 | } until ( defined $callback->get_contractDetailsRequest() && $callback->get_contractDetailsRequest('1')->{Status} eq 'Complete' ); | ||
| 62 | |||
| 63 | warn Dumper( $callback->contractDetailsRequest); | ||
| 64 | |||
| 65 | =head1 SUBROUTINES/METHODS | ||
| 66 | =cut | ||
| 67 | |||
| 68 | 0 | ▶ | use MooseX::Declare; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 69 | |||
| 70 | class Finance::IBrokers::MooseCallback { | ||
| 71 | use MooseX::Types::Moose qw( Int Any Num HashRef ArrayRef Any); | ||
| 72 | use Data::Dumper; | ||
| 73 | use Time::HiRes::Value; | ||
| 74 | use Date::Manip; | ||
| 75 | |||
| 76 | #use Storable; | ||
| 77 | |||
| 78 | use Finance::IBrokers::Types | ||
| 79 | qw(Contract Order OrderState ContractDetails Execution boolean long UnderComp); | ||
| 80 | |||
| 81 | =head2 NextID | ||
| 82 | - Stores the NextID value to use when placing an order. It is initialized by TWS at startup, then incremented with getNextID. | ||
| 83 | |||
| 84 | =cut | ||
| 85 | |||
| 86 | has 'NextID' => ( is => 'rw', isa => Int, default => -1 ); | ||
| 87 | |||
| 88 | =head2 contracts | ||
| 89 | - Stores the an array of Finance::InteractiveBrokers::TWS::com::ib::client::ContractDetails objects in the contractDetails method. | ||
| 90 | |||
| 91 | =cut | ||
| 92 | |||
| 93 | has 'contracts' => ( | ||
| 94 | is => 'rw', | ||
| 95 | isa => | ||
| 96 | 'ArrayRef[Finance::InteractiveBrokers::TWS::com::ib::client::ContractDetails]', | ||
| 97 | traits => ['Array'], | ||
| 98 | default => sub { [] }, | ||
| 99 | handles => { | ||
| 100 | all_contracts => 'elements', | ||
| 101 | add_contract => 'push', | ||
| 102 | map_contracts => 'map', | ||
| 103 | filter_contracts => 'grep', | ||
| 104 | find_contract => 'first', | ||
| 105 | get_contract => 'get', | ||
| 106 | join_contracts => 'join', | ||
| 107 | count_contracts => 'count', | ||
| 108 | has_contracts => 'count', | ||
| 109 | has_no_contracts => 'is_empty', | ||
| 110 | sorted_contracts => 'sort', | ||
| 111 | }, | ||
| 112 | ); | ||
| 113 | |||
| 114 | #has 'contracts' => ( is => 'rw', isa => ArrayRef ); | ||
| 115 | #has 'accountinfo' => ( is => 'rw', isa => HashRef ); | ||
| 116 | |||
| 117 | =head2 debug | ||
| 118 | Set debug to 1 to enable more warn output | ||
| 119 | |||
| 120 | =cut | ||
| 121 | |||
| 122 | has 'debug' => ( is => 'rw', isa => boolean, default => 0 ); | ||
| 123 | |||
| 124 | =head2 contractDetailsRequest | ||
| 125 | - Stores a hash of values describing the contract details request status. | ||
| 126 | |||
| 127 | =cut | ||
| 128 | |||
| 129 | has 'contractDetailsRequest' => ( | ||
| 130 | is => 'rw', | ||
| 131 | isa => HashRef, | ||
| 132 | traits => ['Hash'], | ||
| 133 | default => sub { {} }, | ||
| 134 | handles => { | ||
| 135 | set_contractDetailsRequest => 'set', | ||
| 136 | get_contractDetailsRequest => 'get', | ||
| 137 | has_no_contractDetailsRequests => 'is_empty', | ||
| 138 | num_contractDetailsRequests => 'count', | ||
| 139 | delete_contractDetailsRequest => 'delete', | ||
| 140 | contractDetailsRequest_pairs => 'kv', | ||
| 141 | }, | ||
| 142 | ); | ||
| 143 | |||
| 144 | =head2 accountinfo | ||
| 145 | - Stores the a hash of account information key=>value pairs. | ||
| 146 | |||
| 147 | =cut | ||
| 148 | |||
| 149 | has 'accountinfo' => ( | ||
| 150 | is => 'rw', | ||
| 151 | isa => HashRef, | ||
| 152 | traits => ['Hash'], | ||
| 153 | default => sub { {} }, | ||
| 154 | handles => { | ||
| 155 | set_accountinfo => 'set', | ||
| 156 | get_accountinfo => 'get', | ||
| 157 | has_no_accountinfo => 'is_empty', | ||
| 158 | num_accountinfo => 'count', | ||
| 159 | delete_accountinfo => 'delete', | ||
| 160 | accountinfo_pairs => 'kv', | ||
| 161 | }, | ||
| 162 | ); | ||
| 163 | |||
| 164 | =head2 DataReq | ||
| 165 | - Storage for data requests to be made. | ||
| 166 | |||
| 167 | =cut | ||
| 168 | |||
| 169 | has 'DataReq' => ( | ||
| 170 | is => 'rw', | ||
| 171 | isa => HashRef, | ||
| 172 | traits => ['Hash'], | ||
| 173 | default => sub { {} }, | ||
| 174 | handles => { | ||
| 175 | set_DataReq => 'set', | ||
| 176 | get_DataReq => 'get', | ||
| 177 | has_no_DataReq => 'is_empty', | ||
| 178 | num_DataReq => 'count', | ||
| 179 | delete_DataReq => 'delete', | ||
| 180 | DataReq_pairs => 'kv', | ||
| 181 | }, | ||
| 182 | ); | ||
| 183 | |||
| 184 | =head2 candles | ||
| 185 | - Storage for OHLC candles | ||
| 186 | |||
| 187 | =cut | ||
| 188 | |||
| 189 | has 'candles' => ( | ||
| 190 | is => 'rw', | ||
| 191 | isa => 'HashRef', | ||
| 192 | traits => ['Hash'], | ||
| 193 | default => sub { {} }, | ||
| 194 | handles => { | ||
| 195 | set_candle => 'set', | ||
| 196 | get_candle => 'get', | ||
| 197 | has_no_candle => 'is_empty', | ||
| 198 | num_candle => 'count', | ||
| 199 | delete_candle => 'delete', | ||
| 200 | candle_pairs => 'kv', | ||
| 201 | }, | ||
| 202 | |||
| 203 | ); | ||
| 204 | |||
| 205 | =head2 nextValidId | ||
| 206 | - Called at startup, then when getNextID is used. Sets the next ID for TWS orders. | ||
| 207 | |||
| 208 | =cut | ||
| 209 | |||
| 210 | method nextValidId( Int $orderId) { | ||
| 211 | $self->NextID($orderId); | ||
| 212 | warn "nextValidId initialized with: $orderId\n" if ( $self->debug ); | ||
| 213 | } | ||
| 214 | |||
| 215 | =head2 getNextID | ||
| 216 | - Return the next order ID currently set NextID and increments the value. | ||
| 217 | |||
| 218 | =cut | ||
| 219 | |||
| 220 | method getNextID { | ||
| 221 | my $nextid = $self->NextID; | ||
| 222 | my $addid = $nextid; | ||
| 223 | $self->NextID( ++$addid ); | ||
| 224 | return $nextid; | ||
| 225 | } | ||
| 226 | |||
| 227 | #method error( Exception e ) {} | ||
| 228 | |||
| 229 | =head2 error | ||
| 230 | - Two error methods, since it can be called two different ways. | ||
| 231 | method error( Str $str ) { warn $str if ( $self->debug ); } | ||
| 232 | method error( Int $id, Int $errorCode, Any $errorMsg ) | ||
| 233 | |||
| 234 | =cut | ||
| 235 | |||
| 236 | method error( Str $str ) { warn $str if ( $self->debug ); } | ||
| 237 | |||
| 238 | method error( Int $id, Int $errorCode, Any $errorMsg ) | ||
| 239 | { warn "ERROR: $id, EC: $errorCode, Msg: $errorMsg\n" } | ||
| 240 | |||
| 241 | =head2 connectionClosed | ||
| 242 | - Called with the TWS connection is closed. | ||
| 243 | |||
| 244 | =cut | ||
| 245 | |||
| 246 | method connectionClosed() { warn "Connection Closed\n" } | ||
| 247 | |||
| 248 | =head2 tickPrice | ||
| 249 | - Called when tickPrice changes | ||
| 250 | |||
| 251 | =cut | ||
| 252 | |||
| 253 | method tickPrice( Int $tickerId, Int $field, Num $price, | ||
| 254 | Int $canAutoExecute) { | ||
| 255 | |||
| 256 | my $type = $self->{tickType}->getField($field); | ||
| 257 | my $time = Time::HiRes::Value->now(); | ||
| 258 | my $ae = $canAutoExecute ? 'canAutoExecute' : 'NoAutoExecute'; | ||
| 259 | |||
| 260 | warn "TickPrice: $tickerId, $type: $price, $ae, $time \n" | ||
| 261 | if ( $self->debug ); | ||
| 262 | |||
| 263 | } | ||
| 264 | |||
| 265 | =head2 tickSize | ||
| 266 | - Called when tickSize changes | ||
| 267 | |||
| 268 | =cut | ||
| 269 | |||
| 270 | method tickSize( Int $tickerId, Int $field, Int $size ) { | ||
| 271 | |||
| 272 | my $type = $self->{tickType}->getField($field); | ||
| 273 | my $time = Time::HiRes::Value->now(); | ||
| 274 | |||
| 275 | warn "tickSize: $tickerId, Type: $type, Size: $size, Time: $time\n" | ||
| 276 | if ( $self->debug ); | ||
| 277 | |||
| 278 | } | ||
| 279 | |||
| 280 | =head2 tickGeneric | ||
| 281 | - Called when market data changes | ||
| 282 | |||
| 283 | =cut | ||
| 284 | |||
| 285 | method tickGeneric( Int $tickerId, Int $tickType, Num $value ) { | ||
| 286 | my $type = $self->{tickType}->getField($tickType); | ||
| 287 | warn "tickGeneric: $tickerId, $tickType, $type, $value \n" | ||
| 288 | if ( $self->debug ); | ||
| 289 | } | ||
| 290 | |||
| 291 | =head2 Other methods | ||
| 292 | - See the Interactive Brokers API documentation at https://www.interactivebrokers.com/en/software/api/apiguide/java/java_ewrapper_methods.htm for other methods. | ||
| 293 | |||
| 294 | =cut | ||
| 295 | |||
| 296 | method tickString( Int $tickerId, Int $tickType, Any $value ) { | ||
| 297 | my $type = $self->{tickType}->getField($tickType); | ||
| 298 | warn "tickString: $tickerId, $tickType, $type, $value \n" | ||
| 299 | if ( $self->debug ); | ||
| 300 | |||
| 301 | } | ||
| 302 | |||
| 303 | method tickSnapshotEnd( Int $tickerId) { | ||
| 304 | warn "tickSnapshotEnd called with Ticker ID: $tickerId\n" | ||
| 305 | if ( $self->debug ); | ||
| 306 | } | ||
| 307 | |||
| 308 | method tickOptionComputation( | ||
| 309 | Int $tickerId, | ||
| 310 | Int $field, | ||
| 311 | Num $impliedVol, | ||
| 312 | Num $delta, | ||
| 313 | Num $optPrice, | ||
| 314 | Num $pvDividend, | ||
| 315 | Num $gamma, | ||
| 316 | Num $vega, | ||
| 317 | Num $theta, | ||
| 318 | Num $undPrice | ||
| 319 | ) { | ||
| 320 | |||
| 321 | my $fieldtype = $self->{tickType}->getField($field); | ||
| 322 | warn | ||
| 323 | "tickOptionComputation: ticker: $tickerId, field: $field, F: $fieldtype, IV: $impliedVol, Dt: $delta, OptPrice: $optPrice, pvDiv: $pvDividend, gamma: $gamma, vega: $vega, theta: $theta, undPrice: $undPrice \n" | ||
| 324 | if ( $self->debug ); | ||
| 325 | |||
| 326 | } | ||
| 327 | |||
| 328 | method tickEFP( | ||
| 329 | Int $tickerId, | ||
| 330 | Int $tickType, | ||
| 331 | Num $basisPoints, | ||
| 332 | Any $formattedBasisPoints, | ||
| 333 | Num $impliedFuture, | ||
| 334 | Int $holdDays, | ||
| 335 | Any $futureExpiry, | ||
| 336 | Num $dividendImpact, | ||
| 337 | Num $dividendsToExpiry | ||
| 338 | ) { | ||
| 339 | my $type = $self->{tickType}->getField($tickType); | ||
| 340 | warn | ||
| 341 | "EFP: $tickerId, $tickType, $type, $basisPoints, $formattedBasisPoints, $impliedFuture, $holdDays, $futureExpiry, $dividendImpact, $dividendsToExpiry \n" | ||
| 342 | if ( $self->debug ); | ||
| 343 | |||
| 344 | } | ||
| 345 | |||
| 346 | method orderStatus( | ||
| 347 | Int $orderId, | ||
| 348 | Any $status, | ||
| 349 | Int $filled, | ||
| 350 | Int $remaining, | ||
| 351 | Num $avgFillPrice, | ||
| 352 | Int $permId, | ||
| 353 | Int $parentId, | ||
| 354 | Num $lastFillPrice, | ||
| 355 | Int $clientId, | ||
| 356 | Any $whyHeld) { | ||
| 357 | warn | ||
| 358 | "orderStatus: ID: $orderId, Stat: $status, Fill: $filled, Remain: $remaining, AvgFP: $avgFillPrice, PermID: $permId, ParentID: $parentId, LastFillPrice: $lastFillPrice, ClientID: $clientId, WhyHeld: $whyHeld\n" | ||
| 359 | if ( $self->debug ); | ||
| 360 | |||
| 361 | } | ||
| 362 | |||
| 363 | method openOrder( | ||
| 364 | Int $orderId, | ||
| 365 | Contract $contract, | ||
| 366 | Order $order, | ||
| 367 | OrderState $orderState | ||
| 368 | ) { | ||
| 369 | warn "openOrder: " | ||
| 370 | . Dumper($orderId) . ' ' | ||
| 371 | . Dumper($contract) . ' ' | ||
| 372 | . Dumper($order) . ' ' | ||
| 373 | . Dumper($orderState) . "\n" | ||
| 374 | if ( $self->debug ); | ||
| 375 | |||
| 376 | } | ||
| 377 | |||
| 378 | method openOrderEnd() {} | ||
| 379 | |||
| 380 | method updateAccountValue( | ||
| 381 | Any $key, Any $value, | ||
| 382 | Any $currency, | ||
| 383 | Any $accountName | ||
| 384 | ) { | ||
| 385 | #$self->accountinfo({$accountName->{$key} = $value}}); | ||
| 386 | $self->set_accountinfo( ${key} => { $accountName => $value } ); | ||
| 387 | |||
| 388 | warn "Account Value: $key, $value, $currency, $accountName\n" | ||
| 389 | if ( $self->debug ); | ||
| 390 | } | ||
| 391 | |||
| 392 | method updatePortfolio( | ||
| 393 | Contract $contract, | ||
| 394 | Int $position, | ||
| 395 | Num $marketPrice, | ||
| 396 | Num $marketValue, | ||
| 397 | Num $averageCost, | ||
| 398 | Num $unrealizedPNL, | ||
| 399 | Num $realizedPNL, | ||
| 400 | Any $accountName | ||
| 401 | ) { | ||
| 402 | |||
| 403 | warn "updatePortfolio, " | ||
| 404 | . $contract->{m_conId} | ||
| 405 | . ", $position, $marketPrice, $marketValue, $averageCost, $unrealizedPNL, $realizedPNL, $accountName\n" | ||
| 406 | if ( $self->debug ); | ||
| 407 | |||
| 408 | warn "Portfolio Contract info: " | ||
| 409 | . $contract->{m_conId} . ", " | ||
| 410 | . $contract->{m_symbol} . ", " | ||
| 411 | . $contract->{m_secType} . ", " | ||
| 412 | . $contract->{m_expiry} . ", " | ||
| 413 | . $contract->{m_strike} . ", " | ||
| 414 | . $contract->{m_right} . ", " | ||
| 415 | . $contract->{m_multiplier} . ", " | ||
| 416 | . $contract->{m_exchange} . ", " | ||
| 417 | . $contract->{m_currency} . ", " | ||
| 418 | . $contract->{m_localSymbol} . ", " | ||
| 419 | . $contract->{m_primaryExch} . ", " | ||
| 420 | . $contract->{m_includeExpired} . ", " | ||
| 421 | . $contract->{m_secIdType} . ", " | ||
| 422 | . $contract->{m_secId} . ", " | ||
| 423 | . $contract->{m_comboLegsDescrip} . ", " | ||
| 424 | . $contract->{m_underComp} . "\n\n" | ||
| 425 | if ( $self->debug ); | ||
| 426 | |||
| 427 | } | ||
| 428 | |||
| 429 | method updateAccountTime( Any $timeStamp ) | ||
| 430 | { warn "Timestamp: $timeStamp\n"; } | ||
| 431 | |||
| 432 | method accountDownloadEnd( Any $accountName ) { | ||
| 433 | warn "accountDownloadEnd called with account name $accountName\n" | ||
| 434 | if ( $self->debug ); | ||
| 435 | |||
| 436 | } | ||
| 437 | |||
| 438 | method contractDetails( Int $reqId, ContractDetails $contractDetails ) { | ||
| 439 | |||
| 440 | #print Dumper($contractDetails); | ||
| 441 | $self->add_contract($contractDetails) | ||
| 442 | ; # Add this contract to the ContractDetails array | ||
| 443 | |||
| 444 | warn "contractDetails Request ID: $reqId, \n" if ( $self->debug ); | ||
| 445 | |||
| 446 | #store [\$contractDetails], 'some_file'; | ||
| 447 | warn "\nContract summary: m_conId: " | ||
| 448 | . $contractDetails->{m_summary}->{m_conId} | ||
| 449 | . " m_symbol: " | ||
| 450 | . $contractDetails->{m_summary}->{m_symbol} | ||
| 451 | . " m_secType: " | ||
| 452 | . $contractDetails->{m_summary}->{m_secType} | ||
| 453 | . " m_expiry: " | ||
| 454 | . $contractDetails->{m_summary}->{m_expiry} | ||
| 455 | . " m_strike: " | ||
| 456 | . $contractDetails->{m_summary}->{m_strike} | ||
| 457 | . " m_right: " | ||
| 458 | . $contractDetails->{m_summary}->{m_right} | ||
| 459 | . " m_multiplier: " | ||
| 460 | . $contractDetails->{m_summary}->{m_multiplier} | ||
| 461 | . " m_exchange: " | ||
| 462 | . $contractDetails->{m_summary}->{m_exchange} | ||
| 463 | . " m_currency: " | ||
| 464 | . $contractDetails->{m_summary}->{m_currency} | ||
| 465 | . " m_localSymbol: " | ||
| 466 | . $contractDetails->{m_summary}->{m_localSymbol} | ||
| 467 | . " m_primaryExch: " | ||
| 468 | . $contractDetails->{m_summary}->{m_primaryExch} | ||
| 469 | . " m_includeExpired: " | ||
| 470 | . $contractDetails->{m_summary}->{m_includeExpired} | ||
| 471 | . " m_secIdType: " | ||
| 472 | . $contractDetails->{m_summary}->{m_secIdType} | ||
| 473 | . " m_secId: " | ||
| 474 | . $contractDetails->{m_summary}->{m_secId} | ||
| 475 | . " m_comboLegsDescrip: " | ||
| 476 | . $contractDetails->{m_summary}->{m_comboLegsDescrip} | ||
| 477 | . " m_underComp: " | ||
| 478 | . $contractDetails->{m_summary}->{m_underComp} . "\n" | ||
| 479 | if ( $self->debug ); | ||
| 480 | |||
| 481 | warn "Contract Details:\n" if ( $self->debug ); | ||
| 482 | |||
| 483 | warn "m_summary: " | ||
| 484 | . $contractDetails->{m_summary} . ", " | ||
| 485 | . Dumper( $contractDetails->{m_summary} ) . ", " | ||
| 486 | . "m_marketName: " | ||
| 487 | . $contractDetails->{m_marketName} . ", " | ||
| 488 | . "m_minTick: " | ||
| 489 | . $contractDetails->{m_minTick} . ", " | ||
| 490 | . "m_priceMagnifier: " | ||
| 491 | . $contractDetails->{m_priceMagnifier} . ", " | ||
| 492 | . "m_orderTypes: " | ||
| 493 | . $contractDetails->{m_orderTypes} . ", " | ||
| 494 | . "m_validExchanges: " | ||
| 495 | . $contractDetails->{m_validExchanges} . ", " | ||
| 496 | . "m_underConId: " | ||
| 497 | . $contractDetails->{m_underConId} . ", " | ||
| 498 | . "m_longName: " | ||
| 499 | . $contractDetails->{m_longName} . ", " | ||
| 500 | . "m_contractMonth: " | ||
| 501 | . $contractDetails->{m_contractMonth} . ", " | ||
| 502 | . "m_industry: " | ||
| 503 | . $contractDetails->{m_industry} . ", " | ||
| 504 | . "m_category: " | ||
| 505 | . $contractDetails->{m_category} . ", " | ||
| 506 | . "m_subcategory: " | ||
| 507 | . $contractDetails->{m_subcategory} . ", " | ||
| 508 | . "m_timeZoneId: " | ||
| 509 | . $contractDetails->{m_timeZoneId} . ", " | ||
| 510 | . "m_tradingHours: " | ||
| 511 | . $contractDetails->{m_tradingHours} . ", " | ||
| 512 | . "m_liquidHours: " | ||
| 513 | . $contractDetails->{m_liquidHours} . ", " | ||
| 514 | . "m_evRule: " | ||
| 515 | . $contractDetails->{m_evRule} . ", " | ||
| 516 | . "m_evMultiplier: " | ||
| 517 | . $contractDetails->{m_evMultiplier} . ", " | ||
| 518 | . "m_secIdList: " | ||
| 519 | . $contractDetails->{m_secIdList} . ", " | ||
| 520 | . "m_cusip: " | ||
| 521 | . $contractDetails->{m_cusip} . ", " | ||
| 522 | . "m_ratings: " | ||
| 523 | . $contractDetails->{m_ratings} . ", " | ||
| 524 | . "m_descAppend: " | ||
| 525 | . $contractDetails->{m_descAppend} . ", " | ||
| 526 | . "m_bondType: " | ||
| 527 | . $contractDetails->{m_bondType} . ", " | ||
| 528 | . "m_couponType: " | ||
| 529 | . $contractDetails->{m_couponType} . ", " | ||
| 530 | . "m_maturity: " | ||
| 531 | . $contractDetails->{m_maturity} . ", " | ||
| 532 | . "m_issueDate: " | ||
| 533 | . $contractDetails->{m_issueDate} . ", " | ||
| 534 | . "m_nextOptionDate: " | ||
| 535 | . $contractDetails->{m_nextOptionDate} . ", " | ||
| 536 | . "m_nextOptionType: " | ||
| 537 | . $contractDetails->{m_nextOptionType} . ", " | ||
| 538 | . "m_notes: " | ||
| 539 | . $contractDetails->{m_notes} . "\n" | ||
| 540 | if ( $self->debug ); | ||
| 541 | |||
| 542 | } | ||
| 543 | |||
| 544 | method contractDetailsEnd( Int $reqId ) { | ||
| 545 | $self->set_contractDetailsRequest( | ||
| 546 | $reqId => { 'Status' => 'Complete' } | ||
| 547 | ); | ||
| 548 | if ( $self->debug ) { | ||
| 549 | |||
| 550 | my $d = Data::Dumper->new( [ $self->all_contracts ] ); | ||
| 551 | $d->Purity(1)->Terse(1)->Deepcopy(1); | ||
| 552 | warn "Contract Details request complete for ID $reqId\n"; | ||
| 553 | warn "Contracts: " . $d->Dump; | ||
| 554 | |||
| 555 | #warn "Sample contract details: " | ||
| 556 | #. $self->get_contract(1)->{m_orderTypes} . "\n\n"; | ||
| 557 | } | ||
| 558 | } | ||
| 559 | |||
| 560 | method bondContractDetails( Int $reqId, ContractDetails $contractDetails ) | ||
| 561 | {} | ||
| 562 | |||
| 563 | method execDetails( Int $reqId, Contract $contract, Execution $execution ) | ||
| 564 | { | ||
| 565 | warn "execDetails: $reqId, $contract, $execution \n" | ||
| 566 | if ( $self->debug ); | ||
| 567 | warn "Contract: " . Dumper($contract) if ( $self->debug ); | ||
| 568 | warn "Execution: " . Dumper($execution) if ( $self->debug ); | ||
| 569 | |||
| 570 | } | ||
| 571 | |||
| 572 | method execDetailsEnd( Int $reqId ) {} | ||
| 573 | |||
| 574 | method updateMktDepth( | ||
| 575 | Int $tickerId, | ||
| 576 | Int $position, | ||
| 577 | Int $operation, | ||
| 578 | Int $side, | ||
| 579 | Num $price, | ||
| 580 | Int $size | ||
| 581 | ) { | ||
| 582 | |||
| 583 | my %op; | ||
| 584 | my %s; | ||
| 585 | $op{0} = 'Insert'; | ||
| 586 | $op{1} = 'Update'; | ||
| 587 | $op{2} = 'Delete'; | ||
| 588 | $s{0} = 'Ask'; | ||
| 589 | $s{1} = 'Bid'; | ||
| 590 | |||
| 591 | my $time = Time::HiRes::Value->now(); | ||
| 592 | |||
| 593 | #print "Ticker: $tickerid, pos: $position Op: $op{$operation}, $s{$side}, $price, $size\n"; | ||
| 594 | warn | ||
| 595 | "ID: $tickerId,Pos: $position,Op: $op{$operation},Side: $s{$side},Price: $price,Size: $size, Time: $time\n" | ||
| 596 | if ( $self->debug ); | ||
| 597 | } | ||
| 598 | |||
| 599 | method updateMktDepthL2( | ||
| 600 | Int $tickerId, | ||
| 601 | Int $position, | ||
| 602 | Any $marketMaker, | ||
| 603 | Int $operation, | ||
| 604 | Int $side, | ||
| 605 | Num $price, | ||
| 606 | Int $size | ||
| 607 | ) { | ||
| 608 | |||
| 609 | my %op; | ||
| 610 | my %s; | ||
| 611 | $op{0} = 'Insert'; | ||
| 612 | $op{1} = 'Update'; | ||
| 613 | $op{2} = 'Delete'; | ||
| 614 | $s{0} = 'Ask'; | ||
| 615 | $s{1} = 'Bid'; | ||
| 616 | |||
| 617 | my $time = Time::HiRes::Value->now(); | ||
| 618 | |||
| 619 | warn | ||
| 620 | "L2ID: $tickerId,Pos: $position,Op: $op{$operation},Side: $s{$side},Price: $price,Size: $size, Time: $time\n" | ||
| 621 | if ( $self->debug ); | ||
| 622 | } | ||
| 623 | |||
| 624 | method updateNewsBulletin( Int $msgId, Int $msgType, Any $message, | ||
| 625 | Any $origExchange ) {} | ||
| 626 | |||
| 627 | method managedAccounts( Any $accountsList ) {} | ||
| 628 | |||
| 629 | method receiveFA( Int $faDataType, Any $xml ) {} | ||
| 630 | |||
| 631 | method historicalData( | ||
| 632 | Int $reqId, | ||
| 633 | Any $date, | ||
| 634 | Num $open, | ||
| 635 | Num $high, | ||
| 636 | Num $low, | ||
| 637 | Num $close, | ||
| 638 | Int $volume, | ||
| 639 | Int $count, | ||
| 640 | Num $WAP, | ||
| 641 | boolean $hasGaps | ||
| 642 | ) { | ||
| 643 | warn | ||
| 644 | "ID: $reqId, Date: $date, O: $open, H: $high, L: $low, C: $close, V: $volume, Count: $count, WAP: $WAP, HasGaps: $hasGaps \n" | ||
| 645 | if ( $self->debug ); | ||
| 646 | |||
| 647 | } | ||
| 648 | |||
| 649 | method scannerParameters( Any $xml ) { | ||
| 650 | warn $xml | ||
| 651 | if ( $self->debug ); | ||
| 652 | } | ||
| 653 | |||
| 654 | method commissionReport( Any $commissionreport ) { | ||
| 655 | warn Dumper($commissionreport) | ||
| 656 | if ( $self->debug ); | ||
| 657 | |||
| 658 | } | ||
| 659 | |||
| 660 | method scannerData( | ||
| 661 | Int $reqId, Int $rank, | ||
| 662 | ContractDetails $contractDetails, | ||
| 663 | Any $distance, | ||
| 664 | Any $benchmark, | ||
| 665 | Any $projection, | ||
| 666 | Any $legsStr | ||
| 667 | ) {} | ||
| 668 | |||
| 669 | method scannerDataEnd( Int $reqId ) {} | ||
| 670 | |||
| 671 | method realtimeBar( | ||
| 672 | Int $reqId, | ||
| 673 | long $time, | ||
| 674 | Num $open, | ||
| 675 | Num $high, | ||
| 676 | Num $low, | ||
| 677 | Num $close, | ||
| 678 | long $volume, | ||
| 679 | Num $wap, | ||
| 680 | Int $count | ||
| 681 | ) { | ||
| 682 | warn | ||
| 683 | "RTB: $reqId, $time, $open, $high, $low, $close, $volume, $wap, $count\n" | ||
| 684 | if ( $self->debug ); | ||
| 685 | |||
| 686 | return 1; | ||
| 687 | |||
| 688 | } | ||
| 689 | |||
| 690 | method currentTime( long $millis ) | ||
| 691 | { warn "CurrentTime: $millis\n" if ( $self->debug ); } | ||
| 692 | |||
| 693 | method fundamentalData( Int $reqId, Any $data ) {} | ||
| 694 | |||
| 695 | method deltaNeutralValidation( Int $reqId, UnderComp $underComp ) {} | ||
| 696 | |||
| 697 | sub AUTOLOAD { # catch all for other events | ||
| 698 | my ( $self, @args ) = @_; | ||
| 699 | our $AUTOLOAD; | ||
| 700 | warn "$AUTOLOAD called with: ", join '^', @args, "\n" | ||
| 701 | if ( $self->debug ); | ||
| 702 | return 0; | ||
| 703 | } | ||
| 704 | |||
| 705 | } | ||
| 706 | |||
| 707 | =head1 AUTHOR | ||
| 708 | |||
| 709 | Doug Spencer, C<< <forhire99 at gmail.com> >> | ||
| 710 | |||
| 711 | =head1 BUGS | ||
| 712 | |||
| 713 | Please report any bugs or feature requests to C<bug-finance-ibrokers-moosecallback at rt.cpan.org>, or through | ||
| 714 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Finance-IBrokers-MooseCallback>. I will be notified, and then you'll | ||
| 715 | automatically be notified of progress on your bug as I make changes. | ||
| 716 | |||
| 717 | |||
| 718 | |||
| 719 | |||
| 720 | =head1 SUPPORT | ||
| 721 | |||
| 722 | You can find documentation for this module with the perldoc command. | ||
| 723 | |||
| 724 | perldoc Finance::IBrokers::MooseCallback | ||
| 725 | |||
| 726 | |||
| 727 | You can also look for information at: | ||
| 728 | |||
| 729 | =over 4 | ||
| 730 | |||
| 731 | =item * RT: CPAN's request tracker (report bugs here) | ||
| 732 | |||
| 733 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Finance-IBrokers-MooseCallback> | ||
| 734 | |||
| 735 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 736 | |||
| 737 | L<http://annocpan.org/dist/Finance-IBrokers-MooseCallback> | ||
| 738 | |||
| 739 | =item * CPAN Ratings | ||
| 740 | |||
| 741 | L<http://cpanratings.perl.org/d/Finance-IBrokers-MooseCallback> | ||
| 742 | |||
| 743 | =item * Search CPAN | ||
| 744 | |||
| 745 | L<http://search.cpan.org/dist/Finance-IBrokers-MooseCallback/> | ||
| 746 | |||
| 747 | =back | ||
| 748 | |||
| 749 | |||
| 750 | =head1 ACKNOWLEDGEMENTS | ||
| 751 | |||
| 752 | |||
| 753 | =head1 LICENSE AND COPYRIGHT | ||
| 754 | |||
| 755 | Copyright 2014 Doug Spencer. | ||
| 756 | |||
| 757 | This program is free software; you can redistribute it and/or modify it | ||
| 758 | under the terms of the the Artistic License (2.0). You may obtain a | ||
| 759 | copy of the full license at: | ||
| 760 | |||
| 761 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||
| 762 | |||
| 763 | Any use, modification, and distribution of the Standard or Modified | ||
| 764 | Versions is governed by this Artistic License. By using, modifying or | ||
| 765 | distributing the Package, you accept this license. Do not use, modify, | ||
| 766 | or distribute the Package, if you do not accept this license. | ||
| 767 | |||
| 768 | If your Modified Version has been derived from a Modified Version made | ||
| 769 | by someone other than you, you are nevertheless required to ensure that | ||
| 770 | your Modified Version complies with the requirements of this license. | ||
| 771 | |||
| 772 | This license does not grant you the right to use any trademark, service | ||
| 773 | mark, tradename, or logo of the Copyright Holder. | ||
| 774 | |||
| 775 | This license includes the non-exclusive, worldwide, free-of-charge | ||
| 776 | patent license to make, have made, use, offer to sell, sell, import and | ||
| 777 | otherwise transfer the Package with respect to any patent claims | ||
| 778 | licensable by the Copyright Holder that are necessarily infringed by the | ||
| 779 | Package. If you institute patent litigation (including a cross-claim or | ||
| 780 | counterclaim) against any party alleging that the Package constitutes | ||
| 781 | direct or contributory patent infringement, then this Artistic License | ||
| 782 | to you shall terminate on the date that such litigation is filed. | ||
| 783 | |||
| 784 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||
| 785 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||
| 786 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
| 787 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||
| 788 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||
| 789 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||
| 790 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||
| 791 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 792 | |||
| 793 | |||
| 794 | =cut | ||
| 795 | |||
| 796 | 1; # End of Finance::IBrokers::MooseCallback | ||