ig_markets 0.28 → 0.29

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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -2
  3. data/README.md +9 -6
  4. data/lib/ig_markets.rb +1 -0
  5. data/lib/ig_markets/cli/commands/account_command.rb +1 -1
  6. data/lib/ig_markets/cli/commands/activities_command.rb +2 -2
  7. data/lib/ig_markets/cli/commands/markets_command.rb +1 -1
  8. data/lib/ig_markets/cli/commands/orders_command.rb +1 -1
  9. data/lib/ig_markets/cli/commands/performance_command.rb +2 -2
  10. data/lib/ig_markets/cli/commands/positions_command.rb +1 -1
  11. data/lib/ig_markets/cli/commands/prices_command.rb +1 -1
  12. data/lib/ig_markets/cli/commands/search_command.rb +1 -1
  13. data/lib/ig_markets/cli/commands/sentiment_command.rb +1 -1
  14. data/lib/ig_markets/cli/commands/sprints_command.rb +1 -1
  15. data/lib/ig_markets/cli/commands/stream_command.rb +6 -3
  16. data/lib/ig_markets/cli/commands/transactions_command.rb +2 -2
  17. data/lib/ig_markets/cli/commands/watchlists_command.rb +1 -1
  18. data/lib/ig_markets/cli/main.rb +5 -3
  19. data/lib/ig_markets/cli/tables/accounts_table.rb +29 -26
  20. data/lib/ig_markets/cli/tables/activities_table.rb +23 -21
  21. data/lib/ig_markets/cli/tables/client_sentiments_table.rb +21 -19
  22. data/lib/ig_markets/cli/tables/historical_price_result_snapshots_table.rb +17 -15
  23. data/lib/ig_markets/cli/tables/market_overviews_table.rb +29 -26
  24. data/lib/ig_markets/cli/tables/markets_table.rb +8 -6
  25. data/lib/ig_markets/cli/tables/performances_table.rb +25 -23
  26. data/lib/ig_markets/cli/tables/positions_table.rb +71 -69
  27. data/lib/ig_markets/cli/tables/sprint_market_positions_table.rb +39 -37
  28. data/lib/ig_markets/cli/tables/table.rb +70 -68
  29. data/lib/ig_markets/cli/tables/transactions_table.rb +30 -27
  30. data/lib/ig_markets/cli/tables/working_orders_table.rb +20 -17
  31. data/lib/ig_markets/dealing_platform/account_methods.rb +11 -11
  32. data/lib/ig_markets/instrument.rb +0 -6
  33. data/lib/ig_markets/limited_risk_premium.rb +8 -0
  34. data/lib/ig_markets/position.rb +1 -0
  35. data/lib/ig_markets/transaction.rb +1 -1
  36. data/lib/ig_markets/version.rb +1 -1
  37. data/lib/ig_markets/working_order.rb +1 -0
  38. metadata +17 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ddb9a35321ec6be744a90297554801dda3b386ac
4
- data.tar.gz: a48c71086d5b6384ebcd564bad98125fb4fd660f
3
+ metadata.gz: 187077cf0cdb9a078657a52a828e246bf7dcfe66
4
+ data.tar.gz: 1ce4e0be008ef0d432257ecc126ff0637b76bb89
5
5
  SHA512:
6
- metadata.gz: 377a03f5f52f38011387628d4beda79ba53bf611a4d079bcb6583d32bb8fa6d6a70ad7ce03e8d0d97f44733a80708c3cd0d8469c1dc466a50f7a65ab4f55601c
7
- data.tar.gz: ef6fd8c0825baffadcf19a21efe2e02e6bf7146b105f756a27f7bf7d251ae29a8f227c46282dcbfe3bc332b693117f4a34a3b79848c688528d91dbf81927cb75
6
+ metadata.gz: 4e50a5d55b0b8215a2c03e00f57424c61b0bddb04a8dc46558dd1fdc36a08b1335f0b8d37219bea25fdc8e0a5ca17822135ba3119718461ad0e0b84116c482d8
7
+ data.tar.gz: e509ac730be8ba25036a347649ebf059148f451405c77125a728de390acdbf30393c3d7ab0dc341f84837bff2adf8185568eb22d50623e74b75ba19e6abbf7e4
data/CHANGELOG.md CHANGED
@@ -1,9 +1,20 @@
1
1
  # IG Markets Changelog
