Class: Scottrade::Brokerage

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/scottrade/brokerage.rb

Constant Summary collapse

KEYS_TO_VARIABLES =
{
  # accounts data keys
  "TotalAccountValue"                         => { :key => :total_value, :is_money => true },
  "TotalMoneyBalance"                         => { :key => :total_cash_balance, :is_money => true },
  "YesterdayTotalMoneyBalance"                => { :key => :yesterday_total_cash_balance, :is_money => true },
  "AvailableFreeCash"                         => { :key => :available_free_cash_blanace, :is_money => true },
  "TotalMarketValueWithOptions"               => { :key => :total_market_value_with_options, :is_money => true },
  "TotalMarketValueNoOptions"                 => { :key => :total_market_value_without_options, :is_money => true },
  "YesterdayTotalMarketValue"                 => { :key => :yesterday_total_market_value, :is_money => true },
  "TotalSettledFunds"                         => { :key => :total_settled_funds, :is_money => true },
  "TotalUnsettledSells"                       => { :key => :total_unsettled_sells, :is_money => true },
  "FundsAvailableToBuyNonMarginables"         => { :key => :funds_available_to_buy_non_marginables, :is_money => true },
  "FundsAvailableToBuyMarginables"            => { :key => :funds_available_to_buy_marginables, :is_money => true },
  "FundsAvailableToBuyOptions"                => { :key => :funds_available_to_buy_options, :is_money => true },
  "FundsAvailableToBuyMutualFunds"            => { :key => :funds_available_to_buy_mutual_funds, :is_money => true },
  "FundsAvailableForWithdraw"                 => { :key => :funds_available_for_withdraw, :is_money => true },
  "TodaysChangeApproxLiquidationValNoOptions" => { :key => :approximate_liquidation_value, :is_money => true },
  "BrokerageAccountBalance"                   => { :key => :account_balance, :is_money => true },
  # positions data keys
  "totalMktValue"                             => { :key => :current_market_value, :is_money => false },
  "totalPctChange"                            => { :key => :todays_percent_change,  :is_money => false },
  "toalPriceChange"                           => { :key => :todays_value_change, :is_money => false },
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#request_parameters

Constructor Details

#initialize(session) ⇒ Brokerage

Returns a new instance of Brokerage.



42
43
44
# File 'lib/scottrade/brokerage.rb', line 42

def initialize(session)
  @session = session
end

Instance Attribute Details

#account_balanceObject (readonly)

Returns the value of attribute account_balance.



10
11
12
# File 'lib/scottrade/brokerage.rb', line 10

def 
  @account_balance
end

#accountsObject (readonly)

Returns the value of attribute accounts.



14
15
16
# File 'lib/scottrade/brokerage.rb', line 14

def accounts
  @accounts
end

#approximate_liquidation_valueObject (readonly)

Returns the value of attribute approximate_liquidation_value.



13
14
15
# File 'lib/scottrade/brokerage.rb', line 13

def approximate_liquidation_value
  @approximate_liquidation_value
end

#available_free_cash_blanaceObject (readonly)

Returns the value of attribute available_free_cash_blanace.



10
11
12
# File 'lib/scottrade/brokerage.rb', line 10

def available_free_cash_blanace
  @available_free_cash_blanace
end

#current_market_valueObject (readonly)

Returns the value of attribute current_market_value.



15
16
17
# File 'lib/scottrade/brokerage.rb', line 15

def current_market_value
  @current_market_value
end

#funds_available_for_withdrawObject (readonly)

Returns the value of attribute funds_available_for_withdraw.



13
14
15
# File 'lib/scottrade/brokerage.rb', line 13

def funds_available_for_withdraw
  @funds_available_for_withdraw
end

#funds_available_to_buy_marginablesObject (readonly)

Returns the value of attribute funds_available_to_buy_marginables.



12
13
14
# File 'lib/scottrade/brokerage.rb', line 12

def funds_available_to_buy_marginables
  @funds_available_to_buy_marginables
end

#funds_available_to_buy_mutual_fundsObject (readonly)

Returns the value of attribute funds_available_to_buy_mutual_funds.



13
14
15
# File 'lib/scottrade/brokerage.rb', line 13

def funds_available_to_buy_mutual_funds
  @funds_available_to_buy_mutual_funds
end

#funds_available_to_buy_non_marginablesObject (readonly)

Returns the value of attribute funds_available_to_buy_non_marginables.



12
13
14
# File 'lib/scottrade/brokerage.rb', line 12

def funds_available_to_buy_non_marginables
  @funds_available_to_buy_non_marginables
end

#funds_available_to_buy_optionsObject (readonly)

Returns the value of attribute funds_available_to_buy_options.



13
14
15
# File 'lib/scottrade/brokerage.rb', line 13

def funds_available_to_buy_options
  @funds_available_to_buy_options
end

#positionsObject (readonly)

Returns the value of attribute positions.



14
15
16
# File 'lib/scottrade/brokerage.rb', line 14

def positions
  @positions
end

#todays_percent_changeObject (readonly)

Returns the value of attribute todays_percent_change.



15
16
17
# File 'lib/scottrade/brokerage.rb', line 15

def todays_percent_change
  @todays_percent_change
end

#todays_value_changeObject (readonly)

Returns the value of attribute todays_value_change.



15
16
17
# File 'lib/scottrade/brokerage.rb', line 15

def todays_value_change
  @todays_value_change
end

#total_cash_balanceObject (readonly)

Returns the value of attribute total_cash_balance.



10
11
12
# File 'lib/scottrade/brokerage.rb', line 10

def total_cash_balance
  @total_cash_balance
end

#total_market_value_with_optionsObject (readonly)

Returns the value of attribute total_market_value_with_options.



11
12
13
# File 'lib/scottrade/brokerage.rb', line 11

def total_market_value_with_options
  @total_market_value_with_options
end

#total_market_value_without_optionsObject (readonly)

Returns the value of attribute total_market_value_without_options.



11
12
13
# File 'lib/scottrade/brokerage.rb', line 11

def total_market_value_without_options
  @total_market_value_without_options
end

#total_settled_fundsObject (readonly)

Returns the value of attribute total_settled_funds.



12
13
14
# File 'lib/scottrade/brokerage.rb', line 12

def total_settled_funds
  @total_settled_funds
end

#total_unsettled_sellsObject (readonly)

Returns the value of attribute total_unsettled_sells.



12
13
14
# File 'lib/scottrade/brokerage.rb', line 12

def total_unsettled_sells
  @total_unsettled_sells
end

#total_valueObject (readonly)

Returns the value of attribute total_value.



10
11
12
# File 'lib/scottrade/brokerage.rb', line 10

def total_value
  @total_value
end

#yesterday_total_cash_balanceObject (readonly)

Returns the value of attribute yesterday_total_cash_balance.



10
11
12
# File 'lib/scottrade/brokerage.rb', line 10

def yesterday_total_cash_balance
  @yesterday_total_cash_balance
end

#yesterday_total_market_valueObject (readonly)

Returns the value of attribute yesterday_total_market_value.



11
12
13
# File 'lib/scottrade/brokerage.rb', line 11

def yesterday_total_market_value
  @yesterday_total_market_value
end

Instance Method Details

#update_accountsObject



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/scottrade/brokerage.rb', line 46

def update_accounts
  params = request_parameters("GetFrontEndMoneyBalances")
        
  response = session_post(params)
  set_variables_from_response(response)

  @accounts = []
  unparsed_accounts = response["AccTypeBalances"]
  unparsed_accounts.each{|acct|
    @accounts.push Account.new(acct)
  }
  
end

#update_positionsObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/scottrade/brokerage.rb', line 60

def update_positions
  params = request_parameters("GetPositions_v2")
  params["startRow"] = "0"
  params["noOfRows"] = "1000"
  params["returnRealTimeMktValue"] = "true"
  
  params["serviceID"] = "GetPositions_v2"
  
  response = session_post(params)
  
  set_variables_from_response(response)
  
  @positions = []
  all_positions = response["Positions"]
  all_positions.each{|pos|
    @positions.push Position.new(pos)
  }
end