ig_markets 0.9 → 0.10
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/CHANGELOG.md +8 -0
- data/README.md +9 -8
- data/lib/ig_markets/cli/commands/activities_command.rb +28 -1
- data/lib/ig_markets/cli/commands/positions_command.rb +15 -0
- data/lib/ig_markets/cli/commands/transactions_command.rb +24 -3
- data/lib/ig_markets/cli/config_file.rb +0 -2
- data/lib/ig_markets/cli/main.rb +0 -10
- data/lib/ig_markets/cli/tables/table.rb +2 -2
- data/lib/ig_markets/dealing_platform.rb +9 -0
- data/lib/ig_markets/model.rb +0 -2
- data/lib/ig_markets/request_printer.rb +0 -4
- data/lib/ig_markets/session.rb +5 -9
- data/lib/ig_markets/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 443589ca4b1af7f2e0de04ba1ca8be7f9b1450ec
|
4
|
+
data.tar.gz: 875b689e9ed88ec0b594b4dac26b43ff669366b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0402b33e23f7fd885d74382b50057242e9cd17fe53322e065180e09784f5a530a046a29bdecb88376e1ef7022eb9e21c26eac2db23752676795ba0783a6d29d4
|
7
|
+
data.tar.gz: f26909d155efbb51262d8fddabc0f6c1a72a2de743da7f6aa6ce09518e8c8834e500f087d285e8357980ab72a7319b69c38fd10609226aa9688eacffb05c0b65
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# IG Markets Changelog
|
2
2
|
|
3
|
+
### 0.10 — May 9, 2016
|
4
|
+
|
5
|
+
- Added `--epic` option to the `ig_markets activities` command
|
6
|
+
- Added `--sort-by` option to the `ig_markets activities` and `ig_markets transactions` commands
|
7
|
+
- The `--instrument` option for `ig_markets transactions` is no longer case-sensitive
|
8
|
+
- Added `ig_markets positions close-all` to close all open positions at once
|
9
|
+
- Added `IGMarkets::DealingPlatform#disable_api_key`
|
10
|
+
|
3
11
|
### 0.9 — May 2, 2016
|
4
12
|
|
5
13
|
- `IGMarkets::DealingPlatform#sign_in` now returns an `IGMarkets::ClientAccountSummary` instance
|
data/README.md
CHANGED
@@ -67,7 +67,7 @@ Use `ig_markets help` to get details on the options accepted by the commands and
|
|
67
67
|
commands and their subcommands is:
|
68
68
|
|
69
69
|
- `ig_markets account`
|
70
|
-
- `ig_markets activities --days N [
|
70
|
+
- `ig_markets activities --days N [...]`
|
71
71
|
- `ig_markets confirmation DEAL-REFERENCE`
|
72
72
|
- `ig_markets console`
|
73
73
|
- `ig_markets help [COMMAND]`
|
@@ -75,20 +75,21 @@ commands and their subcommands is:
|
|
75
75
|
- `ig_markets orders create ...`
|
76
76
|
- `ig_markets orders update DEAL-ID ...`
|
77
77
|
- `ig_markets orders delete DEAL-ID`
|
78
|
-
- `ig_markets positions [list] [
|
78
|
+
- `ig_markets positions [list] [...]`
|
79
79
|
- `ig_markets positions create ...`
|
80
80
|
- `ig_markets positions update DEAL-ID ...`
|
81
81
|
- `ig_markets positions close DEAL-ID [...]`
|
82
|
-
- `ig_markets
|
82
|
+
- `ig_markets positions close-all [...]`
|
83
|
+
- `ig_markets prices --epic EPIC --resolution RESOLUTION ...`
|
83
84
|
- `ig_markets search QUERY [--type TYPE]`
|
84
85
|
- `ig_markets sentiment MARKET`
|
85
86
|
- `ig_markets sprints [list]`
|
86
87
|
- `ig_markets sprints create ...`
|
87
|
-
- `ig_markets transactions --days N [
|
88
|
+
- `ig_markets transactions --days N [...]`
|
88
89
|
- `ig_markets watchlists [list]`
|
89
|
-
- `ig_markets watchlists create NAME [EPIC
|
90
|
-
- `ig_markets watchlists add-markets WATCHLIST-ID [EPIC
|
91
|
-
- `ig_markets watchlists remove-markets WATCHLIST-ID [EPIC
|
90
|
+
- `ig_markets watchlists create NAME [EPIC ...]`
|
91
|
+
- `ig_markets watchlists add-markets WATCHLIST-ID [EPIC ...]`
|
92
|
+
- `ig_markets watchlists remove-markets WATCHLIST-ID [EPIC ...]`
|
92
93
|
- `ig_markets watchlists delete WATCHLIST-ID`
|
93
94
|
|
94
95
|
#### Examples
|
@@ -127,7 +128,7 @@ ig_markets orders create --direction buy --epic CS.D.EURUSD.CFD.IP --level 1.1 -
|
|
127
128
|
# Print daily prices for EURUSD from the last two weeks
|
128
129
|
ig_markets prices --epic CS.D.EURUSD.CFD.IP --resolution day --number 14
|
129
130
|
|
130
|
-
# Log in and then open a Ruby console which can be used to query the IG API, all REST requests will be
|
131
|
+
# Log in and then open a Ruby console which can be used to query the IG API, all REST requests will be shown
|
131
132
|
ig_markets console --print-requests
|
132
133
|
```
|
133
134
|
|
@@ -6,10 +6,12 @@ module IGMarkets
|
|
6
6
|
|
7
7
|
option :days, type: :numeric, required: true, desc: 'The number of days to print account activities for'
|
8
8
|
option :from, desc: 'The start date to print account activities from, format: yyyy-mm-dd'
|
9
|
+
option :epic, desc: 'Regex for filtering activities based on their EPIC'
|
10
|
+
option :sort_by, enum: %w(channel date epic type), default: 'date', desc: 'The attribute to sort activities by'
|
9
11
|
|
10
12
|
def activities
|
11
13
|
self.class.begin_session(options) do |dealing_platform|
|
12
|
-
activities =
|
14
|
+
activities = gather_activities dealing_platform
|
13
15
|
|
14
16
|
table = ActivitiesTable.new activities
|
15
17
|
|
@@ -19,6 +21,31 @@ module IGMarkets
|
|
19
21
|
|
20
22
|
private
|
21
23
|
|
24
|
+
def gather_activities(dealing_platform)
|
25
|
+
@epic_regex = Regexp.new options.fetch('epic', ''), Regexp::IGNORECASE
|
26
|
+
|
27
|
+
result = gather_account_history(:activities, dealing_platform).select do |activity|
|
28
|
+
activity_filter activity
|
29
|
+
end
|
30
|
+
|
31
|
+
result.sort_by do |activity|
|
32
|
+
[activity.send(activity_sort_attribute), activity.date]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def activity_filter(activity)
|
37
|
+
@epic_regex.match activity.epic
|
38
|
+
end
|
39
|
+
|
40
|
+
def activity_sort_attribute
|
41
|
+
{
|
42
|
+
'channel' => :channel,
|
43
|
+
'date' => :date,
|
44
|
+
'epic' => :epic,
|
45
|
+
'type' => :transaction_type
|
46
|
+
}.fetch options[:sort_by]
|
47
|
+
end
|
48
|
+
|
22
49
|
def gather_account_history(method_name, dealing_platform)
|
23
50
|
history_options = if options[:from]
|
24
51
|
from = Date.strptime options[:from], '%F'
|
@@ -83,6 +83,21 @@ module IGMarkets
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
+
desc 'close-all', 'Closes all open positions'
|
87
|
+
|
88
|
+
option :order_type, enum: %w(limit market quote), default: 'market', desc: 'The order type'
|
89
|
+
option :time_in_force, enum: %w(execute-and-eliminate fill-or-kill), desc: 'The order fill strategy'
|
90
|
+
|
91
|
+
def close_all
|
92
|
+
Main.begin_session(options) do |dealing_platform|
|
93
|
+
dealing_platform.positions.all.each do |position|
|
94
|
+
deal_reference = position.close position_attributes
|
95
|
+
|
96
|
+
Main.report_deal_confirmation deal_reference
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
86
101
|
private
|
87
102
|
|
88
103
|
ATTRIBUTES = [:currency_code, :direction, :epic, :expiry, :force_open, :guaranteed_stop, :level, :limit_distance,
|
@@ -8,6 +8,8 @@ module IGMarkets
|
|
8
8
|
option :from, desc: 'The start date to print account transactions from, format: yyyy-mm-dd'
|
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
|
+
option :sort_by, enum: %w(date instrument profit-loss type), default: 'date', desc: 'The attribute to sort ' \
|
12
|
+
'transactions by'
|
11
13
|
|
12
14
|
def transactions
|
13
15
|
self.class.begin_session(options) do |dealing_platform|
|
@@ -27,11 +29,30 @@ module IGMarkets
|
|
27
29
|
private
|
28
30
|
|
29
31
|
def gather_transactions(dealing_platform)
|
30
|
-
|
32
|
+
@instrument_regex = Regexp.new options.fetch('instrument', ''), Regexp::IGNORECASE
|
31
33
|
|
32
|
-
gather_account_history(:transactions, dealing_platform).
|
33
|
-
|
34
|
+
result = gather_account_history(:transactions, dealing_platform).select do |transaction|
|
35
|
+
transaction_filter transaction
|
34
36
|
end
|
37
|
+
|
38
|
+
result.sort_by do |transaction|
|
39
|
+
[transaction.send(transaction_sort_attribute), transaction.date_utc]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def transaction_filter(transaction)
|
44
|
+
return false if !options[:interest] && transaction.interest?
|
45
|
+
|
46
|
+
@instrument_regex.match transaction.instrument_name
|
47
|
+
end
|
48
|
+
|
49
|
+
def transaction_sort_attribute
|
50
|
+
{
|
51
|
+
'date' => :date_utc,
|
52
|
+
'instrument' => :instrument_name,
|
53
|
+
'profit-loss' => :profit_and_loss_amount,
|
54
|
+
'type' => :transaction_type
|
55
|
+
}.fetch options[:sort_by]
|
35
56
|
end
|
36
57
|
|
37
58
|
def transaction_totals(transactions)
|
@@ -22,8 +22,6 @@ module IGMarkets
|
|
22
22
|
# Inserts the arguments from this config file into the passed arguments array.
|
23
23
|
#
|
24
24
|
# @param [Array<String>] argv The array of command-line arguments to alter.
|
25
|
-
#
|
26
|
-
# @return [void]
|
27
25
|
def prepend_arguments_to_argv(argv)
|
28
26
|
insert_index = argv.index do |argument|
|
29
27
|
argument[0] == '-'
|
data/lib/ig_markets/cli/main.rb
CHANGED
@@ -26,8 +26,6 @@ module IGMarkets
|
|
26
26
|
# any config files, implementing the --version/-v options, and then invoking the main application.
|
27
27
|
#
|
28
28
|
# @param [Array<String>] argv The array of command-line arguments.
|
29
|
-
#
|
30
|
-
# @return [void]
|
31
29
|
def bootstrap(argv)
|
32
30
|
config_file.prepend_arguments_to_argv argv
|
33
31
|
|
@@ -43,8 +41,6 @@ module IGMarkets
|
|
43
41
|
# occur. This method is used by all of the commands in order to authenticate.
|
44
42
|
#
|
45
43
|
# @param [Thor::CoreExt::HashWithIndifferentAccess] options The Thor options hash.
|
46
|
-
#
|
47
|
-
# @return [void]
|
48
44
|
def begin_session(options)
|
49
45
|
platform = options[:demo] ? :demo : :production
|
50
46
|
|
@@ -65,8 +61,6 @@ module IGMarkets
|
|
65
61
|
# This is done because sometimes there is a delay in the processing of the deal by IG Markets.
|
66
62
|
#
|
67
63
|
# @param [String] deal_reference The deal reference.
|
68
|
-
#
|
69
|
-
# @return [void]
|
70
64
|
def report_deal_confirmation(deal_reference)
|
71
65
|
puts "Deal reference: #{deal_reference}"
|
72
66
|
|
@@ -89,8 +83,6 @@ module IGMarkets
|
|
89
83
|
# @param [String] format The `strptime` format string for the attribute.
|
90
84
|
# @param [String] display_format The human-readable version of `format` to put into the raised exception if
|
91
85
|
# there is a problem parsing the attribute.
|
92
|
-
#
|
93
|
-
# @return [void]
|
94
86
|
def parse_date_time(attributes, attribute, klass, format, display_format)
|
95
87
|
return unless attributes.key? attribute
|
96
88
|
|
@@ -141,8 +133,6 @@ module IGMarkets
|
|
141
133
|
# Prints out details of the passed deal confirmation.
|
142
134
|
#
|
143
135
|
# @param [DealConfirmation] deal_confirmation The deal confirmation to print out.
|
144
|
-
#
|
145
|
-
# @return [void]
|
146
136
|
def print_deal_confirmation(deal_confirmation)
|
147
137
|
puts <<-END
|
148
138
|
Deal ID: #{deal_confirmation.deal_id}
|
@@ -8,7 +8,7 @@ module IGMarkets
|
|
8
8
|
# @param [Hash] options The options hash.
|
9
9
|
# @option options [String] :title The title for this table.
|
10
10
|
def initialize(models, options = {})
|
11
|
-
@models = models
|
11
|
+
@models = Array(models).flatten
|
12
12
|
@title = options[:title] || default_title
|
13
13
|
end
|
14
14
|
|
@@ -43,7 +43,7 @@ module IGMarkets
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def rows
|
46
|
-
@models.
|
46
|
+
@models.each_with_index.map do |model, row_index|
|
47
47
|
if model == :separator
|
48
48
|
:separator
|
49
49
|
else
|
@@ -88,6 +88,15 @@ module IGMarkets
|
|
88
88
|
instantiate_models Application, session.get('operations/application')
|
89
89
|
end
|
90
90
|
|
91
|
+
# Disables the API key currently in use by the logged in session. This means that any further requests to the IG
|
92
|
+
# Markets API with this key will fail with the error `error.security.api-key-disabled`. Disabled API keys can only
|
93
|
+
# be re-enabled through the web platform.
|
94
|
+
#
|
95
|
+
# @return [Application]
|
96
|
+
def disable_api_key
|
97
|
+
instantiate_models Application, session.put('operations/application/disable')
|
98
|
+
end
|
99
|
+
|
91
100
|
# This method is used to instantiate the various `Model` subclasses from data returned by the IG Markets API. It
|
92
101
|
# recurses through arrays and sub-hashes present in `source`, instantiating the required models based on the types
|
93
102
|
# of each attribute as defined on the models. All model instances returned by this method will have their
|
data/lib/ig_markets/model.rb
CHANGED
@@ -126,8 +126,6 @@ module IGMarkets
|
|
126
126
|
# attributes to be set on the model but not have them be part of the model's structure.
|
127
127
|
#
|
128
128
|
# @param [Array<Symbol>] names The names of the deprecated attributes.
|
129
|
-
#
|
130
|
-
# @return [void]
|
131
129
|
def deprecated_attribute(*names)
|
132
130
|
names.each do |name|
|
133
131
|
define_method "#{name}=" do |_value|
|
@@ -9,8 +9,6 @@ module IGMarkets
|
|
9
9
|
# Prints out an options hash that is ready to be passed to `RestClient::Request.execute`.
|
10
10
|
#
|
11
11
|
# @param [Hash] options The options hash.
|
12
|
-
#
|
13
|
-
# @return [void]
|
14
12
|
def print_options(options)
|
15
13
|
return unless enabled
|
16
14
|
|
@@ -27,8 +25,6 @@ module IGMarkets
|
|
27
25
|
# Formats and prints a JSON response body.
|
28
26
|
#
|
29
27
|
# @param [String] body The response body.
|
30
|
-
#
|
31
|
-
# @return [void]
|
32
28
|
def print_response_body(body)
|
33
29
|
return unless enabled
|
34
30
|
|
data/lib/ig_markets/session.rb
CHANGED
@@ -84,7 +84,7 @@ module IGMarkets
|
|
84
84
|
# @param [Fixnum] api_version The API version to target.
|
85
85
|
#
|
86
86
|
# @return [Hash] The response from the IG Markets API.
|
87
|
-
def put(url, payload, api_version = API_V1)
|
87
|
+
def put(url, payload = nil, api_version = API_V1)
|
88
88
|
request(method: :put, url: url, payload: payload, api_version: api_version).fetch :result
|
89
89
|
end
|
90
90
|
|
@@ -99,16 +99,12 @@ module IGMarkets
|
|
99
99
|
request(method: :delete, url: url, payload: payload, api_version: api_version).fetch :result
|
100
100
|
end
|
101
101
|
|
102
|
-
# Returns a human-readable string containing this session's details.
|
103
|
-
#
|
104
|
-
# @return [String]
|
105
|
-
def inspect
|
106
|
-
"#<#{self.class.name} #{client_security_token}, #{x_security_token}>"
|
107
|
-
end
|
108
|
-
|
109
102
|
private
|
110
103
|
|
111
|
-
HOST_URLS = {
|
104
|
+
HOST_URLS = {
|
105
|
+
demo: 'https://demo-api.ig.com/gateway/deal/',
|
106
|
+
production: 'https://api.ig.com/gateway/deal/'
|
107
|
+
}.freeze
|
112
108
|
|
113
109
|
def validate_authentication
|
114
110
|
%i(username password api_key).each do |attribute|
|
data/lib/ig_markets/version.rb
CHANGED
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.
|
4
|
+
version: '0.10'
|
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-05-
|
11
|
+
date: 2016-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|