Class: Coinigy::Subscription

Inherits:
Model
  • Object
show all
Defined in:
lib/coinigy/subscription.rb

Overview

Represents the Subscription to Coinigy, it holds all the info related

Instance Attribute Summary collapse

Attributes inherited from Model

#errors

Class Method Summary collapse

Instance Method Summary collapse

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

#activeObject

Returns the value of attribute active



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def active
  @active
end

#chat_enabledObject

Returns the value of attribute chat_enabled



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def chat_enabled
  @chat_enabled
end

#chat_nickObject

Returns the value of attribute chat_nick



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def chat_nick
  @chat_nick
end

#cityObject

Returns the value of attribute city



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def city
  @city
end

#clientObject

Relationships and other objects



13
14
15
# File 'lib/coinigy/subscription.rb', line 13

def client
  @client
end

#companyObject

Returns the value of attribute company



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def company
  @company
end

#countryObject

Returns the value of attribute country



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def country
  @country
end

#created_onObject

Returns the value of attribute created_on



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def created_on
  @created_on
end

#custom_tickerObject

Returns the value of attribute custom_ticker



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def custom_ticker
  @custom_ticker
end

#emailObject

Returns the value of attribute email



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def email
  @email
end

#first_nameObject

Returns the value of attribute first_name



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def first_name
  @first_name
end

#last_activeObject

Returns the value of attribute last_active



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def last_active
  @last_active
end

#last_loginObject

Returns the value of attribute last_login



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def 
  @last_login
end

#last_nameObject

Returns the value of attribute last_name



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def last_name
  @last_name
end

#newsletterObject

Returns the value of attribute newsletter



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def newsletter
  @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

#phoneObject

Returns the value of attribute phone



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def phone
  @phone
end

#pref_alert_emailObject

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_mobileObject

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_smsObject

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_idObject

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_emailObject

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_codeObject

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_expiresObject

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_emailObject

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_mobileObject

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_smsObject

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

#preferencesObject

Preferences relation



13
14
15
# File 'lib/coinigy/subscription.rb', line 13

def preferences
  @preferences
end

#referral_balanceObject

Returns the value of attribute referral_balance



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def referral_balance
  @referral_balance
end

#stateObject

Returns the value of attribute state



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def state
  @state
end

#street1Object

Returns the value of attribute street1



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def street1
  @street1
end

#street2Object

Returns the value of attribute street2



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def street2
  @street2
end

#subscription_statusObject

Returns the value of attribute subscription_status



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def subscription_status
  @subscription_status
end

#ticker_enabledObject

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_typeObject

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_factorObject

Returns the value of attribute two_factor



4
5
6
# File 'lib/coinigy/subscription.rb', line 4

def two_factor
  @two_factor
end

#zipObject

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..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 (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 { || .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_exchangesObject

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

#attributesObject



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_typesObject

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