ig_markets 0.26 → 0.27

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 593ec96300d193a18f730b26cf9dedb9aec19f54
4
- data.tar.gz: fa29e0da14e82bfb9f53c266275d7a176286a124
3
+ metadata.gz: 38e42f2852c1b0b82d37dcd2268baeea8fe96285
4
+ data.tar.gz: 785316d7a75af12c80128175e93a8130e38a0182
5
5
  SHA512:
6
- metadata.gz: 11a54058f41f9a7e897be4040590eb35f4d1e18117c1ed2a021dc4040f0f937f930f57dcf6565de534e911c47c84139020519a03b0672ba5a28f34bddf66f97f
7
- data.tar.gz: 04def1bdd5817c224bac244e0caf332ae1aed58d951de207b220d061902d38f934b917ea9193a3945ae539d877fce8cc5a1abf2c51bdf7411a5401f950a1c2da
6
+ metadata.gz: 3513fd82d3776331f049479a649206b47803047645ec2a51695dde2492ebdfeaed15678da1ce32f9fca8ecdb5bfa91644f1a6619dbd7b1919a2555791a7382af
7
+ data.tar.gz: b0408775065f32ac25fe8e0e867ca011eb07e85a91be8508ac41a000a792bffed42fbcf2e38835a667b1f59e76186cd6014e22cb885fffac38c8382c7917512b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # IG Markets Changelog
2
2
 
3
+ ### 0.27 — January 18, 2017
4
+
5
+ - Added `IGMarkets::Format.colored_currency`
6
+ - Fixed `ig_markets help` command not working when using a config file
7
+
3
8
  ### 0.26 — January 12, 2017
4
9
 
5
10
  - Fully support Ruby 2.4
@@ -2,7 +2,7 @@ module IGMarkets
2
2
  module CLI
3
3
  # Implements the `ig_markets console` command.
4
4
  class Main < Thor
5
- desc 'console', 'Logs in and opens a live Ruby console, the IGMarkets::DealingPlatform instance is named \'ig\''
5
+ desc 'console', "Logs in and opens a live Ruby console, the IGMarkets::DealingPlatform instance is named 'ig'"
6
6
 
7
7
  def console
8
8
  self.class.begin_session(options) do |dealing_platform|
@@ -18,7 +18,7 @@ module IGMarkets
18
18
 
19
19
  desc 'create', 'Creates a new working order'
20
20
 
21
- option :currency_code, required: true, desc: 'The 3 character currency code, must be one of the instrument\'s ' \
21
+ option :currency_code, required: true, desc: "The 3 character currency code, must be one of the instrument's " \
22
22
  'currencies'
23
23
  option :direction, enum: %w(buy sell), required: true, desc: 'The trade direction'
24
24
  option :epic, required: true, desc: 'The EPIC of the market to trade'
@@ -65,7 +65,7 @@ module IGMarkets
65
65
  Note: this table only shows the profit/loss made from dealing, it does not include interest payments,
66
66
  dividends, or other adjustments that may have occurred over this period.
67
67
 
68
- Total: #{Format.currency(profit_loss, currency).colorize(profit_loss < 0 ? :red : :green)}
68
+ Total: #{Format.colored_currency profit_loss, currency}
69
69
  END
70
70
  end
71
71
  end
@@ -24,14 +24,14 @@ module IGMarkets
24
24
 
25
25
  desc 'create', 'Creates a new position'
26
26
 
27
- option :currency_code, required: true, desc: 'The 3 character currency code, must be one of the instrument\'s ' \
27
+ option :currency_code, required: true, desc: "The 3 character currency code, must be one of the instrument's " \
28
28
  'currencies'
29
29
  option :direction, required: true, enum: %w(buy sell), desc: 'The trade direction'
30
30
  option :epic, required: true, desc: 'The EPIC of the market to trade'
31
31
  option :expiry, desc: 'The expiry date of the instrument (if applicable), format: yyyy-mm-dd'
32
32
  option :force_open, type: :boolean, default: false, desc: 'Whether a force open is required'
33
33
  option :guaranteed_stop, type: :boolean, default: false, desc: 'Whether a guaranteed stop is required'
