Class: Coinigy::Account

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

Overview

Represents an Account of a user subscription to Coinigy

Instance Attribute Summary collapse

Attributes inherited from Model

#errors

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

#auth_activeObject

Returns the value of attribute auth_active



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

def auth_active
  @auth_active
end

#auth_idObject

Returns the value of attribute auth_id



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

def auth_id
  @auth_id
end

#auth_keyObject

Returns the value of attribute auth_key



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

def auth_key
  @auth_key
end

#auth_nicknameObject

Returns the value of attribute auth_nickname



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

def auth_nickname
  @auth_nickname
end

#auth_optional1Object

Returns the value of attribute auth_optional1



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

def auth_optional1
  @auth_optional1
end

#auth_secretObject

Returns the value of attribute auth_secret



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

def auth_secret
  @auth_secret
end

#auth_tradeObject

Returns the value of attribute auth_trade



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

def auth_trade
  @auth_trade
end

#auth_updatedObject

Returns the value of attribute auth_updated



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

def auth_updated
  @auth_updated
end

#exch_idObject

Returns the value of attribute exch_id



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

def exch_id
  @exch_id
end

#exch_nameObject

Returns the value of attribute exch_name



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

def exch_name
  @exch_name
end

#exch_trade_enabledObject

Returns the value of attribute exch_trade_enabled



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

def exch_trade_enabled
  @exch_trade_enabled
end

#exchangeObject

Exchange relation



17
18
19
# File 'lib/coinigy/account.rb', line 17

def exchange
  @exchange
end

#subscriptionObject

Relations



17
18
19
# File 'lib/coinigy/account.rb', line 17

def subscription
  @subscription
end

Instance Method Details

#activate(flag = true) ⇒ Object

Activates or deactivates the account



39
40
41
# File 'lib/coinigy/account.rb', line 39

def activate(flag = true)
  send_to_server { subscription.client.activate_api_key(auth_id, flag ? 1 : 0) }
end

#attributesObject



19
20
21
22
23
24
25
26
# File 'lib/coinigy/account.rb', line 19

def attributes
  { "auth_id" => auth_id, "auth_key" => auth_key,
    "auth_optional1" => auth_optional1, "auth_nickname" => auth_nickname,
    "exch_name" => exch_name, "auth_secret" => auth_secret,
    "auth_active" => auth_active, "auth_updated" => auth_updated,
    "auth_trade" => auth_trade, "exch_trade_enabled" => exch_trade_enabled,
    "exch_id" => exch_id }
end

#balance(refresh = false) ⇒ Object

Returns the balance of this account



49
50
51
52
# File 'lib/coinigy/account.rb', line 49

def balance(refresh = false)
  return subscription.client.refresh_balance(auth_id).data if refresh
  subscription.balances([auth_id])
end

#buy(market_pair, limit_price, quantity) ⇒ Object



54
55
56
# File 'lib/coinigy/account.rb', line 54

def buy(market_pair, limit_price, quantity)
  place_order(Coinigy::Order::BUY, market_pair, limit_price, quantity)
end

#deleteObject

Deletes this account



44
45
46
# File 'lib/coinigy/account.rb', line 44

def delete
  send_to_server { subscription.client.delete_api_key(auth_id) }
end

#sell(market_pair, limit_price, quantity) ⇒ Object



58
59
60
# File 'lib/coinigy/account.rb', line 58

def sell(market_pair, limit_price, quantity)
  place_order(Coinigy::Order::SELL, market_pair, limit_price, quantity)
end

#trading(flag = true) ⇒ Object

Activates or deactivates the trading flag for the account



34
35
36
# File 'lib/coinigy/account.rb', line 34

def trading(flag = true)
  send_to_server { subscription.client.activate_trading_key(auth_id, flag ? 1 : 0) }
end