Class: Coinigy::Subscription
Overview
Represents the Subscription to Coinigy, it holds all the info related
Instance Attribute Summary collapse
-
#accounts(reload = false) ⇒ Object
Accounts relation.
-
#active ⇒ Object
Returns the value of attribute active.
-
#chat_enabled ⇒ Object
Returns the value of attribute chat_enabled.
-
#chat_nick ⇒ Object
Returns the value of attribute chat_nick.
-
#city ⇒ Object
Returns the value of attribute city.
-
#client ⇒ Object
Relationships and other objects.
-
#company ⇒ Object
Returns the value of attribute company.
-
#country ⇒ Object
Returns the value of attribute country.
-
#created_on ⇒ Object
Returns the value of attribute created_on.
-
#custom_ticker ⇒ Object
Returns the value of attribute custom_ticker.
-
#email ⇒ Object
Returns the value of attribute email.
-
#first_name ⇒ Object
Returns the value of attribute first_name.
-
#last_active ⇒ Object
Returns the value of attribute last_active.
-
#last_login ⇒ Object
Returns the value of attribute last_login.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#newsletter ⇒ Object
Returns the value of attribute newsletter.
-
#open_orders(reload = false) ⇒ Object
Open orders relation.
-
#order_history(reload = false) ⇒ Object
Order history relation.
-
#phone ⇒ Object
Returns the value of attribute phone.
-
#pref_alert_email ⇒ Object
Returns the value of attribute pref_alert_email.
-
#pref_alert_mobile ⇒ Object
Returns the value of attribute pref_alert_mobile.
-
#pref_alert_sms ⇒ Object
Returns the value of attribute pref_alert_sms.
-
#pref_app_device_id ⇒ Object
Returns the value of attribute pref_app_device_id.
-
#pref_balance_email ⇒ Object
Returns the value of attribute pref_balance_email.
-
#pref_referral_code ⇒ Object
Returns the value of attribute pref_referral_code.
-
#pref_subscription_expires ⇒ Object
Returns the value of attribute pref_subscription_expires.
-
#pref_trade_email ⇒ Object
Returns the value of attribute pref_trade_email.
-
#pref_trade_mobile ⇒ Object
Returns the value of attribute pref_trade_mobile.
-
#pref_trade_sms ⇒ Object
Returns the value of attribute pref_trade_sms.
-
#preferences ⇒ Object
Preferences relation.
-
#referral_balance ⇒ Object
Returns the value of attribute referral_balance.
-
#state ⇒ Object
Returns the value of attribute state.
-
#street1 ⇒ Object
Returns the value of attribute street1.
-
#street2 ⇒ Object
Returns the value of attribute street2.
-
#subscription_status ⇒ Object
Returns the value of attribute subscription_status.
-
#ticker_enabled ⇒ Object
Returns the value of attribute ticker_enabled.
-
#ticker_indicator_time_type ⇒ Object
Returns the value of attribute ticker_indicator_time_type.
-
#two_factor ⇒ Object
Returns the value of attribute two_factor.
-
#zip ⇒ Object
Returns the value of attribute zip.
Attributes inherited from Model
Class Method Summary collapse
-
.find(key, secret) ⇒ Object
Connects to the API with the credentials given and returns an instance of Subscription with the data of the user.
Instance Method Summary collapse
-
#add_account(name, exchange, key, secret) ⇒ Object
Registers a new account in the subscription and returns it.
-
#alert_history(reload = false) ⇒ Object
Alert history relation.
-
#all_exchanges ⇒ Object
Return all exchanges supported at Coinigy.
- #attributes ⇒ Object
-
#balance(show_nils = 0) ⇒ Object
Returns the mixed balance of the whole subscription.
-
#balance_history(date = Date.today.to_s) ⇒ Object
Returns the balance history for the provided date (separated per account).
-
#balances(ids = [], show_nils = 0) ⇒ Object
Returns the balances for the provided account ids.
-
#exchanges(reload = false) ⇒ Object
Exchanges relation.
-
#open_alerts(reload = false) ⇒ Object
Open alerts relation.
-
#order_and_price_types ⇒ Object
Returns the list of order and price types.
Methods inherited from Model
#errors?, #initialize, #inspect, #save
Constructor Details
This class inherits a constructor from Coinigy::Model
Instance Attribute Details
#accounts(reload = false) ⇒ Object
Accounts relation
13 14 15 |
# File 'lib/coinigy/subscription.rb', line 13 def accounts @accounts end |
#active ⇒ Object
Returns the value of attribute active
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def active @active end |
#chat_enabled ⇒ Object
Returns the value of attribute chat_enabled
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def chat_enabled @chat_enabled end |
#chat_nick ⇒ Object
Returns the value of attribute chat_nick
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def chat_nick @chat_nick end |
#city ⇒ Object
Returns the value of attribute city
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def city @city end |
#client ⇒ Object
Relationships and other objects
13 14 15 |
# File 'lib/coinigy/subscription.rb', line 13 def client @client end |
#company ⇒ Object
Returns the value of attribute company
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def company @company end |
#country ⇒ Object
Returns the value of attribute country
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def country @country end |
#created_on ⇒ Object
Returns the value of attribute created_on
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def created_on @created_on end |
#custom_ticker ⇒ Object
Returns the value of attribute custom_ticker
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def custom_ticker @custom_ticker end |
#email ⇒ Object
Returns the value of attribute email
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def email @email end |
#first_name ⇒ Object
Returns the value of attribute first_name
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def first_name @first_name end |
#last_active ⇒ Object
Returns the value of attribute last_active
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def last_active @last_active end |
#last_login ⇒ Object
Returns the value of attribute last_login
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def last_login @last_login end |
#last_name ⇒ Object
Returns the value of attribute last_name
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def last_name @last_name end |
#newsletter ⇒ Object
Returns the value of attribute newsletter
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def @newsletter end |
#open_orders(reload = false) ⇒ Object
Open orders relation
13 14 15 |
# File 'lib/coinigy/subscription.rb', line 13 def open_orders @open_orders end |
#order_history(reload = false) ⇒ Object
Order history relation
13 14 15 |
# File 'lib/coinigy/subscription.rb', line 13 def order_history @order_history end |
#phone ⇒ Object
Returns the value of attribute phone
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def phone @phone end |
#pref_alert_email ⇒ Object
Returns the value of attribute pref_alert_email
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def pref_alert_email @pref_alert_email end |
#pref_alert_mobile ⇒ Object
Returns the value of attribute pref_alert_mobile
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def pref_alert_mobile @pref_alert_mobile end |
#pref_alert_sms ⇒ Object
Returns the value of attribute pref_alert_sms
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def pref_alert_sms @pref_alert_sms end |
#pref_app_device_id ⇒ Object
Returns the value of attribute pref_app_device_id
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def pref_app_device_id @pref_app_device_id end |
#pref_balance_email ⇒ Object
Returns the value of attribute pref_balance_email
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def pref_balance_email @pref_balance_email end |
#pref_referral_code ⇒ Object
Returns the value of attribute pref_referral_code
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def pref_referral_code @pref_referral_code end |
#pref_subscription_expires ⇒ Object
Returns the value of attribute pref_subscription_expires
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def pref_subscription_expires @pref_subscription_expires end |
#pref_trade_email ⇒ Object
Returns the value of attribute pref_trade_email
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def pref_trade_email @pref_trade_email end |
#pref_trade_mobile ⇒ Object
Returns the value of attribute pref_trade_mobile
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def pref_trade_mobile @pref_trade_mobile end |
#pref_trade_sms ⇒ Object
Returns the value of attribute pref_trade_sms
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def pref_trade_sms @pref_trade_sms end |
#preferences ⇒ Object
Preferences relation
13 14 15 |
# File 'lib/coinigy/subscription.rb', line 13 def preferences @preferences end |
#referral_balance ⇒ Object
Returns the value of attribute referral_balance
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def referral_balance @referral_balance end |
#state ⇒ Object
Returns the value of attribute state
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def state @state end |
#street1 ⇒ Object
Returns the value of attribute street1
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def street1 @street1 end |
#street2 ⇒ Object
Returns the value of attribute street2
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def street2 @street2 end |
#subscription_status ⇒ Object
Returns the value of attribute subscription_status
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def subscription_status @subscription_status end |
#ticker_enabled ⇒ Object
Returns the value of attribute ticker_enabled
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def ticker_enabled @ticker_enabled end |
#ticker_indicator_time_type ⇒ Object
Returns the value of attribute ticker_indicator_time_type
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def ticker_indicator_time_type @ticker_indicator_time_type end |
#two_factor ⇒ Object
Returns the value of attribute two_factor
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def two_factor @two_factor end |
#zip ⇒ Object
Returns the value of attribute zip
4 5 6 |
# File 'lib/coinigy/subscription.rb', line 4 def zip @zip end |
Class Method Details
.find(key, secret) ⇒ Object
Connects to the API with the credentials given and returns an instance of Subscription with the data of the user
24 25 26 27 28 29 |
# File 'lib/coinigy/subscription.rb', line 24 def self.find(key, secret) client = Coinigy::Client.new(key: key, secret: secret) attributes = client.user_info.data attributes[:client] = client new(attributes) end |
Instance Method Details
#add_account(name, exchange, key, secret) ⇒ Object
Registers a new account in the subscription and returns it
45 46 47 48 49 50 51 52 |
# File 'lib/coinigy/subscription.rb', line 45 def add_account(name, exchange, key, secret) new_attributes = { 'api_key' => key, 'api_secret' => secret, 'api_exch_id' => exchange, 'api_nickname' => name } response = client.add_api_key(new_attributes) return nil if response.error? accounts(true).find { |account| account.auth_id.to_i == response.data.to_i } rescue Exception => e nil end |
#alert_history(reload = false) ⇒ Object
Alert history relation
105 106 107 108 |
# File 'lib/coinigy/subscription.rb', line 105 def alert_history(reload = false) load_alerts(reload || @alert_history.nil?) @alert_history end |
#all_exchanges ⇒ Object
Return all exchanges supported at Coinigy
55 56 57 |
# File 'lib/coinigy/subscription.rb', line 55 def all_exchanges @all_exchanges ||= client.exchanges.data.map { |exchange_info| Coinigy::Exchange.new(exchange_info.merge({ subscription: self })) } end |
#attributes ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/coinigy/subscription.rb', line 15 def attributes { "first_name" => first_name, "last_name" => last_name, "company" => company, "phone" => phone, "street1" => street1, "street2" => street2, "city" => city, "state" => state, "zip" => zip, "country" => country } end |
#balance(show_nils = 0) ⇒ Object
Returns the mixed balance of the whole subscription
72 73 74 |
# File 'lib/coinigy/subscription.rb', line 72 def balance(show_nils = 0) balances([], show_nils) end |
#balance_history(date = Date.today.to_s) ⇒ Object
Returns the balance history for the provided date (separated per account)
77 78 79 |
# File 'lib/coinigy/subscription.rb', line 77 def balance_history(date = Date.today.to_s) client.balance_history(date) end |
#balances(ids = [], show_nils = 0) ⇒ Object
Returns the balances for the provided account ids
67 68 69 |
# File 'lib/coinigy/subscription.rb', line 67 def balances(ids = [], show_nils = 0) client.balances(ids.join(','), show_nils).data end |
#exchanges(reload = false) ⇒ Object
Exchanges relation
60 61 62 63 64 |
# File 'lib/coinigy/subscription.rb', line 60 def exchanges(reload = false) @exchanges = nil if reload exchanges_ids_in_accounts = accounts.map(&:exch_id).uniq @exchanges ||= all_exchanges.select {|exchange| exchanges_ids_in_accounts.include?(exchange.exch_id) } end |
#open_alerts(reload = false) ⇒ Object
Open alerts relation
99 100 101 102 |
# File 'lib/coinigy/subscription.rb', line 99 def open_alerts(reload = false) load_alerts(reload || @open_alerts.nil?) @open_alerts end |
#order_and_price_types ⇒ Object
Returns the list of order and price types
82 83 84 |
# File 'lib/coinigy/subscription.rb', line 82 def order_and_price_types @order_and_price_types ||= client.order_types.data end |