34
- option :level, type: :numeric, desc: 'Required if and only if --order-type is \'limit\' or \'quote\''
34
+ option :level, type: :numeric, desc: "Required if and only if --order-type is 'limit' or 'quote'"
35
35
  option :limit_distance, type: :numeric, desc: 'The distance away in pips to place the limit, if set then ' \
36
36
  '--limit-level must not be used'
37
37
  option :limit_level, type: :numeric, desc: 'The limit level, if set then --limit-distance must not be used'
@@ -70,7 +70,7 @@ module IGMarkets
70
70
 
71
71
  desc 'close DEAL-ID', 'Closes or partially closes a position'
72
72
 
73
- option :level, type: :numeric, desc: 'Required if and only if --order-type is \'limit\' or \'quote\''
73
+ option :level, type: :numeric, desc: "Required if and only if --order-type is 'limit' or 'quote'"
74
74
  option :order_type, enum: %w(limit market quote), default: 'market', desc: 'The order type'
75
75
  option :quote_id, desc: 'The Lightstreamer quote ID, required when using --order-type=quote'
76
76
  option :size, type: :numeric, desc: 'The size of the position to close, if not specified then the entire ' \
@@ -130,7 +130,7 @@ module IGMarkets
130
130
  currency_totals = positions.group_by(&:currency).map do |currency, subset|
131
131
  total = subset.map(&:profit_loss).reduce :+
132
132
 
133
- Format.currency(total, currency).colorize(total < 0 ? :red : :green)
133
+ Format.colored_currency total, currency
134
134
  end
135
135
 
136
136
  puts "\nTotal profit/loss: #{currency_totals.join ', '}"
@@ -46,7 +46,7 @@ module IGMarkets
46
46
  #
47
47
  # @param [Array<String>] argv The array of command-line arguments.
48
48
  def bootstrap(argv)
49
- config_file.prepend_profile_arguments_to_argv argv
49
+ config_file.prepend_profile_arguments_to_argv argv unless argv.first == 'help'
50
50
 
51
51
  if argv.index('--version') || argv.index('-v')
52
52
  puts VERSION
@@ -110,7 +110,7 @@ module IGMarkets
110
110
  begin
111
111
  attributes[attribute] = klass.strptime attributes[attribute], format
112
112
  rescue ArgumentError
