ig_markets 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/README.md +32 -16
  4. data/bin/ig_markets +29 -0
  5. data/lib/ig_markets.rb +15 -0
  6. data/lib/ig_markets/account_activity.rb +1 -1
  7. data/lib/ig_markets/account_transaction.rb +1 -1
  8. data/lib/ig_markets/application.rb +2 -2
  9. data/lib/ig_markets/cli/account_command.rb +40 -0
  10. data/lib/ig_markets/cli/activities_command.rb +33 -0
  11. data/lib/ig_markets/cli/confirmation_command.rb +32 -0
  12. data/lib/ig_markets/cli/main.rb +39 -0
  13. data/lib/ig_markets/cli/orders_command.rb +28 -0
  14. data/lib/ig_markets/cli/positions_command.rb +20 -0
  15. data/lib/ig_markets/cli/search_command.rb +30 -0
  16. data/lib/ig_markets/cli/sentiment_command.rb +35 -0
  17. data/lib/ig_markets/cli/sprints_command.rb +28 -0
  18. data/lib/ig_markets/cli/transactions_command.rb +56 -0
  19. data/lib/ig_markets/cli/watchlists_command.rb +34 -0
  20. data/lib/ig_markets/deal_confirmation.rb +4 -4
  21. data/lib/ig_markets/dealing_platform/position_methods.rb +3 -3
  22. data/lib/ig_markets/dealing_platform/sprint_market_position_methods.rb +1 -1
  23. data/lib/ig_markets/dealing_platform/watchlist_methods.rb +1 -3
  24. data/lib/ig_markets/dealing_platform/working_order_methods.rb +10 -10
  25. data/lib/ig_markets/format.rb +36 -0
  26. data/lib/ig_markets/historical_price_result.rb +1 -1
  27. data/lib/ig_markets/instrument.rb +2 -2
  28. data/lib/ig_markets/market.rb +10 -10
  29. data/lib/ig_markets/model.rb +23 -60
  30. data/lib/ig_markets/model/typecasters.rb +78 -0
  31. data/lib/ig_markets/payload_formatter.rb +19 -6
  32. data/lib/ig_markets/position.rb +7 -21
  33. data/lib/ig_markets/request_failed_error.rb +1 -1
  34. data/lib/ig_markets/sprint_market_position.rb +18 -3
  35. data/lib/ig_markets/version.rb +1 -1
  36. data/lib/ig_markets/working_order.rb +11 -11
  37. metadata +39 -64
  38. data/.codeclimate.yml +0 -15
  39. data/.gitignore +0 -9
  40. data/.rspec +0 -2
  41. data/.rubocop.yml +0 -2
  42. data/.travis.yml +0 -10
  43. data/.yardopts +0 -4
  44. data/Gemfile +0 -2
  45. data/ig_markets.gemspec +0 -28
  46. data/spec/factories/ig_markets/account.rb +0 -14
  47. data/spec/factories/ig_markets/account_activity.rb +0 -21
  48. data/spec/factories/ig_markets/account_balance.rb +0 -8
  49. data/spec/factories/ig_markets/account_transaction.rb +0 -15
  50. data/spec/factories/ig_markets/application.rb +0 -21
  51. data/spec/factories/ig_markets/client_sentiment.rb +0 -7
  52. data/spec/factories/ig_markets/deal_confirmation.rb +0 -20
  53. data/spec/factories/ig_markets/historical_price_result.rb +0 -7
  54. data/spec/factories/ig_markets/historical_price_result_data_allowance.rb +0 -7
  55. data/spec/factories/ig_markets/historical_price_result_price.rb +0 -7
  56. data/spec/factories/ig_markets/historical_price_result_snapshot.rb +0 -10
  57. data/spec/factories/ig_markets/instrument.rb +0 -32
  58. data/spec/factories/ig_markets/instrument_currency.rb +0 -9
  59. data/spec/factories/ig_markets/instrument_expiry_details.rb +0 -6
  60. data/spec/factories/ig_markets/instrument_margin_deposit_band.rb +0 -8
  61. data/spec/factories/ig_markets/instrument_opening_hours.rb +0 -6
  62. data/spec/factories/ig_markets/instrument_rollover_details.rb +0 -6
  63. data/spec/factories/ig_markets/instrument_slippage_factor.rb +0 -6
  64. data/spec/factories/ig_markets/market.rb +0 -7
  65. data/spec/factories/ig_markets/market_dealing_rules.rb +0 -11
  66. data/spec/factories/ig_markets/market_dealing_rules_rule_details.rb +0 -6
  67. data/spec/factories/ig_markets/market_hierarchy_result.rb +0 -6
  68. data/spec/factories/ig_markets/market_hierarchy_result_hierarchy_node.rb +0 -6
  69. data/spec/factories/ig_markets/market_overview.rb +0 -22
  70. data/spec/factories/ig_markets/market_snapshot.rb +0 -17
  71. data/spec/factories/ig_markets/position.rb +0 -19
  72. data/spec/factories/ig_markets/sprint_market_position.rb +0 -16
  73. data/spec/factories/ig_markets/watchlist.rb +0 -9
  74. data/spec/factories/ig_markets/working_order.rb +0 -21
  75. data/spec/ig_markets/account_transaction_spec.rb +0 -30
  76. data/spec/ig_markets/dealing_platform/account_methods_spec.rb +0 -58
  77. data/spec/ig_markets/dealing_platform/client_sentiment_methods_spec.rb +0 -29
  78. data/spec/ig_markets/dealing_platform/market_methods_spec.rb +0 -80
  79. data/spec/ig_markets/dealing_platform/position_methods_spec.rb +0 -137
  80. data/spec/ig_markets/dealing_platform/sprint_market_position_methods_spec.rb +0 -39
  81. data/spec/ig_markets/dealing_platform/watchlist_methods_spec.rb +0 -89
  82. data/spec/ig_markets/dealing_platform/working_order_methods_spec.rb +0 -120
  83. data/spec/ig_markets/dealing_platform_spec.rb +0 -40
  84. data/spec/ig_markets/model_spec.rb +0 -127
  85. data/spec/ig_markets/password_encryptor_spec.rb +0 -23
  86. data/spec/ig_markets/payload_formatter_spec.rb +0 -19
  87. data/spec/ig_markets/position_spec.rb +0 -37
  88. data/spec/ig_markets/response_parser_spec.rb +0 -13
  89. data/spec/ig_markets/session_spec.rb +0 -134
  90. data/spec/spec_helper.rb +0 -14
  91. data/spec/support/factory_girl.rb +0 -7
  92. data/spec/support/random_test_order.rb +0 -3
