Class: Agents::BybitAgent

Inherits:
Agent
  • Object
show all
Includes:
FormConfigurable
Defined in:
lib/huginn_bybit_agent/bybit_agent.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



102
103
104
# File 'lib/huginn_bybit_agent/bybit_agent.rb', line 102

def check
  trigger_action
end

#default_optionsObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/huginn_bybit_agent/bybit_agent.rb', line 49

def default_options
  {
    'type' => '',
    'apikey' => '',
    'windows' => '5000',
    'limit' => '10',
    'secretkey' => '',
    'debug' => 'false',
    'expected_receive_period_in_days' => '2',
    'changes_only' => 'true'
  }
end

#validate_optionsObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/huginn_bybit_agent/bybit_agent.rb', line 70

def validate_options
  errors.add(:base, "type has invalid value: should be 'get_balances' 'order_history' 'trade_history'") if interpolated['type'].present? && !%w(get_balances order_history trade_history).include?(interpolated['type'])

  unless options['apikey'].present? || !['get_balances', 'order_history', 'trade_history'].include?(options['type'])
    errors.add(:base, "apikey is a required field")
  end

  unless options['secretkey'].present? || !['get_balances', 'order_history', 'trade_history'].include?(options['type'])
    errors.add(:base, "secretkey is a required field")
  end

  unless options['limit'].present? || !['order_history', 'trade_history'].include?(options['type'])
    errors.add(:base, "limit is a required field")
  end

  if options.has_key?('changes_only') && boolify(options['changes_only']).nil?
    errors.add(:base, "if provided, changes_only must be true or false")
  end

  if options.has_key?('debug') && boolify(options['debug']).nil?
    errors.add(:base, "if provided, debug must be true or false")
  end

  unless options['expected_receive_period_in_days'].present? && options['expected_receive_period_in_days'].to_i > 0
    errors.add(:base, "Please provide 'expected_receive_period_in_days' to indicate how many days can pass before this Agent is considered to be not working")
  end
end

#working?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/huginn_bybit_agent/bybit_agent.rb', line 98

def working?
  event_created_within?(options['expected_receive_period_in_days']) && !recent_error_logs?
end