113
- raise ArgumentError, "invalid #{attribute}, use format \"#{display_format}\""
113
+ raise ArgumentError, %(invalid #{attribute}, use format "#{display_format}")
114
114
  end
115
115
  else
116
116
  attributes[attribute] = nil
@@ -170,9 +170,7 @@ END
170
170
  def print_deal_confirmation_profit_loss(deal_confirmation)
171
171
  return unless deal_confirmation.profit
172
172
 
173
- profit = Format.currency deal_confirmation.profit, deal_confirmation.profit_currency
174
-
175
- puts "Profit/loss: #{profit.colorize(deal_confirmation.profit < 0 ? :red : :green)}"
173
+ puts "Profit/loss: #{Format.colored_currency deal_confirmation.profit, deal_confirmation.profit_currency}"
176
174
  end
177
175
  end
178
176
  end
@@ -1,6 +1,6 @@
1
1
  module IGMarkets
2
2
  # This is the primary class for interacting with the IG Markets API. After signing in using {#sign_in} most
3
- # functionality is accessed via the following top-level methods:
3
+ # functionality can be accessed using the following methods:
4
4
  #
5
5
  # - {#account}
6
6
  # - {#client_sentiment}
@@ -11,9 +11,9 @@ module IGMarkets
11
11
  # - {#working_orders}
12
12
  # - {#streaming}
13
13
  #
14
- # See `README.md` for examples.
14
+ # See `README.md` for code examples.
15
15
  #
16
- # If any errors occur while executing requests to the IG Markets API then an {IGMarketsError} will be raised.
16
+ # If any errors occur while executing requests to the IG Markets API then an {IGMarketsError} subclass will be raised.
17
17
  class DealingPlatform
18
18
  # The session used by this dealing platform.
19
19
  #
@@ -25,7 +25,7 @@ module IGMarkets
25
25
  # @return [ClientAccountSummary]
26
26
  attr_reader :client_account_summary
27
27
 
28
- # Methods for working with the logged in account.
28
+ # Methods for working with the balances and history of the logged in account.
29
29
  #
30
30
  # @return [AccountMethods]
31
31
  attr_reader :account
@@ -80,13 +80,13 @@ module IGMarkets
80
80
 
81
81
  # Signs in to the IG Markets Dealing Platform, either the live platform or the demo platform.
82
82
  #
83
- # @param [String] username The account username.
84
- # @param [String] password The account password.
85
- # @param [String] api_key The account API key.
83
+ # @param [String] username The IG Markets username.
84
+ # @param [String] password The IG Markets password.
85
+ # @param [String] api_key The IG Markets API key.
86
86
  # @param [:live, :demo] platform The platform to use.
87
87
  #
88
88
  # @return [ClientAccountSummary] The client account summary returned by the sign in request. This result can also
89
- # be accessed through the {#client_account_summary} accessor.
89
+ # be accessed later using {#client_account_summary}.
90
90
  def sign_in(username, password, api_key, platform)
91
91
  session.username = username
92
92
  session.password = password
@@ -118,9 +118,9 @@ module IGMarkets
118
118
  instantiate_models Application, session.get('operations/application')
119
119
  end
120
120
 
121
- # Disables the API key currently in use by the logged in session. This means that any further requests to the IG
122
- # Markets API with this key will fail with the error `error.security.api-key-disabled`. Disabled API keys can only
123
- # be re-enabled through the web platform.
121
+ # Disables the API key currently being used by the logged in session. This means that any further requests to the IG
122
+ # Markets API with this key will raise {Errors::APIKeyDisabledError}. Disabled API keys can only be re-enabled
123
+ # through the web platform.
124
124
  #
125
125
  # @return [Application]
126
126
  def disable_api_key
@@ -20,19 +20,34 @@ module IGMarkets
20
20
  # currencies except the Japanese Yen.
21
21
  #
22
22
  # @param [Float, Integer] amount The currency amount to format.
23
- # @param [String] currency The currency.
23
+ # @param [String] currency_name The name or symbol of the currency.
24
24
  #
25
25
  # @return [String] The formatted currency amount, e.g. `"USD -130.40"`, `"AUD 539.10"`, `"JPY 3560"`.
26
- def currency(amount, currency)
26
+ def currency(amount, currency_name)
27
27
  return '' unless amount
28
28
 
29
- if ['JPY', '¥'].include? currency
30
- "#{currency} #{format '%i', amount.to_i}"
29
+ if ['JPY', '¥'].include? currency_name
30
+ "#{currency_name} #{format '%i', amount.to_i}"
31
31
  else
32
- "#{currency} #{format '%.2f', amount.to_f}"
32
+ "#{currency_name} #{format '%.2f', amount.to_f}"
33
33
  end
34
34
  end
35
35
 
36
+ # Returns a formatted string for the specified currency amount and currency, and colors it red for negative values
37
+ # and green for positive values. Two decimal places are used for all currencies except the Japanese Yen.
38
+ #
39
+ # @param [Float, Integer] amount The currency amount to format.
40
+ # @param [String] currency_name The currency.
41
+ #
42
+ # @return [String] The formatted and colored currency amount, e.g. `"USD -130.40"`, `"AUD 539.10"`, `"JPY 3560"`.
43
+ def colored_currency(amount, currency_name)
44
+ return '' unless amount
45
+
46
+ color = amount < 0 ? :red : :green
47
+
48
+ currency(amount, currency_name).send color
49
+ end
50
+
36
51
  # Returns a formatted string for the specified number of seconds in the format `[<hours>:]<minutes>:<seconds>`.
37
52
  #
38
53
  # @param [Integer] value The number of seconds to format.
@@ -1,4 +1,4 @@
1
1
  module IGMarkets
2
2
  # The version of this gem.
3
- VERSION = '0.26'.freeze
3
+ VERSION = '0.27'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ig_markets
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.26'
4
+ version: '0.27'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Viney
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-12 00:00:00.000000000 Z
11
+ date: 2017-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -184,14 +184,14 @@ dependencies:
184
184
  requirements:
185
185
  - - "~>"
186
186
  - !ruby/object:Gem::Version
187
- version: '0.46'
187
+ version: '0.47'
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - "~>"
193
193
  - !ruby/object:Gem::Version
194
- version: '0.46'
194
+ version: '0.47'
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: simplecov
197
197
  requirement: !ruby/object:Gem::Requirement