2
2
 
3
+ ### 0.29 — March 8, 2017
4
+
5
+ - The `IGMarkets::AccountMethods#activities` and `IGMarkets::AccountMethods#transactions` now take `Time`
6
+ values for `:from` and `:to` instead of `Date` values
7
+ - The `ig_markets activities`, `ig_markets performance` and `ig_markets transactions` commands now expect
8
+ their optional `--from` option to be formatted as `yyyy-mm-ddThh:mm:ss`
9
+ - Fixed `IGMarkets::AccountMethods#activities` and `IGMarkets::AccountMethods#transactions` never returning
10
+ if there were more than 500 activities or transactions in a single day during the specified period
11
+ - Added `IGMarkets::Position#limited_risk_premium` and `IGMarkets::WorkingOrder#limited_risk_premium`
12
+ - Supprt the `chart` transaction type
13
+
3
14
  ### 0.28 — February 24, 2017
4
15
 
5
- - Added IGMarkets::Instrument#limited_risk_premium
6
- - Added IGMarkets::Transaction#open_date_utc
16
+ - Added `IGMarkets::Instrument#limited_risk_premium`
17
+ - Added `IGMarkets::Transaction#open_date_utc`
7
18
  - Added `#currency`, `#good_till_date`, `#order_type` and `#time_in_force` attributes to
8
19
  `IGMarkets::Streaming::WorkingOrderUpdate`
9
20
  - Fixed `IGMarkets::AccountState` not updating its working orders when a level update is received
data/README.md CHANGED
@@ -119,7 +119,7 @@ ig_markets account
119
119
  # Print EUR/USD transactions from the last week, excluding interest transactions
120
120
  ig_markets transactions --days 7 --instrument EUR/USD --no-interest
121
121
 
122
- # Search for EURUSD markets
122
+ # Search for EURUSD currency markets
123
123
  ig_markets search EURUSD --type currencies
124
124
 
125
125
  # Print details for the EURUSD pair and the Dow Jones Industrial Average
@@ -181,13 +181,16 @@ ig = IGMarkets::DealingPlatform.new
181
181
  ig.sign_in 'username', 'password', 'api_key', :demo
182
182
  ig.sign_out
183
183
 
184
+ one_week = 7 * 24 * 60 * 60
185
+ two_weeks = 14 * 24 * 60 * 60
186
+
184
187
  # Account
185
188
  ig.account.all
186
- ig.account.activities from: Date.today - 7
187
- ig.account.activities from: Date.today - 14, to: Date.today - 7
188
- ig.account.transactions from: Date.today - 7
189
- ig.account.transactions from: Date.today - 14, to: Date.today - 7
190
- ig.account.transactions from: Date.today - 14, to: Date.today - 7, type: :withdrawal
189
+ ig.account.activities from: Time.now - one_week
190
+ ig.account.activities from: Time.now - one_week, to: Time.now - one_week
191
+ ig.account.transactions from: Time.now - one_week
192
+ ig.account.transactions from: Time.now - two_weeks, to: Time.now - one_week
193
+ ig.account.transactions from: Time.now - two_weeks, to: Time.now - one_week, type: :withdrawal
191
194
 
192
195
  # Dealing
193
196
  ig.deal_confirmation 'deal_reference'
data/lib/ig_markets.rb CHANGED
@@ -35,6 +35,7 @@ require 'ig_markets/dealing_platform/watchlist_methods'
35
35
  require 'ig_markets/dealing_platform/working_order_methods'
36
36
  require 'ig_markets/errors'
37
37
  require 'ig_markets/format'
38
+ require 'ig_markets/limited_risk_premium'
38
39
  require 'ig_markets/instrument'
39
40
  require 'ig_markets/historical_price_result'
40
41
  require 'ig_markets/market'
