ig_markets 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -4
  3. data/README.md +70 -17
  4. data/lib/ig_markets.rb +27 -15
  5. data/lib/ig_markets/{account_activity.rb → activity.rb} +1 -1
  6. data/lib/ig_markets/cli/{account_command.rb → commands/account_command.rb} +5 -4
  7. data/lib/ig_markets/cli/commands/activities_command.rb +37 -0
  8. data/lib/ig_markets/cli/commands/confirmation_command.rb +14 -0
  9. data/lib/ig_markets/cli/{orders_command.rb → commands/orders_command.rb} +16 -21
  10. data/lib/ig_markets/cli/{positions_command.rb → commands/positions_command.rb} +31 -19
  11. data/lib/ig_markets/cli/commands/search_command.rb +18 -0
  12. data/lib/ig_markets/cli/commands/sentiment_command.rb +19 -0
  13. data/lib/ig_markets/cli/{sprints_command.rb → commands/sprints_command.rb} +10 -8
  14. data/lib/ig_markets/cli/commands/transactions_command.rb +61 -0
  15. data/lib/ig_markets/cli/{watchlists_command.rb → commands/watchlists_command.rb} +16 -12
  16. data/lib/ig_markets/cli/main.rb +65 -15
  17. data/lib/ig_markets/cli/tables/accounts_table.rb +30 -0
  18. data/lib/ig_markets/cli/tables/activities_table.rb +29 -0
  19. data/lib/ig_markets/cli/tables/client_sentiments_table.rb +31 -0
  20. data/lib/ig_markets/cli/tables/market_overviews_table.rb +47 -0
  21. data/lib/ig_markets/cli/tables/positions_table.rb +83 -0
  22. data/lib/ig_markets/cli/tables/sprint_market_positions_table.rb +55 -0
  23. data/lib/ig_markets/cli/tables/table.rb +103 -0
  24. data/lib/ig_markets/cli/tables/transactions_table.rb +41 -0
  25. data/lib/ig_markets/cli/tables/working_orders_table.rb +27 -0
  26. data/lib/ig_markets/dealing_platform/account_methods.rb +8 -8
  27. data/lib/ig_markets/dealing_platform/client_sentiment_methods.rb +4 -0
  28. data/lib/ig_markets/dealing_platform/market_methods.rb +1 -1
  29. data/lib/ig_markets/format.rb +20 -7
  30. data/lib/ig_markets/market_overview.rb +1 -1
  31. data/lib/ig_markets/model.rb +10 -1
  32. data/lib/ig_markets/model/typecasters.rb +1 -1
  33. data/lib/ig_markets/position.rb +12 -11
  34. data/lib/ig_markets/request_printer.rb +56 -0
  35. data/lib/ig_markets/response_parser.rb +11 -0
  36. data/lib/ig_markets/session.rb +7 -8
  37. data/lib/ig_markets/{account_transaction.rb → transaction.rb} +4 -17
  38. data/lib/ig_markets/version.rb +1 -1
  39. metadata +54 -16
  40. data/lib/ig_markets/cli/activities_command.rb +0 -31
  41. data/lib/ig_markets/cli/confirmation_command.rb +0 -16
  42. data/lib/ig_markets/cli/output.rb +0 -115
  43. data/lib/ig_markets/cli/search_command.rb +0 -16
  44. data/lib/ig_markets/cli/sentiment_command.rb +0 -24
  45. data/lib/ig_markets/cli/transactions_command.rb +0 -57
@@ -1,16 +0,0 @@
1
- module IGMarkets
2
- module CLI
3
- # Implements the `ig_markets search` command.
4
- class Main < Thor
5
- desc 'search <QUERY>', 'Searches markets based on the specified query string'
6
-
7
- def search(query)
8
- self.class.begin_session(options) do |dealing_platform|
9
- dealing_platform.markets.search(query).each do |market_overview|
10
- Output.print_market_overview market_overview
11
- end
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,24 +0,0 @@
1
- module IGMarkets
2
- module CLI
3
- # Implements the `ig_markets sentiment` command.
4
- class Main
5
- desc 'sentiment <MARKET>', 'Prints sentiment for the specified market'
6
-
7
- option :related, type: :boolean, desc: 'Whether to print sentiment for related markets as well'
8
-
9
- def sentiment(market)
10
- self.class.begin_session(options) do |dealing_platform|
11
- client_sentiment = dealing_platform.client_sentiment[market]
12
-
13
- Output.print_client_sentiment client_sentiment
14
-
15
- if options[:related]
16
- client_sentiment.related_sentiments.each do |model|
17
- Output.print_client_sentiment model
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,57 +0,0 @@
1
- module IGMarkets
2
- module CLI
3
- # Implements the `ig_markets transactions` command.
4
- class Main
5
- desc 'transactions', 'Prints account transactions'
6
-
7
- option :days, type: :numeric, required: true, desc: 'The number of days to print account transactions for'
8
- option :start_date, desc: 'The start date to print account transactions from, format: yyyy-mm-dd'
9
-
10
- def transactions
11
- self.class.begin_session(options) do |dealing_platform|
12
- transactions = gather_transactions(dealing_platform, options[:days], options[:start_date]).sort_by(&:date)
13
-
14
- transactions.each do |transaction|
15
- Output.print_transaction transaction
16
- end
17
-
18
- print_transaction_totals transactions
19
- end
20
- end
21
-
22
- private
23
-
24
- def gather_transactions(dealing_platform, days, start_date = nil)
25
- if start_date
26
- start_date = Date.strptime options[:start_date], '%F'
27
-
28
- dealing_platform.account.transactions_in_date_range start_date, start_date + days.to_i
29
- else
30
- dealing_platform.account.recent_transactions days
31
- end
32
- end
33
-
34
- def transaction_totals(transactions)
35
- transactions.each_with_object({}) do |transaction, hash|
36
- profit_loss = transaction.profit_and_loss_amount
37
-
38
- currency = (hash[transaction.currency] ||= Hash.new(0))
39
-
40
- currency[:delta] += profit_loss
41
- currency[:interest] += profit_loss if transaction.interest?
42
- end
43
- end
44
-
45
- def print_transaction_totals(transactions)
46
- transaction_totals(transactions).each do |currency, value|
47
- puts <<-END
48
-
49
- Totals for currency '#{currency}':
50
- Interest: #{Format.currency value[:interest], currency}
51
- Profit/loss: #{Format.currency value[:delta], currency}
52
- END
53
- end
54
- end
55
- end
56
- end
57
- end