ig_markets 0.1
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 +7 -0
- data/.codeclimate.yml +15 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +10 -0
- data/.yardopts +4 -0
- data/Gemfile +2 -0
- data/LICENSE.md +25 -0
- data/README.md +134 -0
- data/ig_markets.gemspec +28 -0
- data/lib/ig_markets.rb +42 -0
- data/lib/ig_markets/account.rb +23 -0
- data/lib/ig_markets/account_activity.rb +24 -0
- data/lib/ig_markets/account_transaction.rb +49 -0
- data/lib/ig_markets/api_versions.rb +10 -0
- data/lib/ig_markets/application.rb +22 -0
- data/lib/ig_markets/boolean.rb +5 -0
- data/lib/ig_markets/client_sentiment.rb +16 -0
- data/lib/ig_markets/deal_confirmation.rb +41 -0
- data/lib/ig_markets/dealing_platform.rb +105 -0
- data/lib/ig_markets/dealing_platform/account_methods.rb +92 -0
- data/lib/ig_markets/dealing_platform/client_sentiment_methods.rb +26 -0
- data/lib/ig_markets/dealing_platform/market_methods.rb +59 -0
- data/lib/ig_markets/dealing_platform/position_methods.rb +164 -0
- data/lib/ig_markets/dealing_platform/sprint_market_position_methods.rb +46 -0
- data/lib/ig_markets/dealing_platform/watchlist_methods.rb +42 -0
- data/lib/ig_markets/dealing_platform/working_order_methods.rb +115 -0
- data/lib/ig_markets/historical_price_result.rb +33 -0
- data/lib/ig_markets/instrument.rb +89 -0
- data/lib/ig_markets/market.rb +99 -0
- data/lib/ig_markets/market_hierarchy_result.rb +13 -0
- data/lib/ig_markets/market_overview.rb +24 -0
- data/lib/ig_markets/model.rb +185 -0
- data/lib/ig_markets/password_encryptor.rb +31 -0
- data/lib/ig_markets/payload_formatter.rb +38 -0
- data/lib/ig_markets/position.rb +191 -0
- data/lib/ig_markets/regex.rb +10 -0
- data/lib/ig_markets/request_failed_error.rb +21 -0
- data/lib/ig_markets/response_parser.rb +35 -0
- data/lib/ig_markets/session.rb +186 -0
- data/lib/ig_markets/sprint_market_position.rb +17 -0
- data/lib/ig_markets/version.rb +4 -0
- data/lib/ig_markets/watchlist.rb +37 -0
- data/lib/ig_markets/working_order.rb +68 -0
- data/spec/factories/ig_markets/account.rb +14 -0
- data/spec/factories/ig_markets/account_activity.rb +21 -0
- data/spec/factories/ig_markets/account_balance.rb +8 -0
- data/spec/factories/ig_markets/account_transaction.rb +15 -0
- data/spec/factories/ig_markets/application.rb +21 -0
- data/spec/factories/ig_markets/client_sentiment.rb +7 -0
- data/spec/factories/ig_markets/deal_confirmation.rb +20 -0
- data/spec/factories/ig_markets/historical_price_result.rb +7 -0
- data/spec/factories/ig_markets/historical_price_result_data_allowance.rb +7 -0
- data/spec/factories/ig_markets/historical_price_result_price.rb +7 -0
- data/spec/factories/ig_markets/historical_price_result_snapshot.rb +10 -0
- data/spec/factories/ig_markets/instrument.rb +32 -0
- data/spec/factories/ig_markets/instrument_currency.rb +9 -0
- data/spec/factories/ig_markets/instrument_expiry_details.rb +6 -0
- data/spec/factories/ig_markets/instrument_margin_deposit_band.rb +8 -0
- data/spec/factories/ig_markets/instrument_opening_hours.rb +6 -0
- data/spec/factories/ig_markets/instrument_rollover_details.rb +6 -0
- data/spec/factories/ig_markets/instrument_slippage_factor.rb +6 -0
- data/spec/factories/ig_markets/market.rb +7 -0
- data/spec/factories/ig_markets/market_dealing_rules.rb +11 -0
- data/spec/factories/ig_markets/market_dealing_rules_rule_details.rb +6 -0
- data/spec/factories/ig_markets/market_hierarchy_result.rb +6 -0
- data/spec/factories/ig_markets/market_hierarchy_result_hierarchy_node.rb +6 -0
- data/spec/factories/ig_markets/market_overview.rb +22 -0
- data/spec/factories/ig_markets/market_snapshot.rb +17 -0
- data/spec/factories/ig_markets/position.rb +19 -0
- data/spec/factories/ig_markets/sprint_market_position.rb +16 -0
- data/spec/factories/ig_markets/watchlist.rb +9 -0
- data/spec/factories/ig_markets/working_order.rb +21 -0
- data/spec/ig_markets/account_transaction_spec.rb +30 -0
- data/spec/ig_markets/dealing_platform/account_methods_spec.rb +58 -0
- data/spec/ig_markets/dealing_platform/client_sentiment_methods_spec.rb +29 -0
- data/spec/ig_markets/dealing_platform/market_methods_spec.rb +80 -0
- data/spec/ig_markets/dealing_platform/position_methods_spec.rb +137 -0
- data/spec/ig_markets/dealing_platform/sprint_market_position_methods_spec.rb +39 -0
- data/spec/ig_markets/dealing_platform/watchlist_methods_spec.rb +89 -0
- data/spec/ig_markets/dealing_platform/working_order_methods_spec.rb +120 -0
- data/spec/ig_markets/dealing_platform_spec.rb +40 -0
- data/spec/ig_markets/model_spec.rb +127 -0
- data/spec/ig_markets/password_encryptor_spec.rb +23 -0
- data/spec/ig_markets/payload_formatter_spec.rb +19 -0
- data/spec/ig_markets/position_spec.rb +37 -0
- data/spec/ig_markets/response_parser_spec.rb +13 -0
- data/spec/ig_markets/session_spec.rb +134 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/support/factory_girl.rb +7 -0
- data/spec/support/random_test_order.rb +3 -0
- metadata +261 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
describe IGMarkets::DealingPlatform do
|
2
|
+
let(:session) { IGMarkets::Session.new }
|
3
|
+
let(:platform) do
|
4
|
+
IGMarkets::DealingPlatform.new.tap do |platform|
|
5
|
+
platform.instance_variable_set :@session, session
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'has a valid session' do
|
10
|
+
expect(IGMarkets::DealingPlatform.new.session).to be_an_instance_of(IGMarkets::Session)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'can sign in' do
|
14
|
+
expect(session).to receive(:sign_in).and_return({})
|
15
|
+
expect(platform.sign_in('username', 'password', 'api_key', :production)).to eq({})
|
16
|
+
expect(session.username).to eq('username')
|
17
|
+
expect(session.password).to eq('password')
|
18
|
+
expect(session.api_key).to eq('api_key')
|
19
|
+
expect(session.platform).to eq(:production)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'can sign out' do
|
23
|
+
expect(session).to receive(:sign_out).and_return(nil)
|
24
|
+
expect(platform.sign_out).to eq(nil)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'can retrieve a deal confirmation' do
|
28
|
+
deal_confirmation = build :deal_confirmation
|
29
|
+
|
30
|
+
expect(session).to receive(:get).with('confirms/deal_id', IGMarkets::API_V1).and_return(deal_confirmation)
|
31
|
+
expect(platform.deal_confirmation('deal_id')).to eq(deal_confirmation)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'can retrieve the current applications' do
|
35
|
+
applications = [build(:application)]
|
36
|
+
|
37
|
+
expect(session).to receive(:get).with('operations/application', IGMarkets::API_V1).and_return(applications)
|
38
|
+
expect(platform.applications).to eq(applications)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
describe IGMarkets::Model do
|
2
|
+
class TestModel < IGMarkets::Model
|
3
|
+
attribute :id
|
4
|
+
attribute :bool, IGMarkets::Boolean
|
5
|
+
attribute :string, String, regex: /\A[A-Z]{3}\Z/, nil_if: '-'
|
6
|
+
attribute :date, DateTime, format: '%Y-%m-%d'
|
7
|
+
attribute :float, Float
|
8
|
+
attribute :symbol, Symbol, allowed_values: [:a, :b]
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:model) { TestModel.new }
|
12
|
+
|
13
|
+
it 'initializes with specified attribute values' do
|
14
|
+
expect(TestModel.new(id: 'test', bool: true).attributes).to eq(
|
15
|
+
id: 'test', bool: true, string: nil, date: nil, float: nil, symbol: nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'fails when initialized with an unknown attribute' do
|
19
|
+
expect { TestModel.new id: 'test', unknown: '' }.to raise_error(ArgumentError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'has the correct getter and setter methods' do
|
23
|
+
[:id, :id=, :bool, :bool=, :string, :string=, :date, :date=, :float, :float=, :symbol, :symbol=].each do |id|
|
24
|
+
expect(model.respond_to?(id)).to eq(true)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'has the correct attributes hash' do
|
29
|
+
expect(model.attributes).to eq(id: nil, bool: nil, string: nil, date: nil, float: nil, symbol: nil)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'inspects attributes' do
|
33
|
+
expect(model.inspect).to eq('#<TestModel id: nil, bool: nil, string: nil, date: nil, float: nil, symbol: nil>')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'inspects attributes in nested models' do
|
37
|
+
class TestModel2 < IGMarkets::Model
|
38
|
+
attribute :test, TestModel
|
39
|
+
end
|
40
|
+
|
41
|
+
model = TestModel2.new test: TestModel.new
|
42
|
+
|
43
|
+
expect(model.inspect).to eq(
|
44
|
+
'#<TestModel2 test: #<TestModel id: nil, bool: nil, string: nil, date: nil, float: nil, symbol: nil>>')
|
45
|
+
end
|
46
|
+
|
47
|
+
it '#from accepts nil' do
|
48
|
+
expect(TestModel.from(nil)).to eq(nil)
|
49
|
+
end
|
50
|
+
|
51
|
+
it '#from accepts an attributes hash' do
|
52
|
+
expect(TestModel.from(id: 'test').attributes).to eq(
|
53
|
+
id: 'test', bool: nil, string: nil, date: nil, float: nil, symbol: nil)
|
54
|
+
end
|
55
|
+
|
56
|
+
it '#from accepts an instance and creates a copy' do
|
57
|
+
instance = TestModel.new(id: 'test')
|
58
|
+
|
59
|
+
expect(TestModel.from(instance)).to eq(instance)
|
60
|
+
expect(TestModel.from(instance)).not_to eql(instance)
|
61
|
+
end
|
62
|
+
|
63
|
+
it '#from accepts an Array of attributes hashes' do
|
64
|
+
expect(TestModel.from([{ id: 'a' }, { id: 'b' }])).to eq([TestModel.new(id: 'a'), TestModel.new(id: 'b')])
|
65
|
+
end
|
66
|
+
|
67
|
+
it '#from raises on invalid inputs' do
|
68
|
+
['', DateTime.new, IGMarkets::Model.new].each do |invalid_input|
|
69
|
+
expect { TestModel.from(invalid_input) }.to raise_error(ArgumentError)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'raises ArgumentError for an invalid boolean' do
|
74
|
+
expect { model.bool = '' }.to raise_error(ArgumentError)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'raises ArgumentError when string value does not match the regex' do
|
78
|
+
expect { model.string = 'abc' }.to raise_error(ArgumentError)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'raises ArgumentError for an invalid date' do
|
82
|
+
expect { model.date = '2015-29-01' }.to raise_error(ArgumentError)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'raises ArgumentError for an invalid float' do
|
86
|
+
expect { model.float = 'a' }.to raise_error(ArgumentError)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'raises ArgumentError for an invalid symbol' do
|
90
|
+
expect { model.symbol = :invalid }.to raise_error(ArgumentError)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'returns the correct set of allowed values for an attribute' do
|
94
|
+
expect(TestModel.allowed_values(:symbol)).to eq([:a, :b])
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'sets attribute to nil when value matches a nil_if' do
|
98
|
+
model.string = '-'
|
99
|
+
expect(model.string).to eq(nil)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'correctly parses a date in the expected format' do
|
103
|
+
model.date = '2015-01-10'
|
104
|
+
expect(model.date).to eq(DateTime.new(2015, 1, 10))
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'with all attributes set' do
|
108
|
+
before do
|
109
|
+
model.id = 'id'
|
110
|
+
model.bool = true
|
111
|
+
model.string = 'ABC'
|
112
|
+
model.date = '2015-01-10'
|
113
|
+
model.float = '1.0'
|
114
|
+
model.symbol = 'a'
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'has the correct attributes hash' do
|
118
|
+
expect(model.attributes).to eq(
|
119
|
+
id: 'id', bool: true, string: 'ABC', date: DateTime.new(2015, 1, 10), float: 1.0, symbol: :a)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'inspects attributes' do
|
123
|
+
expect(model.inspect).to eq(
|
124
|
+
'#<TestModel id: "id", bool: true, string: "ABC", date: 2015-01-10T00:00:00+00:00, float: 1.0, symbol: :a>')
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
describe IGMarkets::PasswordEncryptor do
|
2
|
+
let(:encryptor) { IGMarkets::PasswordEncryptor.new }
|
3
|
+
let(:rsa_key_pair) { OpenSSL::PKey::RSA.new 2048 }
|
4
|
+
|
5
|
+
it 'can set its public key from an encoded public key' do
|
6
|
+
expect { encryptor.encoded_public_key = Base64.strict_encode64 rsa_key_pair.to_pem }.not_to raise_error
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'can encrypt a password' do
|
10
|
+
password = 'test'
|
11
|
+
|
12
|
+
encryptor.time_stamp = '1000'
|
13
|
+
encryptor.public_key = rsa_key_pair
|
14
|
+
|
15
|
+
encoded_encrypted_password = encryptor.encrypt password
|
16
|
+
|
17
|
+
decoded_encrypted_password = Base64.strict_decode64 encoded_encrypted_password
|
18
|
+
encoded_decrypted_password = rsa_key_pair.private_decrypt decoded_encrypted_password
|
19
|
+
decoded_decrypted_password = Base64.strict_decode64 encoded_decrypted_password
|
20
|
+
|
21
|
+
expect(decoded_decrypted_password).to eq("#{password}|#{encryptor.time_stamp}")
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe IGMarkets::PayloadFormatter do
|
2
|
+
class PayloadModel < IGMarkets::Model
|
3
|
+
attribute :the_string
|
4
|
+
attribute :the_symbol, Symbol, allowed_values: [:two_three]
|
5
|
+
attribute :the_date, DateTime, format: '%Y/%m/%d'
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'formats payloads correctly' do
|
9
|
+
model = PayloadModel.new the_string: 'string', the_symbol: :two_three, the_date: '2010/10/20'
|
10
|
+
|
11
|
+
expect(IGMarkets::PayloadFormatter.format(model)).to eq(
|
12
|
+
theString: 'string', theSymbol: 'TWO_THREE', theDate: '2010/10/20')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'camel cases snake case strings' do
|
16
|
+
expect(IGMarkets::PayloadFormatter.snake_case_to_camel_case('one')).to eq(:one)
|
17
|
+
expect(IGMarkets::PayloadFormatter.snake_case_to_camel_case('one_two_three')).to eq(:oneTwoThree)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
describe IGMarkets::Position do
|
2
|
+
let(:profitable_position) do
|
3
|
+
market = build :market_overview, bid: 4.0, lot_size: 3, scaling_factor: 5
|
4
|
+
build :position, currency: 'USD', level: 1.0, direction: :buy, size: 2, market: market
|
5
|
+
end
|
6
|
+
let(:unprofitable_position) do
|
7
|
+
market = build :market_overview, offer: 4.0, lot_size: 3, scaling_factor: 5
|
8
|
+
build :position, currency: 'USD', level: 1.0, direction: :sell, size: 2, market: market
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'knows if it has a trailing stop' do
|
12
|
+
expect(build(:position).trailing_stop?).to be false
|
13
|
+
expect(build(:position, trailing_step: 1, trailing_stop_distance: 10).trailing_stop?).to be true
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'calculates correct price deltas' do
|
17
|
+
expect(profitable_position.price_delta).to eq(3.0)
|
18
|
+
expect(unprofitable_position.price_delta).to eq(-3.0)
|
19
|
+
expect(profitable_position.profitable?).to be true
|
20
|
+
expect(unprofitable_position.profitable?).to be false
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'calculates correct profit/loss amounts' do
|
24
|
+
expect(profitable_position.profit_loss).to eq(90)
|
25
|
+
expect(unprofitable_position.profit_loss).to eq(-90)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'correctly formats profit/loss amounts' do
|
29
|
+
expect(profitable_position.formatted_profit_loss).to eq('USD 90.00')
|
30
|
+
expect(unprofitable_position.formatted_profit_loss).to eq('USD -90.00')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'correctly formats position size' do
|
34
|
+
expect(profitable_position.formatted_size).to eq('+2')
|
35
|
+
expect(unprofitable_position.formatted_size).to eq('-2')
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
describe IGMarkets::ResponseParser do
|
2
|
+
it 'snake cases camel case keys' do
|
3
|
+
parsed = IGMarkets::ResponseParser.parse(update: 1, updateTime: 1, updateTimeUTC: 1, updateUTCTime: 1)
|
4
|
+
|
5
|
+
expect(parsed).to eq(update: 1, update_time: 1, update_time_utc: 1, update_utc_time: 1)
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'parses arrays' do
|
9
|
+
parsed = IGMarkets::ResponseParser.parse([{ aB: 1 }, { cD: 2 }])
|
10
|
+
|
11
|
+
expect(parsed).to eq([{ a_b: 1 }, { c_d: 2 }])
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
describe IGMarkets::Session do
|
2
|
+
let(:response) { instance_double 'RestClient::Response' }
|
3
|
+
let(:rest_client) { RestClient::Request }
|
4
|
+
|
5
|
+
context 'a non-signed in session' do
|
6
|
+
let(:session) do
|
7
|
+
IGMarkets::Session.new.tap do |session|
|
8
|
+
session.username = 'username'
|
9
|
+
session.password = 'password'
|
10
|
+
session.api_key = 'api_key'
|
11
|
+
session.platform = :production
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'is not alive' do
|
16
|
+
expect(session.alive?).to eq(false)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'can sign in' do
|
20
|
+
expect(response).to receive(:code).exactly(4).times.and_return(200)
|
21
|
+
expect(response).to receive(:headers).and_return(cst: '1', x_security_token: '2')
|
22
|
+
expect(response).to receive(:body).twice.and_return(
|
23
|
+
{ encryptionKey: Base64.strict_encode64(OpenSSL::PKey::RSA.new(256).to_pem), timeStamp: '1000' }.to_json,
|
24
|
+
{}.to_json
|
25
|
+
)
|
26
|
+
expect(rest_client).to receive(:execute).twice.and_return(response)
|
27
|
+
|
28
|
+
expect(session.sign_in).to eq(nil)
|
29
|
+
|
30
|
+
expect(session.cst).to eq('1')
|
31
|
+
expect(session.x_security_token).to match('2')
|
32
|
+
expect(session.alive?).to eq(true)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'fails to sign in when required attributes are missing' do
|
36
|
+
%i(username password api_key platform).each do |attribute|
|
37
|
+
session.send "#{attribute}=", nil
|
38
|
+
expect { session.sign_in }.to raise_error(ArgumentError)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'a signed in session' do
|
44
|
+
let(:session) do
|
45
|
+
IGMarkets::Session.new.tap do |s|
|
46
|
+
s.instance_variable_set :@cst, 'cst'
|
47
|
+
s.instance_variable_set :@x_security_token, 'x_security_token'
|
48
|
+
s.instance_variable_set :@api_key, 'api_key'
|
49
|
+
s.instance_variable_set :@platform, :production
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'is alive' do
|
54
|
+
expect(session.alive?).to eq(true)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'passes correct details for a post request' do
|
58
|
+
expect(response).to receive_messages(code: 200, body: { ids: [1, 2] }.to_json)
|
59
|
+
expect(rest_client).to receive(:execute).with(params(:post, 'url', id: 1)).and_return(response)
|
60
|
+
expect(session.post('url', { id: 1 }, IGMarkets::API_V1)).to eq(ids: [1, 2])
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'can sign out' do
|
64
|
+
expect(response).to receive_messages(code: 200, body: {}.to_json)
|
65
|
+
expect(rest_client).to receive(:execute).with(params(:delete, 'session')).and_return(response)
|
66
|
+
expect(session.sign_out).to eq(nil)
|
67
|
+
expect(session.alive?).to eq(false)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'fails when the HTTP response is not 200' do
|
71
|
+
expect(response).to receive_messages(code: 404, body: { errorCode: '1' }.to_json)
|
72
|
+
expect(rest_client).to receive(:execute).with(params(:get, 'url')).and_raise(RestClient::Exception, response)
|
73
|
+
expect { session.get('url', IGMarkets::API_V1) }.to raise_error do |error|
|
74
|
+
expect(error).to be_a(IGMarkets::RequestFailedError)
|
75
|
+
expect(error.error).to eq('1')
|
76
|
+
expect(error.http_code).to eq(404)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'handles when the HTTP response is not JSON' do
|
81
|
+
expect(response).to receive_messages(code: 404, body: 'not_valid_json')
|
82
|
+
expect(rest_client).to receive(:execute).with(params(:get, 'url')).and_raise(RestClient::Exception, response)
|
83
|
+
expect { session.get('url', IGMarkets::API_V1) }.to raise_error(IGMarkets::RequestFailedError)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'converts a SocketError into a RequestFailedError' do
|
87
|
+
expect(rest_client).to receive(:execute).with(params(:get, 'url')).and_raise(SocketError)
|
88
|
+
expect { session.get('url', IGMarkets::API_V1) }.to raise_error(IGMarkets::RequestFailedError)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'converts a RestClient::Exception that has no response into a RequestFailedError' do
|
92
|
+
expect(rest_client).to receive(:execute).with(params(:get, 'url')).and_raise(RestClient::Exception)
|
93
|
+
expect { session.get('url', IGMarkets::API_V1) }.to raise_error(IGMarkets::RequestFailedError)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'can process a PUT request' do
|
97
|
+
expect(response).to receive_messages(code: 200, body: '')
|
98
|
+
expect(rest_client).to receive(:execute).with(params(:put, 'url', id: 1)).and_return(response)
|
99
|
+
expect(session.put('url', { id: 1 }, IGMarkets::API_V1)).to eq({})
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'can process a DELETE request with a payload' do
|
103
|
+
execute_params = params :post, 'url', id: 1
|
104
|
+
execute_params[:headers]['_method'] = :delete
|
105
|
+
|
106
|
+
expect(response).to receive_messages(code: 204, body: '')
|
107
|
+
expect(rest_client).to receive(:execute).with(execute_params).and_return(response)
|
108
|
+
expect(session.delete('url', { id: 1 }, IGMarkets::API_V1)).to eq({})
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'inspects correctly' do
|
112
|
+
expect(session.inspect).to eq('#<IGMarkets::Session cst, x_security_token>')
|
113
|
+
end
|
114
|
+
|
115
|
+
def headers
|
116
|
+
hash = {}
|
117
|
+
hash[:accept] = hash[:content_type] = 'application/json; charset=UTF-8'
|
118
|
+
hash[:version] = 1
|
119
|
+
hash[:cst] = 'cst'
|
120
|
+
hash[:x_security_token] = 'x_security_token'
|
121
|
+
hash[:'X-IG-API-KEY'] = 'api_key'
|
122
|
+
hash
|
123
|
+
end
|
124
|
+
|
125
|
+
def params(method, url, payload = nil)
|
126
|
+
hash = {}
|
127
|
+
hash[:method] = method
|
128
|
+
hash[:url] = "https://api.ig.com/gateway/deal/#{url}"
|
129
|
+
hash[:headers] = headers
|
130
|
+
hash[:payload] = payload && payload.to_json
|
131
|
+
hash
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
require 'codeclimate-test-reporter'
|
5
|
+
if ENV.key? 'CODECLIMATE_REPO_TOKEN'
|
6
|
+
CodeClimate::TestReporter.start
|
7
|
+
else
|
8
|
+
SimpleCov.start
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'ig_markets'
|
12
|
+
|
13
|
+
require 'support/factory_girl'
|
14
|
+
require 'support/random_test_order'
|
metadata
ADDED
@@ -0,0 +1,261 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ig_markets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Richard Viney
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: codeclimate-test-reporter
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: factory_girl
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: github-markup
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: redcarpet
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.4'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.4'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec-mocks
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.4'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.4'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.39'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.39'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: yard
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.8'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.8'
|
139
|
+
description: Ruby client for the IG Markets dealing platform.
|
140
|
+
email: richard.viney@gmail.com
|
141
|
+
executables: []
|
142
|
+
extensions: []
|
143
|
+
extra_rdoc_files: []
|
144
|
+
files:
|
145
|
+
- ".codeclimate.yml"
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rspec"
|
148
|
+
- ".rubocop.yml"
|
149
|
+
- ".travis.yml"
|
150
|
+
- ".yardopts"
|
151
|
+
- Gemfile
|
152
|
+
- LICENSE.md
|
153
|
+
- README.md
|
154
|
+
- ig_markets.gemspec
|
155
|
+
- lib/ig_markets.rb
|
156
|
+
- lib/ig_markets/account.rb
|
157
|
+
- lib/ig_markets/account_activity.rb
|
158
|
+
- lib/ig_markets/account_transaction.rb
|
159
|
+
- lib/ig_markets/api_versions.rb
|
160
|
+
- lib/ig_markets/application.rb
|
161
|
+
- lib/ig_markets/boolean.rb
|
162
|
+
- lib/ig_markets/client_sentiment.rb
|
163
|
+
- lib/ig_markets/deal_confirmation.rb
|
164
|
+
- lib/ig_markets/dealing_platform.rb
|
165
|
+
- lib/ig_markets/dealing_platform/account_methods.rb
|
166
|
+
- lib/ig_markets/dealing_platform/client_sentiment_methods.rb
|
167
|
+
- lib/ig_markets/dealing_platform/market_methods.rb
|
168
|
+
- lib/ig_markets/dealing_platform/position_methods.rb
|
169
|
+
- lib/ig_markets/dealing_platform/sprint_market_position_methods.rb
|
170
|
+
- lib/ig_markets/dealing_platform/watchlist_methods.rb
|
171
|
+
- lib/ig_markets/dealing_platform/working_order_methods.rb
|
172
|
+
- lib/ig_markets/historical_price_result.rb
|
173
|
+
- lib/ig_markets/instrument.rb
|
174
|
+
- lib/ig_markets/market.rb
|
175
|
+
- lib/ig_markets/market_hierarchy_result.rb
|
176
|
+
- lib/ig_markets/market_overview.rb
|
177
|
+
- lib/ig_markets/model.rb
|
178
|
+
- lib/ig_markets/password_encryptor.rb
|
179
|
+
- lib/ig_markets/payload_formatter.rb
|
180
|
+
- lib/ig_markets/position.rb
|
181
|
+
- lib/ig_markets/regex.rb
|
182
|
+
- lib/ig_markets/request_failed_error.rb
|
183
|
+
- lib/ig_markets/response_parser.rb
|
184
|
+
- lib/ig_markets/session.rb
|
185
|
+
- lib/ig_markets/sprint_market_position.rb
|
186
|
+
- lib/ig_markets/version.rb
|
187
|
+
- lib/ig_markets/watchlist.rb
|
188
|
+
- lib/ig_markets/working_order.rb
|
189
|
+
- spec/factories/ig_markets/account.rb
|
190
|
+
- spec/factories/ig_markets/account_activity.rb
|
191
|
+
- spec/factories/ig_markets/account_balance.rb
|
192
|
+
- spec/factories/ig_markets/account_transaction.rb
|
193
|
+
- spec/factories/ig_markets/application.rb
|
194
|
+
- spec/factories/ig_markets/client_sentiment.rb
|
195
|
+
- spec/factories/ig_markets/deal_confirmation.rb
|
196
|
+
- spec/factories/ig_markets/historical_price_result.rb
|
197
|
+
- spec/factories/ig_markets/historical_price_result_data_allowance.rb
|
198
|
+
- spec/factories/ig_markets/historical_price_result_price.rb
|
199
|
+
- spec/factories/ig_markets/historical_price_result_snapshot.rb
|
200
|
+
- spec/factories/ig_markets/instrument.rb
|
201
|
+
- spec/factories/ig_markets/instrument_currency.rb
|
202
|
+
- spec/factories/ig_markets/instrument_expiry_details.rb
|
203
|
+
- spec/factories/ig_markets/instrument_margin_deposit_band.rb
|
204
|
+
- spec/factories/ig_markets/instrument_opening_hours.rb
|
205
|
+
- spec/factories/ig_markets/instrument_rollover_details.rb
|
206
|
+
- spec/factories/ig_markets/instrument_slippage_factor.rb
|
207
|
+
- spec/factories/ig_markets/market.rb
|
208
|
+
- spec/factories/ig_markets/market_dealing_rules.rb
|
209
|
+
- spec/factories/ig_markets/market_dealing_rules_rule_details.rb
|
210
|
+
- spec/factories/ig_markets/market_hierarchy_result.rb
|
211
|
+
- spec/factories/ig_markets/market_hierarchy_result_hierarchy_node.rb
|
212
|
+
- spec/factories/ig_markets/market_overview.rb
|
213
|
+
- spec/factories/ig_markets/market_snapshot.rb
|
214
|
+
- spec/factories/ig_markets/position.rb
|
215
|
+
- spec/factories/ig_markets/sprint_market_position.rb
|
216
|
+
- spec/factories/ig_markets/watchlist.rb
|
217
|
+
- spec/factories/ig_markets/working_order.rb
|
218
|
+
- spec/ig_markets/account_transaction_spec.rb
|
219
|
+
- spec/ig_markets/dealing_platform/account_methods_spec.rb
|
220
|
+
- spec/ig_markets/dealing_platform/client_sentiment_methods_spec.rb
|
221
|
+
- spec/ig_markets/dealing_platform/market_methods_spec.rb
|
222
|
+
- spec/ig_markets/dealing_platform/position_methods_spec.rb
|
223
|
+
- spec/ig_markets/dealing_platform/sprint_market_position_methods_spec.rb
|
224
|
+
- spec/ig_markets/dealing_platform/watchlist_methods_spec.rb
|
225
|
+
- spec/ig_markets/dealing_platform/working_order_methods_spec.rb
|
226
|
+
- spec/ig_markets/dealing_platform_spec.rb
|
227
|
+
- spec/ig_markets/model_spec.rb
|
228
|
+
- spec/ig_markets/password_encryptor_spec.rb
|
229
|
+
- spec/ig_markets/payload_formatter_spec.rb
|
230
|
+
- spec/ig_markets/position_spec.rb
|
231
|
+
- spec/ig_markets/response_parser_spec.rb
|
232
|
+
- spec/ig_markets/session_spec.rb
|
233
|
+
- spec/spec_helper.rb
|
234
|
+
- spec/support/factory_girl.rb
|
235
|
+
- spec/support/random_test_order.rb
|
236
|
+
homepage: https://github.com/rviney/ig_markets
|
237
|
+
licenses:
|
238
|
+
- MIT
|
239
|
+
metadata: {}
|
240
|
+
post_install_message:
|
241
|
+
rdoc_options: []
|
242
|
+
require_paths:
|
243
|
+
- lib
|
244
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
245
|
+
requirements:
|
246
|
+
- - ">="
|
247
|
+
- !ruby/object:Gem::Version
|
248
|
+
version: '2.0'
|
249
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
250
|
+
requirements:
|
251
|
+
- - ">="
|
252
|
+
- !ruby/object:Gem::Version
|
253
|
+
version: '0'
|
254
|
+
requirements: []
|
255
|
+
rubyforge_project:
|
256
|
+
rubygems_version: 2.5.1
|
257
|
+
signing_key:
|
258
|
+
specification_version: 4
|
259
|
+
summary: Ruby client for the IG Markets dealing platform.
|
260
|
+
test_files: []
|
261
|
+
has_rdoc:
|