@@ -8,7 +8,7 @@ module IGMarkets
8
8
  self.class.begin_session(options) do |dealing_platform|
9
9
  accounts = dealing_platform.account.all
10
10
 
11
- table = AccountsTable.new accounts
11
+ table = Tables::AccountsTable.new accounts
12
12
 
13
13
  puts table
14
14
  end
@@ -5,7 +5,7 @@ module IGMarkets
5
5
  desc 'activities', 'Prints account activities'
6
6
 
7
7
  option :days, type: :numeric, required: true, desc: 'The number of days to print account activities for'
8
- option :from, desc: 'The start date to print account activities from, format: yyyy-mm-dd'
8
+ option :from, desc: 'The date and time to print account activities from, format: yyyy-mm-ddThh:mm:ss'
9
9
  option :epic, desc: 'Regex for filtering activities based on their EPIC'
10
10
  option :sort_by, enum: %w(channel date epic type), default: 'date', desc: 'The attribute to sort activities by'
11
11
 
@@ -15,7 +15,7 @@ module IGMarkets
15
15
 
16
16
  activities = gather_activities dealing_platform
17
17
 
18
- table = ActivitiesTable.new activities
18
+ table = Tables::ActivitiesTable.new activities
19
19
 
20
20
  puts table
21
21
  end
@@ -8,7 +8,7 @@ module IGMarkets
8
8
  self.class.begin_session(options) do |dealing_platform|
9
9
  markets = dealing_platform.markets.find(*epics)
10
10
 
11
- table = MarketsTable.new markets
11
+ table = Tables::MarketsTable.new markets
12
12
 
13
13
  puts table
14
14
  end
@@ -8,7 +8,7 @@ module IGMarkets
8
8
  Main.begin_session(options) do |dealing_platform|
9
9
  working_orders = dealing_platform.working_orders.all
10
10
 
11
- table = WorkingOrdersTable.new working_orders
11
+ table = Tables::WorkingOrdersTable.new working_orders
12
12
 
13
13
  puts table
14
14
  end
@@ -5,14 +5,14 @@ module IGMarkets
5
5
  desc 'performance', 'Prints a summary of trading performance over a period'
6
6
 
7
7
  option :days, type: :numeric, required: true, desc: 'The number of days to print performance for'
8
- option :from, desc: 'The start date to show performance from, format: yyyy-mm-dd'
8
+ option :from, desc: 'The date and time to show performance from, format: yyyy-mm-ddThh:mm:ss'
9
9
 
10
10
  def performance
11
11
  self.class.begin_session(options) do |dealing_platform|
12
12
  performances = gather_performances dealing_platform
13
13
  lookup_instrument_names performances, dealing_platform
14
14
 
15
- table = PerformancesTable.new performances
15
+ table = Tables::PerformancesTable.new performances
16
16
 
17
17
  puts table
18
18
 
@@ -12,7 +12,7 @@ module IGMarkets
12
12
  position.market.instrument_type == :binary
13
13
  end
14
14
 
15
- positions_table = PositionsTable.new positions, aggregate: options[:aggregate]
15
+ positions_table = Tables::PositionsTable.new positions, aggregate: options[:aggregate]
16
16
 
17
17
  puts positions_table
18
18
 
@@ -19,7 +19,7 @@ module IGMarkets
19
19
  result = historical_price_result dealing_platform
20
20
  allowance = result.metadata.allowance
21
21
 
22
- table = HistoricalPriceResultSnapshotsTable.new result.prices, title: "Prices for #{options[:epic]}"
22
+ table = Tables::HistoricalPriceResultSnapshotsTable.new result.prices, title: "Prices for #{options[:epic]}"
23
23
 
24
24
  puts <<-END
25
25
  #{table}
@@ -11,7 +11,7 @@ module IGMarkets
11
11
  self.class.begin_session(options) do |dealing_platform|
12
12
  market_overviews = gather_market_overviews dealing_platform, query
13
13
 
14
- table = MarketOverviewsTable.new market_overviews
14
+ table = Tables::MarketOverviewsTable.new market_overviews
15
15
 
16
16
  puts table
17
17
  end
