Class: IB::Alert
- Inherits:
-
Object
- Object
- IB::Alert
- Defined in:
- lib/ib/account-infos.rb,
lib/alerts/base-alert.rb,
lib/alerts/order-alerts.rb,
lib/alerts/gateway-alerts.rb
Class Method Summary collapse
-
.add_orderstate_alert(*codes) ⇒ Object
IB::Alert#AddOrderstateAlert.
- .alert_202(msg) ⇒ Object
- .alert_2101(msg) ⇒ Object
- .alert_2102(msg) ⇒ Object
- .ignore_alert(*codes) ⇒ Object
- .log_alert_in_debug(*codes) ⇒ Object
- .log_alert_in_error(*codes) ⇒ Object
- .log_alert_in_info(*codes) ⇒ Object
- .log_alert_in_warn(*codes) ⇒ Object
-
.logger ⇒ Object
acts as prototype for any generated method require ‘active_support’.
- .method_missing(method_id = nil, msg = nil, *args, &block) ⇒ Object
-
.status_2101(account) ⇒ Object
resets status and raises IB::TransmissionError.
Class Method Details
.add_orderstate_alert(*codes) ⇒ Object
IB::Alert#AddOrderstateAlert
The OrderState-Record is used to record the history of the order. If selected Alert-Messages appear, they are added to the Order.order_state-Array. The last Status is available as Order.order_state, all states are accessible by Order.order_states
The TWS-Message-text is stored to the »warning-text«-field. The Status is always »rejected«. If the first OrderState-object of a Order is »rejected«, the order is not placed at all. Otherwise only the last action is not applied and the order is unchanged.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/alerts/order-alerts.rb', line 38 def add_orderstate_alert *codes codes.each do |n| class_eval <<-EOD def self.alert_#{n} msg if msg.error_id.present? IB::Gateway.current.account_data do | account | order= account.locate_order( local_id: msg.error_id ) if order.present? && ( order.order_state.status != 'Rejected' ) order.order_states.update_or_create( IB::OrderState.new( status: 'Rejected' , perm_id: order.perm_id, warning_text: '#{n}: '+ msg.message, local_id: msg.error_id ), :status ) IB::Gateway.logger.error{ msg.to_human } end # order present? end # mutex-environment end # branch end # def EOD end # loop end |
.alert_202(msg) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/alerts/order-alerts.rb', line 4 def self.alert_202 msg # do anything in a secure mutex-synchronized-environment any_order = IB::Gateway.current.account_data do | account | order= account.locate_order( local_id: msg.error_id ) if order.present? && ( order.order_state.status != 'Cancelled' ) order.order_states.update_or_create( IB::OrderState.new( status: 'Cancelled', perm_id: order.perm_id, local_id: order.local_id ) , :status ) end order # return_value end if any_order.compact.empty? IB::Gateway.logger.error{"Alert 202: The deleted order was not registered: local_id #{msg.error_id}"} end end |
.alert_2101(msg) ⇒ Object
7 8 9 10 |
# File 'lib/ib/account-infos.rb', line 7 def alert_2101 msg logger.error {msg.} @status_2101 = msg.dup end |
.alert_2102(msg) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/alerts/gateway-alerts.rb', line 5 def self.alert_2102 msg # Connectivity between IB and Trader Workstation has been restored - data maintained. sleep 0.1 # no need to wait too long. if IB::OrientGateway.current.check_connection IB::Connection.logger.debug { "Alert 2102: Connection stable" } else IB::OrientGateway.current.reconnect end end |
.ignore_alert(*codes) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/alerts/base-alert.rb', line 70 def ignore_alert *codes codes.each do |n| class_eval <<-EOD def self.alert_#{n} msg # even the log_debug entry is suppressed end EOD end end |
.log_alert_in_debug(*codes) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/alerts/base-alert.rb', line 79 def log_alert_in_debug *codes codes.each do |n| class_eval <<-EOD def self.alert_#{n} msg logger.debug { msg.to_human } end EOD end end |
.log_alert_in_error(*codes) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/alerts/base-alert.rb', line 107 def log_alert_in_error *codes codes.each do |n| class_eval <<-EOD def self.alert_#{n} msg if msg.error_id.present? && msg.error_id > 0 logger.error { msg.message + ' id: ' + msg.error_id.to_s } else logger.error { msg.message } end end EOD end end |
.log_alert_in_info(*codes) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/alerts/base-alert.rb', line 88 def log_alert_in_info *codes codes.each do |n| class_eval <<-EOD def self.alert_#{n} msg logger.info { msg.to_human } end EOD end end |
.log_alert_in_warn(*codes) ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/alerts/base-alert.rb', line 97 def log_alert_in_warn *codes codes.each do |n| class_eval <<-EOD def self.alert_#{n} msg logger.warn { msg.to_human } end EOD end end |
.logger ⇒ Object
acts as prototype for any generated method require ‘active_support’
43 44 45 |
# File 'lib/alerts/base-alert.rb', line 43 def self.logger IB::Connection.logger end |
.method_missing(method_id = nil, msg = nil, *args, &block) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/alerts/base-alert.rb', line 47 def self.method_missing( method_id =nil, msg = nil , *args, &block ) # puts "METHOD MISSING" # puts msg if msg.is_a? IB::Messages::Incoming::Alert logger.debug { msg.to_human } else logger.error { "Argument to IB::Alert is not a IB::Messages::Incoming::Alert" } logger.error { "The object: #{msg.inspect} " } end rescue NoMethodError unless logger.nil? logger.error { "The Argument is not a valid IB::Messages:Incoming::Alert object"} logger.error { "The object: #{msg.inspect} " } else puts "No Logging-Device specified" puts "The object: #{msg.inspect} " end end |
.status_2101(account) ⇒ Object
resets status and raises IB::TransmissionError
12 13 14 15 |
# File 'lib/ib/account-infos.rb', line 12 def status_2101 account # resets status and raises IB::TransmissionError error account.account + ": " +@status_2101., :reader unless @status_2101.nil? @status_2101 = nil # always returns nil end |