ig_markets 0.3 → 0.4

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.
@@ -4,8 +4,8 @@ module IGMarkets
4
4
  class Position < Model
5
5
  attribute :contract_size, Float
6
6
  attribute :controlled_risk, Boolean
7
- attribute :created_date, Time, format: '%Y/%m/%d %T:%L', time_zone: '+0000'
8
- attribute :created_date_utc, Time, format: '%FT%T', time_zone: '+0000'
7
+ attribute :created_date, Time, format: '%Y/%m/%d %T:%L'
8
+ attribute :created_date_utc, Time, format: '%FT%T'
9
9
  attribute :currency, String, regex: Regex::CURRENCY
10
10
  attribute :deal_id
11
11
  attribute :direction, Symbol, allowed_values: [:buy, :sell]
@@ -104,10 +104,7 @@ module IGMarkets
104
104
 
105
105
  private
106
106
 
107
- HOST_URLS = {
108
- demo: 'https://demo-api.ig.com/gateway/deal/',
109
- production: 'https://api.ig.com/gateway/deal/'
110
- }.freeze
107
+ HOST_URLS = { demo: 'https://demo-api.ig.com/gateway/deal/', production: 'https://api.ig.com/gateway/deal/' }.freeze
111
108
 
112
109
  def validate_authentication
113
110
  %i(username password api_key).each do |attribute|
@@ -120,10 +117,7 @@ module IGMarkets
120
117
  def password_encryptor
121
118
  result = get 'session/encryptionKey', API_V1
122
119
 
123
- PasswordEncryptor.new.tap do |encryptor|
124
- encryptor.encoded_public_key = result.fetch :encryption_key
125
- encryptor.time_stamp = result.fetch :time_stamp
126
- end
120
+ PasswordEncryptor.new result.fetch(:encryption_key), result.fetch(:time_stamp)
127
121
  end
128
122
 
129
123
  def request(options)
@@ -162,16 +156,25 @@ module IGMarkets
162
156
 
163
157
  RestClient::Request.execute options
164
158
  rescue RestClient::Exception => exception
165
- return exception.response if exception.response
159
+ raise RequestFailedError, exception.message unless exception.response
160
+
161
+ return exception.response unless !options[:retry] && client_token_invalid?(exception.response)
166
162
 
167
- raise RequestFailedError, exception.message
163
+ sign_in
164
+ execute_request options.merge(retry: true)
168
165
  rescue SocketError => socket_error
169
166
  raise RequestFailedError, socket_error
170
167
  end
171
168
 
169
+ def client_token_invalid?(response)
170
+ ResponseParser.parse(JSON.parse(response.body))[:error_code] == 'error.security.client-token-invalid'
171
+ rescue JSON::ParserError
172
+ false
173
+ end
174
+
172
175
  def process_response(response)
173
176
  result = begin
174
- ResponseParser.parse JSON.parse(response.body, symbolize_names: true)
177
+ ResponseParser.parse JSON.parse(response.body)
175
178
  rescue JSON::ParserError
176
179
  {}
177
180
  end
@@ -1,4 +1,4 @@
1
1
  module IGMarkets
2
2
  # The version of this gem.
3
- VERSION = '0.3'.freeze
3
+ VERSION = '0.4'.freeze
4
4
  end
@@ -3,14 +3,14 @@ module IGMarkets
3
3
  # {DealingPlatform::WorkingOrderMethods#[]}.
4
4
  class WorkingOrder < Model
5
5
  attribute :created_date, Time, format: '%Y/%m/%d %T:%L'
6
- attribute :created_date_utc, Time, format: '%FT%T', time_zone: '+0000'
6
+ attribute :created_date_utc, Time, format: '%FT%T'
7
7
  attribute :currency_code, String, regex: Regex::CURRENCY
8
8
  attribute :deal_id
9
9
  attribute :direction, Symbol, allowed_values: [:buy, :sell]
10
10
  attribute :dma, Boolean
11
11
  attribute :epic, String, regex: Regex::EPIC
12
- attribute :good_till_date, Time, format: '%Y/%m/%d %R', time_zone: '+0000'
13
- attribute :good_till_date_iso, Time, format: '%FT%R', time_zone: '+0000'
12
+ attribute :good_till_date, Time, format: '%Y/%m/%d %R'
13
+ attribute :good_till_date_iso, Time, format: '%FT%R'
14
14
  attribute :guaranteed_stop, Boolean
15
15
  attribute :limit_distance, Fixnum
16
16
  attribute :order_level, Float
@@ -38,7 +38,6 @@ module IGMarkets
38
38
  # @option new_attributes [Float] :level
39
39
  # @option new_attributes [Fixnum] :limit_distance
40
40
  # @option new_attributes [Fixnum] :stop_distance
41
- # @option new_attributes [:good_till_cancelled, :good_till_date] :time_in_force
42
41
  # @option new_attributes [:limit, :stop] :type
43
42
  #
44
43
  # @return [String] The deal reference of the update operation. Use {DealingPlatform#deal_confirmation} to check
@@ -48,6 +47,8 @@ module IGMarkets
48
47
  stop_distance: stop_distance, time_in_force: time_in_force, type: order_type
49
48
  }.merge new_attributes
50
49
 
50
+ new_attributes[:time_in_force] = new_attributes[:good_till_date] ? :good_till_date : :good_till_cancelled
51
+
51
52
  payload = PayloadFormatter.format WorkingOrderUpdateAttributes.new new_attributes
52
53
 
53
54
  @dealing_platform.session.put("workingorders/otc/#{deal_id}", payload, API_V1).fetch(:deal_reference)
