Class: IB::Alert
- Inherits:
-
Object
- Object
- IB::Alert
- Defined in:
- lib/ib/alerts/base-alert.rb,
lib/ib/alerts/order-alerts.rb,
lib/ib/alerts/gateway-alerts.rb,
lib/ib/gateway/account-infos.rb
Class Method Summary collapse
-
.add_orderstate_alert(*codes) ⇒ Object
IB::Alert#AddOrderstateAlert.
-
.alert_202(msg) ⇒ Object
error msg, :order, nil.
- .alert_2101(msg) ⇒ Object
- .alert_2102(msg) ⇒ Object
- .alert_388(msg) ⇒ Object
- .ignore_alert(*codes) ⇒ Object
- .log_alert_in_error(*codes) ⇒ Object
- .log_alert_in_info(*codes) ⇒ Object
- .log_alert_in_warn(*codes) ⇒ Object
- .logger ⇒ Object
- .method_missing(method_id, msg, *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.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ib/alerts/order-alerts.rb', line 43 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
error msg, :order, nil
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ib/alerts/order-alerts.rb', line 9 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/gateway/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/ib/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::Gateway.current.check_connection IB::Gateway.logger.debug { "Alert 2102: Connection stable" } else IB::Gateway.current.reconnect end end |
.alert_388(msg) ⇒ Object
4 5 6 7 8 |
# File 'lib/ib/alerts/order-alerts.rb', line 4 def self.alert_388 msg # Order size x is smaller than the minimum required size of yy. IB::Gateway.logger.error msg.inspect # error msg, :order, nil end |
.ignore_alert(*codes) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/ib/alerts/base-alert.rb', line 68 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_error(*codes) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ib/alerts/base-alert.rb', line 96 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
77 78 79 80 81 82 83 84 85 |
# File 'lib/ib/alerts/base-alert.rb', line 77 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
86 87 88 89 90 91 92 93 94 |
# File 'lib/ib/alerts/base-alert.rb', line 86 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
64 65 66 |
# File 'lib/ib/alerts/base-alert.rb', line 64 def logger IB::Connection.logger || IB::Gateway.logger end |
.method_missing(method_id, msg, *args, &block) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ib/alerts/base-alert.rb', line 44 def self.method_missing( method_id, msg , *args, &block ) 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/gateway/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 |