@@ -9,7 +9,7 @@ module IGMarkets
9
9
  client_sentiment = dealing_platform.client_sentiment[market]
10
10
  client_sentiments = [client_sentiment, :separator, client_sentiment.related_sentiments]
11
11
 
12
- table = ClientSentimentsTable.new client_sentiments, title: "Client sentiment for '#{market}'"
12
+ table = Tables::ClientSentimentsTable.new client_sentiments, title: "Client sentiment for '#{market}'"
13
13
 
14
14
  puts table
15
15
  end
@@ -10,7 +10,7 @@ module IGMarkets
10
10
 
11
11
  markets = dealing_platform.markets.find sprints.map(&:epic).uniq
12
12
 
13
- table = SprintMarketPositionsTable.new sprints, markets: markets
13
+ table = Tables::SprintMarketPositionsTable.new sprints, markets: markets
14
14
 
15
15
  puts table
16
16
  end
@@ -109,9 +109,12 @@ module IGMarkets
109
109
  account_state.process_queued_data
110
110
 
111
111
  window.clear
112
- window.print_lines AccountsTable.new(account_state.accounts).lines, '',
113
- PositionsTable.new(account_state.positions, aggregate: options[:aggregate]).lines, '',
114
- WorkingOrdersTable.new(account_state.working_orders).lines, ''
112
+ window.print_lines Tables::AccountsTable.new(account_state.accounts).lines,
113
+ '',
114
+ Tables::PositionsTable.new(account_state.positions, aggregate: options[:aggregate]).lines,
115
+ '',
116
+ Tables::WorkingOrdersTable.new(account_state.working_orders).lines,
117
+ ''
115
118
  window.refresh
116
119
  end
117
120
  end
@@ -5,7 +5,7 @@ module IGMarkets
5
5
  desc 'transactions', 'Prints account transactions'
6
6
 
7
7
  option :days, type: :numeric, required: true, desc: 'The number of days to print account transactions for'
8
- option :from, desc: 'The start date to print account transactions from, format: yyyy-mm-dd'
8
+ option :from, desc: 'The date and time to print account transactions from, format: yyyy-mm-ddThh:mm:ss'
9
9
  option :instrument, desc: 'Regex for filtering transactions based on their instrument'
10
10
  option :interest, type: :boolean, default: true, desc: 'Whether to show interest deposits and withdrawals'
11
11
  option :sort_by, enum: %w(date instrument profit-loss type), default: 'date', desc: 'The attribute to sort ' \
@@ -17,7 +17,7 @@ module IGMarkets
17
17
 
18
18
  transactions = gather_transactions dealing_platform
19
19
 
20
- table = TransactionsTable.new transactions
20
+ table = Tables::TransactionsTable.new transactions
21
21
 
22
22
  puts table
23
23
 
@@ -7,7 +7,7 @@ module IGMarkets
7
7
  def list
8
8
  Main.begin_session(options) do |dealing_platform|
9
9
  dealing_platform.watchlists.all.each_with_index do |watchlist, index|
10
- table = MarketOverviewsTable.new watchlist.markets, title: table_title(watchlist)
10
+ table = Tables::MarketOverviewsTable.new watchlist.markets, title: table_title(watchlist)
11
11
 
12
12
  puts '' if index > 0
13
13
  puts table
@@ -30,13 +30,15 @@ module IGMarkets
30
30
  # Turns the `:days` and `:from` options into a hash with `:from` and `:to` keys that can be passed to
31
31
  # {AccountMethods#activities} and {AccountMethods#transactions}.
32
32
  def history_options
33
+ days_in_seconds = options[:days] * 24 * 60 * 60
34
+
33
35
  if options[:from]
34
- from = Date.strptime options[:from], '%F'
35
- to = from + options[:days]
36
+ from = Time.strptime options[:from], '%FT%T'
37
+ to = from + days_in_seconds
36
38
 
37
39
  { from: from, to: to }
38
40
  else
39
- { from: Date.today - options[:days] }
41
+ { from: Time.now - days_in_seconds }
40
42
  end
41
43
  end
42
44
 