@@ -1,16 +0,0 @@
1
- FactoryGirl.define do
2
- factory :sprint_market_position, class: IGMarkets::SprintMarketPosition do
3
- created_date '2014/10/22 18:30:15:000'
4
- currency 'USD'
5
- deal_id 'deal_id'
6
- description 'description'
7
- direction 'BUY'
8
- epic 'UA.D.AAPL.CASH.IP'
9
- expiry_time '2014/10/22 19:30:14:000'
10
- instrument_name 'instrument'
11
- market_status 'TRADEABLE'
12
- payout_amount 100.0
13
- size 1
14
- strike_level 110.0
15
- end
16
- end
@@ -1,9 +0,0 @@
1
- FactoryGirl.define do
2
- factory :watchlist, class: IGMarkets::Watchlist do
3
- id '2547731'
4
- name 'Markets'
5
- editable false
6
- deleteable false
7
- default_system_watchlist false
8
- end
9
- end
@@ -1,21 +0,0 @@
1
- FactoryGirl.define do
2
- factory :working_order, class: IGMarkets::WorkingOrder do
3
- created_date '2014/10/20 13:30:03:000'
4
- currency_code 'USD'
5
- deal_id 'deal_id'
6
- direction 'BUY'
7
- dma false
8
- epic 'UA.D.AAPL.CASH.IP'
9
- good_till_date '2015/10/20 10:45:29:000'
10
- good_till_date_iso '2015-10-30T12:59'
11
- guaranteed_stop false
12
- limit_distance 1.0
13
- order_level 100.0
14
- order_size 1
15
- order_type 'LIMIT'
16
- stop_distance 1.0
17
- time_in_force 'GOOD_TILL_DATE'
18
-
19
- market { build :market_overview }
20
- end
21
- end
@@ -1,30 +0,0 @@
1
- describe IGMarkets::DealingPlatform do
2
- it 'correctly identifies interest payments' do
3
- {
4
- { transaction_type: :with, instrument_name: 'interest' } => true,
5
- { transaction_type: :depo, instrument_name: ',interest' } => true,
6
- { transaction_type: :with, instrument_name: 'interest,' } => true,
7
- { transaction_type: :depo, instrument_name: ',interest,' } => true,
8
- { transaction_type: :with, instrument_name: 'pinterest' } => false,
9
- { transaction_type: :depo, instrument_name: 'interests' } => false
10
- }.each do |attributes, result|
11
- expect(build(:account_transaction, attributes).interest?).to eq(result)
12
- end
13
- end
14
-
15
- it 'reports correct profit/loss amounts' do
16
- expect(build(:account_transaction, currency: 'USD', profit_and_loss: 'USD10.10').profit_and_loss_amount).to eq(10.1)
17
- expect(build(:account_transaction, currency: 'USD', profit_and_loss: 'USD-5.50').profit_and_loss_amount).to eq(-5.5)
18
-
19
- expect { build(:account_transaction, currency: 'USD', profit_and_loss: 'EUR-5.0').profit_and_loss_amount }
20
- .to raise_error(StandardError)
21
- end
22
-
23
- it 'formats transaction types' do
24
- expect(build(:account_transaction, transaction_type: :deal).formatted_transaction_type).to eq('Deal')
25
- expect(build(:account_transaction, transaction_type: :depo).formatted_transaction_type).to eq('Deposit')
26
- expect(build(:account_transaction, transaction_type: :dividend).formatted_transaction_type).to eq('Dividend')
27
- expect(build(:account_transaction, transaction_type: :exchange).formatted_transaction_type).to eq('Exchange')
28
- expect(build(:account_transaction, transaction_type: :with).formatted_transaction_type).to eq('Withdrawal')
29
- end
30
- end
@@ -1,58 +0,0 @@
1
- describe IGMarkets::DealingPlatform::AccountMethods 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 'can retrieve accounts' do
10
- accounts = [build(:account)]
11
-
12
- expect(session).to receive(:get).with('accounts', IGMarkets::API_V1).and_return(accounts: accounts)
13
-
14
- expect(platform.account.all).to eq(accounts)
15
- end
16
-
17
- it 'can retrieve activities in a date range' do
18
- activities = [build(:account_activity)]
19
-
20
- expect(session).to receive(:get)
21
- .with('history/activity/20-05-2014/27-10-2014', IGMarkets::API_V1)
22
- .and_return(activities: activities)
23
-
24
- expect(platform.account.activities_in_date_range(Date.new(2014, 5, 20), Date.new(2014, 10, 27))).to eq(activities)
25
- end
26
-
27
- it 'can retrieve activities in recent period' do
28
- activities = [build(:account_activity)]
29
-
30
- expect(session).to receive(:get)
31
- .with('history/activity/1000000', IGMarkets::API_V1)
32
- .and_return(activities: activities)
33
-
34
- expect(platform.account.recent_activities(1000)).to eq(activities)
35
- end
36
-
37
- it 'can retrieve transactions in a date range' do
38
- transactions = [build(:account_transaction)]
39
-
40
- expect(session).to receive(:get)
41
- .with('history/transactions/ALL/20-05-2014/27-10-2014', IGMarkets::API_V1)
42
- .and_return(transactions: transactions)
43
-
44
- result = platform.account.transactions_in_date_range Date.new(2014, 5, 20), Date.new(2014, 10, 27), :all
45
-
46
- expect(result).to eq(transactions)
47
- end
48
-
49
- it 'can retrieve transactions in recent period' do
50
- transactions = [build(:account_transaction)]
51
-
52
- expect(session).to receive(:get)
53
- .with('history/transactions/DEPOSIT/1000000', IGMarkets::API_V1)
54
- .and_return(transactions: transactions)
55
-
56
- expect(platform.account.recent_transactions(1000, :deposit)).to eq(transactions)
57
- end
58
- end
@@ -1,29 +0,0 @@
1
- describe IGMarkets::DealingPlatform::ClientSentimentMethods 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 'can retrieve the client sentiment for a market' do
10
- client_sentiment = build :client_sentiment
11
-
12
- expect(session).to receive(:get).with('clientsentiment/1', IGMarkets::API_V1).and_return(client_sentiment)
13
-
14
- expect(platform.client_sentiment['1']).to eq(client_sentiment)
15
- end
16
-
17
- it 'can retrieve the related client sentiments for a market' do
18
- client_sentiment = build :client_sentiment, market_id: '1'
19
- related_client_sentiments = [build(:client_sentiment), build(:client_sentiment)]
20
-
21
- expect(session).to receive(:get).with('clientsentiment/1', IGMarkets::API_V1).and_return(client_sentiment)
22
-
23
- expect(session).to receive(:get)
24
- .with('clientsentiment/related/1', IGMarkets::API_V1)
25
- .and_return(client_sentiments: related_client_sentiments)
26
-
27
- expect(platform.client_sentiment['1'].related_sentiments).to eq(related_client_sentiments)
28
- end
29
- end
@@ -1,80 +0,0 @@
1
- describe IGMarkets::DealingPlatform::MarketMethods 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 'can retrieve the market hierarchy root' do
10
- result = build :market_hierarchy_result
11
-
12
- expect(session).to receive(:get).with('marketnavigation', IGMarkets::API_V1).and_return(result)
13
- expect(platform.markets.hierarchy).to eq(result)
14
- end
15
-
16
- it 'can retrieve a market hierarchy node' do
17
- result = build :market_hierarchy_result
18
-
19
- expect(session).to receive(:get).with('marketnavigation/1', IGMarkets::API_V1).and_return(result)
20
- expect(platform.markets.hierarchy(1)).to eq(result)
21
- end
22
-
23
- it 'can retrieve a market from an EPIC' do
24
- get_result = {
25
- market_details: [{
26
- dealing_rules: build(:market_dealing_rules),
27
- instrument: build(:instrument),
28
- snapshot: build(:market_snapshot)
29
- }]
30
- }
31
-
32
- expect(session).to receive(:get).with('markets?epics=ABCDEF', IGMarkets::API_V2).and_return(get_result)
33
- expect(platform.markets['ABCDEF']).to eq(IGMarkets::Market.from(get_result[:market_details])[0])
34
- end
35
-
36
- it 'can search for markets' do
37
- markets = [build(:market_overview)]
38
-
39
- expect(session).to receive(:get).with('markets?searchTerm=USD', IGMarkets::API_V1).and_return(markets: markets)
40
- expect(platform.markets.search('USD')).to eq(markets)
41
- end
42
-
43
- it 'can retrieve a specified number of historical prices for a market' do
44
- markets_get_result = {
45
- market_details: [{
46
- dealing_rules: build(:market_dealing_rules),
47
- instrument: build(:instrument),
48
- snapshot: build(:market_snapshot)
49
- }]
50
- }
51
-
52
- historical_price_result = build :historical_price_result
53
-
54
- expect(session).to receive(:get).with('markets?epics=ABCDEF', IGMarkets::API_V2).and_return(markets_get_result)
55
- expect(session).to receive(:get).with('prices/ABCDEF/DAY/5', IGMarkets::API_V2).and_return(historical_price_result)
56
- expect(platform.markets['ABCDEF'].recent_prices(:day, 5)).to eq(historical_price_result)
57
- end
58
-
59
- it 'can retrieve a date range of historical prices for a market' do
60
- from_date = DateTime.new 2014, 1, 2, 3, 4, 5
61
- to_date = DateTime.new 2014, 2, 3, 4, 5, 6
62
-
63
- markets_get_result = {
64
- market_details: [{
65
- dealing_rules: build(:market_dealing_rules),
66
- instrument: build(:instrument),
67
- snapshot: build(:market_snapshot)
68
- }]
69
- }
70
-
71
- historical_price_result = build :historical_price_result
72
-
73
- expect(session).to receive(:get).with('markets?epics=ABCDEF', IGMarkets::API_V2).and_return(markets_get_result)
74
- expect(session).to receive(:get)
75
- .with('prices/ABCDEF/DAY/2014-01-02T03:04:05/2014-02-03T04:05:06', IGMarkets::API_V2)
76
- .and_return(historical_price_result)
77
-
78
- expect(platform.markets['ABCDEF'].prices_in_date_range(:day, from_date, to_date)).to eq(historical_price_result)
79
- end
80
- end
@@ -1,137 +0,0 @@
1
- describe IGMarkets::DealingPlatform::PositionMethods 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 'can retrieve the current positions' do
10
- positions = [build(:position)]
11
-
12
- get_result = {
13
- positions: positions.map(&:attributes).map do |a|
14
- { market: a[:market], position: a }
15
- end
16
- }
17
-
18
- expect(session).to receive(:get).with('positions', IGMarkets::API_V2).and_return(get_result)
19
- expect(platform.positions.all).to eq(positions)
20
- end
21
-
22
- it 'can retrieve a single position' do
23
- position = build :position
24
-
25
- expect(session).to receive(:get)
26
- .with("positions/#{position.deal_id}", IGMarkets::API_V2)
27
- .and_return(position: position.attributes, market: position.market)
28
-
29
- expect(platform.positions[position.deal_id]).to eq(position)
30
- end
31
-
32
- it 'can create a position' do
33
- attributes = {
34
- currency_code: 'USD',
35
- direction: :buy,
36
- epic: 'CS.D.EURUSD.CFD.IP',
37
- size: 2.0
38
- }
39
-
40
- payload = {
41
- currencyCode: 'USD',
42
- direction: 'BUY',
43
- epic: 'CS.D.EURUSD.CFD.IP',
44
- expiry: '-',
45
- forceOpen: false,
46
- guaranteedStop: false,
47
- orderType: 'MARKET',
48
- size: 2.0,
49
- timeInForce: 'EXECUTE_AND_ELIMINATE'
50
- }
51
-
52
- result = { deal_reference: 'reference' }
53
-
54
- expect(session).to receive(:post).with('positions/otc', payload, IGMarkets::API_V2).and_return(result)
55
- expect(platform.positions.create(attributes)).to eq(result.fetch(:deal_reference))
56
- end
57
-
58
- it 'validates position creation attributes correctly' do
59
- attributes = {
60
- currency_code: 'USD',
61
- direction: :buy,
62
- epic: 'CS.D.EURUSD.CFD.IP',
63
- size: 2.0,
64
- time_in_force: :execute_and_eliminate
65
- }
66
-
67
- create_position = proc do |override_attributes = {}|
68
- platform.positions.create attributes.merge override_attributes
69
- end
70
-
71
- expect(session).to receive(:post).exactly(10).times.and_return(deal_reference: 'reference')
72
-
73
- expect { create_position.call }.to_not raise_error
74
- expect { create_position.call order_type: :quote }.to raise_error(ArgumentError)
75
- expect { create_position.call order_type: :quote, quote_id: 'a' }.to raise_error(ArgumentError)
76
- expect { create_position.call order_type: :quote, level: 1 }.to raise_error(ArgumentError)
77
- expect { create_position.call order_type: :quote, quote_id: 'a', level: 1 }.to_not raise_error
78
- expect { create_position.call order_type: :limit }.to raise_error(ArgumentError)
79
- expect { create_position.call order_type: :limit, level: 1 }.to_not raise_error
80
- expect { create_position.call trailing_stop: true, stop_distance: 1 }.to raise_error(ArgumentError)
81
- expect { create_position.call trailing_stop: true, stop_distance: 1, trailing_stop_increment: 1 }.not_to raise_error
82
- expect { create_position.call limit_distance: 1 }.not_to raise_error
83
- expect { create_position.call limit_level: 1 }.not_to raise_error
84
- expect { create_position.call limit_distance: 1, limit_level: 1 }.to raise_error(ArgumentError)
85
- expect { create_position.call stop_distance: 1 }.not_to raise_error
86
- expect { create_position.call stop_level: 1 }.not_to raise_error
87
- expect { create_position.call stop_distance: 1, stop_level: 1 }.to raise_error(ArgumentError)
88
- expect { create_position.call guaranteed_stop: true }.to raise_error(ArgumentError)
89
- expect { create_position.call guaranteed_stop: true, stop_distance: 1 }.not_to raise_error
90
- expect { create_position.call guaranteed_stop: true, stop_level: 1 }.not_to raise_error
91
- end
92
-
93
- it 'can update a position' do
94
- position = build :position, deal_id: '1'
95
-
96
- get_result = { position: position.attributes, market: position.market }
97
- payload = { limitLevel: 2.0, stopLevel: 1.0, trailingStop: false }
98
- put_result = { deal_reference: 'reference' }
99
-
100
- expect(session).to receive(:get).with('positions/1', IGMarkets::API_V2).and_return(get_result)
101
- expect(session).to receive(:put).with('positions/otc/1', payload, IGMarkets::API_V2).and_return(put_result)
102
- expect(platform.positions['1'].update(stop_level: 1, limit_level: 2)).to eq('reference')
103
- end
104
-
105
- it 'can close a position' do
106
- position = build :position, deal_id: '1', size: 5
107
-
108
- get_result = { position: position.attributes, market: position.market }
109
- payload = { dealId: '1', direction: 'SELL', orderType: 'MARKET', size: 5.0, timeInForce: 'EXECUTE_AND_ELIMINATE' }
110
- delete_result = { deal_reference: 'reference' }
111
-
112
- expect(session).to receive(:get).with('positions/1', IGMarkets::API_V2).and_return(get_result)
113
- expect(session).to receive(:delete).with('positions/otc', payload, IGMarkets::API_V1).and_return(delete_result)
114
- expect(platform.positions['1'].close).to eq('reference')
115
- end
116
-
117
- it 'validates position close attributes correctly' do
118
- position = build :position, deal_id: '1'
119
- position.instance_variable_set :@dealing_platform, platform
120
-
121
- attributes = { time_in_force: :execute_and_eliminate }
122
-
123
- close_position = proc do |override_attributes = {}|
124
- position.close attributes.merge override_attributes
125
- end
126
-
127
- expect(session).to receive(:delete).exactly(3).times.and_return(deal_reference: 'reference')
128
-
129
- expect { close_position.call }.to_not raise_error
130
- expect { close_position.call order_type: :quote }.to raise_error(ArgumentError)
131
- expect { close_position.call order_type: :quote, quote_id: 'a' }.to raise_error(ArgumentError)
132
- expect { close_position.call order_type: :quote, level: 1 }.to raise_error(ArgumentError)
133
- expect { close_position.call order_type: :quote, quote_id: 'a', level: 1 }.to_not raise_error
134
- expect { close_position.call order_type: :limit }.to raise_error(ArgumentError)
135
- expect { close_position.call order_type: :limit, level: 1 }.to_not raise_error
136
- end
137
- end
@@ -1,39 +0,0 @@
1
- describe IGMarkets::DealingPlatform::SprintMarketPositionMethods 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 'can retrieve the current sprint market positions' do
10
- positions = [build(:sprint_market_position)]
11
-
12
- expect(session).to receive(:get)
13
- .with('positions/sprintmarkets', IGMarkets::API_V1)
14
- .and_return(sprint_market_positions: positions)
15
-
16
- expect(platform.sprint_market_positions.all).to eq(positions)
17
- end
18
-
19
- it 'can create a sprint market position' do
20
- attributes = {
21
- direction: :buy,
22
- epic: 'CS.D.EURUSD.CFD.IP',
23
- expiry_period: :five_minutes,
24
- size: 2.0
25
- }
26
-
27
- payload = {
28
- direction: 'BUY',
29
- epic: 'CS.D.EURUSD.CFD.IP',
30
- expiryPeriod: 'FIVE_MINUTES',
31
- size: 2.0
32
- }
33
-
34
- result = { deal_reference: 'reference' }
35
-
36
- expect(session).to receive(:post).with('positions/sprintmarkets', payload, IGMarkets::API_V1).and_return(result)
37
- expect(platform.sprint_market_positions.create(attributes)).to eq(result.fetch(:deal_reference))
38
- end
39
- end
@@ -1,89 +0,0 @@
1
- describe IGMarkets::DealingPlatform::WatchlistMethods 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 'can retrieve the watchlists' do
10
- watchlists = [build(:watchlist)]
11
-
12
- expect(session).to receive(:get).with('watchlists', IGMarkets::API_V1).and_return(watchlists: watchlists)
13
- expect(platform.watchlists.all).to eq(watchlists)
14
- end
15
-
16
- it 'can retrieve the markets for a watchlist' do
17
- markets = [build(:market_overview)]
18
-
19
- expect(session).to receive(:get).with('watchlists', IGMarkets::API_V1).and_return(watchlists: [{ id: 1 }])
20
- expect(session).to receive(:get).with('watchlists/1', IGMarkets::API_V1).and_return(markets: markets)
21
- expect(platform.watchlists['1'].markets).to eq(markets)
22
- end
23
-
24
- it 'can create a watchlist' do
25
- watchlist_id = '1000'
26
- name = 'New Watchlist'
27
- epics = ['ABCDEF']
28
-
29
- expect(session).to receive(:post)
30
- .with('watchlists', { name: name, epics: epics }, IGMarkets::API_V1)
31
- .and_return(watchlist_id: watchlist_id, status: 'SUCCESS')
32
-
33
- expect(session).to receive(:get)
34
- .with('watchlists', IGMarkets::API_V1)
35
- .and_return(watchlists: [{ id: watchlist_id }])
36
-
37
- expect(platform.watchlists.create(name, epics)).to eq(IGMarkets::Watchlist.new(id: watchlist_id))
38
- end
39
-
40
- it 'can delete a watchlist' do
41
- watchlist_id = '1000'
42
-
43
- result = { status: 'SUCCESS' }
44
-
45
- expect(session).to receive(:get)
46
- .with('watchlists', IGMarkets::API_V1)
47
- .and_return(watchlists: [{ id: watchlist_id }])
48
-
49
- expect(session).to receive(:delete)
50
- .with("watchlists/#{watchlist_id}", nil, IGMarkets::API_V1)
51
- .and_return(result)
52
-
53
- expect(platform.watchlists[watchlist_id].delete).to eq(result)
54
- end
55
-
56
- it 'can add a market to a watchlist' do
57
- watchlist_id = '1000'
58
- epic = 'ABCDEF'
59
-
60
- result = { status: 'SUCCESS' }
61
-
62
- expect(session).to receive(:get)
63
- .with('watchlists', IGMarkets::API_V1)
64
- .and_return(watchlists: [{ id: watchlist_id }])
65
-
66
- expect(session).to receive(:put)
67
- .with("watchlists/#{watchlist_id}", { epic: epic }, IGMarkets::API_V1)
68
- .and_return(result)
69
-
70
- expect(platform.watchlists[watchlist_id].add_market(epic)).to eq(result)
71
- end
72
-
73
- it 'can remove a market from a watchlist' do
74
- watchlist_id = '1000'
75
- epic = 'ABCDEF'
76
-
77
- result = { status: 'SUCCESS' }
78
-
79
- expect(session).to receive(:get)
80
- .with('watchlists', IGMarkets::API_V1)
81
- .and_return(watchlists: [{ id: watchlist_id }])
82
-
83
- expect(session).to receive(:delete)
84
- .with("watchlists/#{watchlist_id}/#{epic}", nil, IGMarkets::API_V1)
85
- .and_return(result)
86
-
87
- expect(platform.watchlists[watchlist_id].remove_market(epic)).to eq(result)
88
- end
89
- end