rh-console 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/helpers/format_helpers.rb +12 -0
- data/lib/robinhood_client.rb +9 -16
- data/lib/robinhood_console.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1fc087e337bef189aac07044fea9bf8b7c56507a17b1af9766f2f330ad7aca8
|
4
|
+
data.tar.gz: c6c0860c9b68fb60fd2daa685cbda6d66bcd3b785f873d02b538cb340fb19b83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 245d0fc54eb0e26e0f07a76d6e9e4aafb65313bc483702f16a5f245fe3e098b3b2191158fe9ed959ec64bd037ff008de40fbae48b00edff375a24060eaeb3fc9
|
7
|
+
data.tar.gz: 51bff25f8bb675d4cf4406932894f67f8b3b3fa7d078e086fa3c4b0148ccee56619719faa9c2a9daa67ac02c87f86a3b5bb6710342d6cb3a142341f0846e0901
|
@@ -15,4 +15,16 @@ module FormatHelpers
|
|
15
15
|
rounded
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
# Add commas to a dollar amount
|
20
|
+
#
|
21
|
+
# @param value [String] a float dollar value
|
22
|
+
#
|
23
|
+
# @return [String] A string with commas added appropriately
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# commarize(3901.5) => "3,901.5"
|
27
|
+
def self.commarize(value)
|
28
|
+
value.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
|
29
|
+
end
|
18
30
|
end
|
data/lib/robinhood_client.rb
CHANGED
@@ -20,8 +20,12 @@ class RobinhoodClient
|
|
20
20
|
ROBINHOOD_ACCOUNTS_ROUTE = "https://api.robinhood.com/accounts/".freeze
|
21
21
|
# Route that returns authenticated user's order history
|
22
22
|
ROBINHOOD_ORDERS_ROUTE = "https://api.robinhood.com/orders/".freeze
|
23
|
+
# Route that returns the authenticated user's portfolio
|
24
|
+
ROBINHOOD_PORTFOLIO_ROUTE = "https://api.robinhood.com/portfolios/".freeze
|
23
25
|
# Route to fetch the authenticated user's default watchlist
|
24
26
|
ROBINHOOD_DEFAULT_WATCHLIST = "https://api.robinhood.com/watchlists/Default/".freeze
|
27
|
+
# Route to fetch the authenticated user's stock positions
|
28
|
+
ROBINHOOD_POSITIONS_ROUTE = "https://api.robinhood.com/positions/".freeze
|
25
29
|
# Route to fetch the authenticated user's option positions
|
26
30
|
ROBINHOOD_OPTIONS_POSITIONS_ROUTE = "https://api.robinhood.com/options/positions/".freeze
|
27
31
|
# Route to get a quote for an option ID
|
@@ -115,7 +119,7 @@ class RobinhoodClient
|
|
115
119
|
# my_new_client = RobinhoodClient.interactively_create_client
|
116
120
|
def self.interactively_create_client
|
117
121
|
print "Enter your username: "
|
118
|
-
username = gets.chomp
|
122
|
+
username = STDIN.gets.chomp
|
119
123
|
print "Password: "
|
120
124
|
password = STDIN.noecho(&:gets).chomp
|
121
125
|
|
@@ -328,6 +332,7 @@ class RobinhoodClient
|
|
328
332
|
instrument_urls.each do |instrument|
|
329
333
|
instruments_string += "#{instrument},"
|
330
334
|
end
|
335
|
+
instruments_string.chop!
|
331
336
|
params["instruments"] = instruments_string
|
332
337
|
quote = get(ROBINHOOD_OPTION_QUOTE_ROUTE, params: params, return_as_json: true)
|
333
338
|
quote["results"]
|
@@ -527,11 +532,12 @@ class RobinhoodClient
|
|
527
532
|
def stock_positions
|
528
533
|
position_params = {}
|
529
534
|
position_params["nonzero"] = true
|
530
|
-
get(
|
535
|
+
get("#{ROBINHOOD_POSITIONS_ROUTE}", params: position_params, return_as_json: true)["results"]
|
531
536
|
end
|
532
537
|
|
533
538
|
def portfolio
|
534
|
-
|
539
|
+
account_number = self.account["account_number"]
|
540
|
+
get("#{ROBINHOOD_PORTFOLIO_ROUTE}#{account_number}/", return_as_json: true)
|
535
541
|
end
|
536
542
|
|
537
543
|
def account
|
@@ -769,17 +775,4 @@ class RobinhoodClient
|
|
769
775
|
end
|
770
776
|
|
771
777
|
end
|
772
|
-
|
773
|
-
# Add commas to a dollar amount
|
774
|
-
#
|
775
|
-
# @param value [String] a float dollar value
|
776
|
-
#
|
777
|
-
# @return [String] A string with commas added appropriately
|
778
|
-
#
|
779
|
-
# @example
|
780
|
-
# commarize(3901.5) => "3,901.5"
|
781
|
-
def commarize(value)
|
782
|
-
value.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
|
783
|
-
end
|
784
|
-
|
785
778
|
end
|
data/lib/robinhood_console.rb
CHANGED
@@ -636,7 +636,7 @@ class RobinhoodConsole
|
|
636
636
|
|
637
637
|
all_time_portfolio_change += all_time_dollar_change
|
638
638
|
|
639
|
-
stock_position_rows << [stock["symbol"], "#{'%.2f' % quantity}", "$ #{'%.2f' % latest_price}", "$ #{'%.2f' % cost_basis}", "$ #{'%.2f' % day_dollar_change}".send(day_color), "#{'%.2f' % day_percent_change} %".send(day_color), "$ #{
|
639
|
+
stock_position_rows << [stock["symbol"], "#{'%.2f' % quantity}", "$ #{'%.2f' % latest_price}", "$ #{'%.2f' % cost_basis}", "$ #{'%.2f' % day_dollar_change}".send(day_color), "#{'%.2f' % day_percent_change} %".send(day_color), "$ #{FormatHelpers.commarize('%.2f' % all_time_dollar_change)}".send(all_time_color)]
|
640
640
|
end
|
641
641
|
|
642
642
|
options_positions.each do |option_position|
|
@@ -675,10 +675,10 @@ class RobinhoodConsole
|
|
675
675
|
|
676
676
|
all_time_portfolio_color = all_time_portfolio_change >= 0 ? :green : :red
|
677
677
|
|
678
|
-
portfolio_text += "\n\nHoldings: $ #{
|
679
|
-
portfolio_text += "Cash: $ #{
|
680
|
-
portfolio_text += "Equity: $ #{
|
681
|
-
portfolio_text += "\nAll time change on stock holdings: " + "$ #{
|
678
|
+
portfolio_text += "\n\nHoldings: $ #{FormatHelpers.commarize('%.2f' % portfolio["market_value"].to_f)}\n"
|
679
|
+
portfolio_text += "Cash: $ #{FormatHelpers.commarize('%.2f' % (account["cash"].to_f + account["unsettled_funds"].to_f))}\n"
|
680
|
+
portfolio_text += "Equity: $ #{FormatHelpers.commarize('%.2f' % portfolio["equity"].to_f)}\n"
|
681
|
+
portfolio_text += "\nAll time change on stock holdings: " + "$ #{FormatHelpers.commarize('%.2f' % all_time_portfolio_change)}\n".send(all_time_portfolio_color)
|
682
682
|
portfolio_text
|
683
683
|
|
684
684
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rh-console
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/brentjo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A command line interface to the Robinhood API. View your portfolio, stream
|
14
14
|
quotes, and place orders at the command line.
|