@@ -1,38 +1,41 @@
1
1
  module IGMarkets
2
2
  module CLI
3
- # Helper class that prints out an array of {IGMarkets::Account} instances in a table.
4
- class AccountsTable < Table
5
- private
3
+ module Tables
4
+ # Helper class that prints out an array of {IGMarkets::Account} instances in a table.
5
+ class AccountsTable < Table
6
+ private
6
7
 
7
- def default_title
8
- 'Accounts'
9
- end
8
+ def default_title
9
+ 'Accounts'
10
+ end
10
11
 
11
- def headings
12
- ['Name', 'ID', 'Type', 'Currency', 'Status', 'Preferred', 'Available', 'Balance', 'Margin', 'Profit/loss']
13
- end
12
+ def headings
13
+ ['Name', 'ID', 'Type', 'Currency', 'Status', 'Preferred', 'Available', 'Balance', 'Margin', 'Profit/loss']
14
+ end
14
15
 
15
- def right_aligned_columns
16
- [6, 7, 8, 9]
17
- end
16
+ def right_aligned_columns
17
+ [6, 7, 8, 9]
18
+ end
18
19
 
19
- def row(account)
20
- type = { cfd: 'CFD', physical: 'Physical', spreadbet: 'Spreadbet' }.fetch account.account_type
21
- status = { disabled: 'Disabled', enabled: 'Enabled', suspended_from_dealing: 'Suspended' }.fetch account.status
20
+ def row(account)
21
+ type = { cfd: 'CFD', physical: 'Physical', spreadbet: 'Spreadbet' }.fetch account.account_type
22
+ status = { disabled: 'Disabled', enabled: 'Enabled',
23
+ suspended_from_dealing: 'Suspended' }.fetch account.status
22
24
 
23
- [account.account_name, account.account_id, type, account.currency, status, account.preferred] +
24
- [:available, :balance, :deposit, :profit_loss].map do |attribute|
25
- Format.currency account.balance.send(attribute), account.currency
26
- end
27
- end
25
+ [account.account_name, account.account_id, type, account.currency, status, account.preferred] +
26
+ [:available, :balance, :deposit, :profit_loss].map do |attribute|
27
+ Format.currency account.balance.send(attribute), account.currency
28
+ end
29
+ end
28
30
 
29
- def cell_color(value, _model, _row_index, column_index)
30
- return unless headings[column_index] == 'Profit/loss'
31
+ def cell_color(value, _model, _row_index, column_index)
32
+ return unless headings[column_index] == 'Profit/loss'
31
33
 
32
- if value =~ /-/
33
- :red
34
- else
35
- :green
34
+ if value =~ /-/
35
+ :red
36
+ else
37
+ :green
38
+ end
36
39
  end
37
40
  end
38
41
  end
@@ -1,33 +1,35 @@
1
1
  module IGMarkets
2
2
  module CLI
3
- # Helper class that prints out an array of {IGMarkets::Activity} instances in a table.
4
- class ActivitiesTable < Table
5
- private
3
+ module Tables
4
+ # Helper class that prints out an array of {IGMarkets::Activity} instances in a table.
5
+ class ActivitiesTable < Table
6
+ private
6
7
 
7
- def default_title
8
- 'Activities'
9
- end
8
+ def default_title
9
+ 'Activities'
10
+ end
10
11
 
11
- def headings
12
- %w(Date Channel Type Status EPIC Market Size Level Limit Stop Result)
13
- end
12
+ def headings
13
+ %w(Date Channel Type Status EPIC Market Size Level Limit Stop Result)
14
+ end
14
15
 
15
- def right_aligned_columns
16
- [6, 7, 8, 9]
17
- end
16
+ def right_aligned_columns
17
+ [6, 7, 8, 9]
18
+ end
18
19
 
19
- def row(activity)
20
- details = activity.details
20
+ def row(activity)
21
+ details = activity.details
21
22
 
22
- [activity.date, activity.channel, activity.type, activity.status, activity.epic, details.market_name,
23
- details.size, details.level, details.limit_level, details.stop_level, action_types(details)]
24
- end
23
+ [activity.date, activity.channel, activity.type, activity.status, activity.epic, details.market_name,
24
+ details.size, details.level, details.limit_level, details.stop_level, action_types(details)]
25
+ end
25
26
 