@@ -55,7 +56,7 @@ module IGMarkets
55
56
 
56
57
  # Internal model used by {#update}.
57
58
  class WorkingOrderUpdateAttributes < Model
58
- attribute :good_till_date, Time, format: '%Y/%m/%d %R'
59
+ attribute :good_till_date, Time, format: '%Y/%m/%d %R:%S'
59
60
  attribute :level, Float
60
61
  attribute :limit_distance, Fixnum
61
62
  attribute :stop_distance, Fixnum
data/lib/ig_markets.rb CHANGED
@@ -13,17 +13,19 @@ require 'ig_markets/account_activity'
13
13
  require 'ig_markets/account_transaction'
14
14
  require 'ig_markets/api_versions'
15
15
  require 'ig_markets/application'
16
+ require 'ig_markets/cli/orders_command'
17
+ require 'ig_markets/cli/positions_command'
18
+ require 'ig_markets/cli/sprints_command'
19
+ require 'ig_markets/cli/watchlists_command'
16
20
  require 'ig_markets/cli/main'
17
21
  require 'ig_markets/cli/account_command'
18
22
  require 'ig_markets/cli/activities_command'
23
+ require 'ig_markets/cli/config_file'
19
24
  require 'ig_markets/cli/confirmation_command'
20
- require 'ig_markets/cli/orders_command'
21
- require 'ig_markets/cli/positions_command'
25
+ require 'ig_markets/cli/output'
22
26
  require 'ig_markets/cli/search_command'
23
27
  require 'ig_markets/cli/sentiment_command'
24
- require 'ig_markets/cli/sprints_command'
25
28
  require 'ig_markets/cli/transactions_command'
26
- require 'ig_markets/cli/watchlists_command'
27
29
  require 'ig_markets/client_sentiment'
28
30
  require 'ig_markets/deal_confirmation'
29
31
  require 'ig_markets/dealing_platform'
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.3'
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Viney
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-14 00:00:00.000000000 Z
11
+ date: 2016-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -157,7 +157,11 @@ executables:
157
157
  extensions: []
158
158
  extra_rdoc_files: []
159
159
  files:
160
+ - CHANGELOG.md
161
+ - LICENSE.md
162
+ - README.md
160
163
  - bin/ig_markets
164
+ - lib/ig_markets.rb
161
165
  - lib/ig_markets/account.rb
162
166
  - lib/ig_markets/account_activity.rb
163
167
  - lib/ig_markets/account_transaction.rb
@@ -166,9 +170,11 @@ files:
166
170
  - lib/ig_markets/boolean.rb
167
171
  - lib/ig_markets/cli/account_command.rb
168
172
  - lib/ig_markets/cli/activities_command.rb
173
+ - lib/ig_markets/cli/config_file.rb
169
174
  - lib/ig_markets/cli/confirmation_command.rb
170
175
  - lib/ig_markets/cli/main.rb
171
176
  - lib/ig_markets/cli/orders_command.rb
177
+ - lib/ig_markets/cli/output.rb
172
178
  - lib/ig_markets/cli/positions_command.rb
173
179
  - lib/ig_markets/cli/search_command.rb
174
180
  - lib/ig_markets/cli/sentiment_command.rb
@@ -177,6 +183,7 @@ files:
177
183
  - lib/ig_markets/cli/watchlists_command.rb
178
184
  - lib/ig_markets/client_sentiment.rb
179
185
  - lib/ig_markets/deal_confirmation.rb
186
+ - lib/ig_markets/dealing_platform.rb
180
187
  - lib/ig_markets/dealing_platform/account_methods.rb
181
188
  - lib/ig_markets/dealing_platform/client_sentiment_methods.rb
182
189
  - lib/ig_markets/dealing_platform/market_methods.rb
@@ -184,15 +191,14 @@ files:
184
191
  - lib/ig_markets/dealing_platform/sprint_market_position_methods.rb
185
192
  - lib/ig_markets/dealing_platform/watchlist_methods.rb
186
193
  - lib/ig_markets/dealing_platform/working_order_methods.rb
187
- - lib/ig_markets/dealing_platform.rb
188
194
  - lib/ig_markets/format.rb
189
195
  - lib/ig_markets/historical_price_result.rb
190
196
  - lib/ig_markets/instrument.rb
191
197
  - lib/ig_markets/market.rb
192
198
  - lib/ig_markets/market_hierarchy_result.rb
193
199
  - lib/ig_markets/market_overview.rb
194
- - lib/ig_markets/model/typecasters.rb
195
200
  - lib/ig_markets/model.rb
201
+ - lib/ig_markets/model/typecasters.rb
196
202
  - lib/ig_markets/password_encryptor.rb
197
203
  - lib/ig_markets/payload_formatter.rb
198
204
  - lib/ig_markets/position.rb
@@ -204,10 +210,6 @@ files:
204
210
  - lib/ig_markets/version.rb
205
211
  - lib/ig_markets/watchlist.rb
206
212
  - lib/ig_markets/working_order.rb
207
- - lib/ig_markets.rb
208
- - CHANGELOG.md
209
- - LICENSE.md
210
- - README.md
211
213
  homepage: https://github.com/rviney/ig_markets
212
214
  licenses:
213
215
  - MIT
@@ -228,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
230
  version: '0'
229
231
  requirements: []
230
232
  rubyforge_project:
231
- rubygems_version: 2.0.14
233
+ rubygems_version: 2.5.1
232
234
  signing_key:
233
235
  specification_version: 4
234
236
  summary: Ruby client for the IG Markets dealing platform.