26
- def action_types(details)
27
- types = details.actions.map(&:action_type).uniq
28
- types.delete :unknown
27
+ def action_types(details)
28
+ types = details.actions.map(&:action_type).uniq
29
+ types.delete :unknown
29
30
 
30
- types.map { |v| format_cell_value v }.join ', '
31
+ types.map { |v| format_cell_value v }.join ', '
32
+ end
31
33
  end
32
34
  end
33
35
  end
@@ -1,29 +1,31 @@
1
1
  module IGMarkets
2
2
  module CLI
3
- # Helper class that prints out an array of {IGMarkets::ClientSentiment} instances in a table.
4
- class ClientSentimentsTable < Table
5
- private
3
+ module Tables
4
+ # Helper class that prints out an array of {IGMarkets::ClientSentiment} instances in a table.
5
+ class ClientSentimentsTable < Table
6
+ private
6
7
 
7
- def headings
8
- ['Market', 'Long %', 'Short %']
9
- end
8
+ def headings
9
+ ['Market', 'Long %', 'Short %']
10
+ end
10
11
 
11
- def right_aligned_columns
12
- [1, 2]
13
- end
12
+ def right_aligned_columns
13
+ [1, 2]
14
+ end
14
15
 
15
- def row(client_sentiment)
16
- [client_sentiment.market_id, client_sentiment.long_position_percentage,
17
- client_sentiment.short_position_percentage]
18
- end
16
+ def row(client_sentiment)
17
+ [client_sentiment.market_id, client_sentiment.long_position_percentage,
18
+ client_sentiment.short_position_percentage]
19
+ end
19
20
 
20
- def cell_color(_value, client_sentiment, _row_index, _column_index)
21
- distance_from_center = (client_sentiment.long_position_percentage - 50.0).abs
21
+ def cell_color(_value, client_sentiment, _row_index, _column_index)
22
+ distance_from_center = (client_sentiment.long_position_percentage - 50.0).abs
22
23
 
23
- if distance_from_center > 35
24
- :red
25
- elsif distance_from_center > 20
26
- :yellow
24
+ if distance_from_center > 35
25
+ :red
26
+ elsif distance_from_center > 20
27
+ :yellow
28
+ end
27
29
  end
28
30
  end
29
31
  end
@@ -1,24 +1,26 @@
1
1
  module IGMarkets
2
2
  module CLI
3
- # Helper class that prints out an array of {IGMarkets::HistoricalPriceResult::Snapshot} instances in a table.
4
- class HistoricalPriceResultSnapshotsTable < Table
5
- private
3
+ module Tables
4
+ # Helper class that prints out an array of {IGMarkets::HistoricalPriceResult::Snapshot} instances in a table.
5
+ class HistoricalPriceResultSnapshotsTable < Table
6
+ private
6
7
 
7
- def headings
8
- %w(Date Open Close Low High)
9
- end
8
+ def headings
9
+ %w(Date Open Close Low High)
10
+ end
10
11
 
11
- def right_aligned_columns
12
- [1, 2, 3, 4]
13
- end
12
+ def right_aligned_columns
13
+ [1, 2, 3, 4]
14
+ end
14
15
 
15
- def row(snapshot)
16
- [snapshot.snapshot_time_utc, format_price(snapshot.open_price), format_price(snapshot.close_price),
17
- format_price(snapshot.low_price), format_price(snapshot.high_price)]
18
- end
16
+ def row(snapshot)
17
+ [snapshot.snapshot_time_utc, format_price(snapshot.open_price), format_price(snapshot.close_price),
18
+ format_price(snapshot.low_price), format_price(snapshot.high_price)]
19
+ end
19
20
 
20
- def format_price(price)
21
- (price.ask + price.bid) / 2.0
21
+ def format_price(price)
22
+ (price.ask + price.bid) / 2.0
23
+ end
22
24
  end
23
25
  end
24
26
  end