em-nordnet 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,14 @@
1
+ #encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe Em::Nordnet::Config do
5
+ subject do
6
+ Em::Nordnet::Config.new 'https://api.test.nordnet.se', 'user', 'secret', 'pem', 'service'
7
+ end
8
+
9
+ its(:url) { should == 'https://api.test.nordnet.se' }
10
+ its(:user) { should == 'user' }
11
+ its(:password) { should == 'secret' }
12
+ its(:pem) { should == 'pem' }
13
+ its(:service) { should == 'service' }
14
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Em::Nordnet::Goliath::PublicFeed do
4
+ describe '.connection'
5
+
6
+ describe '.subscribe'
7
+
8
+ describe 'initialization'
9
+
10
+ describe '#run'
11
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Em::Nordnet::Instrument do
4
+ describe 'initialization' do
5
+ let(:attributes) do
6
+ {
7
+ id: 123,
8
+ market_id: 321,
9
+ currency: 'SEK',
10
+ shortname: 'Swedbank A',
11
+ longname: 'Swedbank A',
12
+ is_in_code: '123123123',
13
+ ticksize_id: '123123123'
14
+ }
15
+ end
16
+
17
+ subject { Em::Nordnet::Instrument.new attributes }
18
+
19
+ its(:id) { should == 123 }
20
+ its(:market_id) { should == 321 }
21
+ its(:currency) { should == 'SEK' }
22
+ its(:shortname) { should == 'Swedbank A' }
23
+ its(:longname) { should == 'Swedbank A' }
24
+ its(:is_in_code) { should == '123123123' }
25
+ its(:ticksize_id) { should == '123123123' }
26
+ end
27
+
28
+ describe '.search' do
29
+ it 'should return a collection of instruments matching the symbol and options'
30
+ end
31
+
32
+ describe '#subscribe_params' do
33
+ it 'should return subscription feed parameters for the given type'
34
+ end
35
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Em::Nordnet::Order do
4
+
5
+ describe 'initialization' do
6
+ let(:account) { Em::Nordnet::Account.new }
7
+ let(:instrument) { Em::Nordnet::Instrument.new}
8
+ let(:attributes) { { id: 123, account: account, instrument: instrument, price: 23.2, status: 'OK' } }
9
+
10
+ subject { Em::Nordnet::Order.new attributes }
11
+
12
+ its(:id) { should == 123 }
13
+ its(:account) { should == account }
14
+ its(:instrument) { should == instrument }
15
+ its(:price) { should == 23.2 }
16
+ its(:status) { should == 'OK' }
17
+ end
18
+
19
+
20
+ describe '.buy' do
21
+ it 'needs to be tested'
22
+ end
23
+
24
+ describe '.all' do
25
+ it 'should return a collection of orders belonging to the given account id'
26
+ end
27
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Em::Nordnet do
4
+ describe '.configure' do
5
+ def alternative_config
6
+ Em::Nordnet.configure do |c|
7
+ c.url = 'https://api.test.nordnet.se'
8
+ c.user = 'user'
9
+ c.password = 'password'
10
+ c.pem = 'PEM'
11
+ c.service = 'SERVICE'
12
+ end
13
+ end
14
+
15
+ subject { Em::Nordnet.config }
16
+
17
+ before(:all) { alternative_config }
18
+ after(:all) { configure_nordnet }
19
+
20
+ its(:url) { should == 'https://api.test.nordnet.se' }
21
+ its(:user) { should == 'user' }
22
+ its(:password) { should == 'password' }
23
+ its(:pem) { should == 'PEM' }
24
+ its(:service) { should == 'SERVICE' }
25
+ end
26
+
27
+ describe '.config' do
28
+ it 'should return an instance of config' do
29
+ Em::Nordnet.config.should be_instance_of(Em::Nordnet::Config)
30
+ end
31
+
32
+ it 'should be memoized' do
33
+ Em::Nordnet.config.should === Em::Nordnet.config
34
+ end
35
+ end
36
+
37
+ describe '.api', type: 'api authenticated' do
38
+ it 'should return an instance of api' do
39
+ Em::Nordnet.api.should be_instance_of(Em::Nordnet::Api)
40
+ end
41
+
42
+ it 'should be memoized' do
43
+ Em::Nordnet.api.should === Em::Nordnet.api
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,28 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+
18
+ config.before(:all) { configure_nordnet }
19
+ config.before(:each, type: 'api authenticated') { stub_login }
20
+ end
21
+
22
+ require_relative 'support/configure_helper'
23
+ require_relative 'support/api_helper'
24
+
25
+ require 'rubygems'
26
+ require 'webmock/rspec'
27
+
28
+ require 'em-nordnet'
@@ -0,0 +1,15 @@
1
+ def default_headers
2
+ { headers: { 'Content-Length' => 0, 'Content-Type' => 'application/json' } }
3
+ end
4
+
5
+ def authorization_headers
6
+ { headers: { 'Accept-Encoding' => 'gzip, compressed', 'Authorization' => 'Basic Y2YxNDdjNjkwZjY1ZmUxMDY4ZjQwZWYyM2YyMzY0OGViZjhjN2YwMjpjZjE0N2M2OTBmNjVmZTEwNjhmNDBlZjIzZjIzNjQ4ZWJmOGM3ZjAy', 'Content-Type' => 'application/json' } }
7
+ end
8
+
9
+ def post_authorization_headers
10
+ { headers: { 'Authorization' => 'Basic Y2YxNDdjNjkwZjY1ZmUxMDY4ZjQwZWYyM2YyMzY0OGViZjhjN2YwMjpjZjE0N2M2OTBmNjVmZTEwNjhmNDBlZjIzZjIzNjQ4ZWJmOGM3ZjAy', 'Content-Length' => '0', 'Content-Type' => 'application/json' } }
11
+ end
12
+
13
+ def delete_authorization_headers
14
+ { headers: { 'Authorization' => 'Basic Y2YxNDdjNjkwZjY1ZmUxMDY4ZjQwZWYyM2YyMzY0OGViZjhjN2YwMjpjZjE0N2M2OTBmNjVmZTEwNjhmNDBlZjIzZjIzNjQ4ZWJmOGM3ZjAy', 'Content-Type' => 'application/json' } }
15
+ end
@@ -0,0 +1,205 @@
1
+ def login_result
2
+ {
3
+ environment: 'test',
4
+ session_key: 'cf147c690f65fe1068f40ef23f23648ebf8c7f02',
5
+ private_feed: {port: 443, hostname: 'priv.api.test.nordnet.se', encrypted: true},
6
+ expires_in: 300,
7
+ country: 'SE',
8
+ public_feed: {port: 443, hostname: 'pub.api.test.nordnet.se', encrypted: true}
9
+ }
10
+ end
11
+
12
+ def touch_result
13
+ {logged_in: true}
14
+ end
15
+
16
+ def realtime_access_result
17
+ [{level: 2, marketID: '44'}, {level: 2, marketID: '11'}]
18
+ end
19
+
20
+ def news_sources_result
21
+ [{
22
+ name: 'SIX News Norway',
23
+ imageurl: 'now/images/loggaSix.gif',
24
+ code: 'sixnn',
25
+ sourceid: 50,
26
+ level: 'REALTIME'
27
+ }]
28
+ end
29
+
30
+ def news_items_result
31
+ pending "Needs request result"
32
+ end
33
+
34
+ def news_item_result
35
+ pending "Needs request result"
36
+ end
37
+
38
+ def accounts_result
39
+ [{alias: nil, default: 'true', id: '9210370'}]
40
+ end
41
+
42
+ def account_result
43
+ {
44
+ ownCapital: '1000000.0',
45
+ futureSum: '0.0',
46
+ forwardSum: '0.0',
47
+ collateral: '0.0',
48
+ interest: '0.0',
49
+ tradingPower: '1000000.0',
50
+ accountSum: '1000000.0',
51
+ loanLimit: '1000000.0',
52
+ pawnValue: '0.0',
53
+ fullMarketvalue: '0.0',
54
+ ownCapitalMorning: '1000000.0',
55
+ accountCurrency: 'SEK'
56
+ }
57
+ end
58
+
59
+ def ledgers_result
60
+ [{
61
+ accountSumAcc: '1000000.0',
62
+ accIntCred: '0.0',
63
+ currency: 'SEK',
64
+ accIntDeb: '0.0',
65
+ accountSum: '1000000.0'
66
+ }]
67
+ end
68
+
69
+ def positions_result
70
+ pending "Needs request result"
71
+ end
72
+
73
+ def orders_result
74
+ [{
75
+ priceCondition: 'LIMIT',
76
+ validity: { validUntil: 1344870300000, type: 'DAY' },
77
+ price: { value: 60.0, curr: 'SEK' },
78
+ side: 'BUY',
79
+ orderID: 651270,
80
+ volumeCondition: 'NORMAL',
81
+ tradedVolume: 0.0,
82
+ instrumentID: {marketID: 11, identifier: '101'},
83
+ orderState: 'LOCAL',
84
+ accno: 9210370,
85
+ openVolume: 0.0,
86
+ volume: 200.0,
87
+ actionState: 'INS_PEND',
88
+ activationCondition: {type: 'NONE'},
89
+ modDate: 1344768947395
90
+ }]
91
+ end
92
+
93
+ def trades_result
94
+ pending "Needs request result"
95
+ end
96
+
97
+ def instrument_search_result
98
+ [instrument_lookup_result]
99
+ end
100
+
101
+ def instrument_lookup_result
102
+ {
103
+ currency: 'SEK',
104
+ type: 'A',
105
+ country: 'SE',
106
+ identifier: 101,
107
+ marketID: 11,
108
+ shortname: 'ERIC B',
109
+ isinCode: 'SE0000108656',
110
+ longname: 'Ericsson B',
111
+ ticksizeid: 12
112
+ }
113
+ end
114
+
115
+ def multiple_instrument_lookup_result
116
+ pending "Needs request result"
117
+ end
118
+
119
+ def chart_data_result
120
+ pending "Needs request result"
121
+ end
122
+
123
+ def lists_result
124
+ [{name: 'First North SE', country: 'SE', id: '6'}]
125
+ end
126
+
127
+ def list_items_result
128
+ pending "Needs request result"
129
+ end
130
+
131
+ def markets_result
132
+ [{
133
+ name: 'Burgundy',
134
+ country: 'DK',
135
+ marketID: '32',
136
+ ordertypes: [
137
+ {text: 'Normal order', type: 'NORMAL'},
138
+ {text: 'Fill or kill', type: 'FOK'},
139
+ {text: 'Fill and kill', type: 'FAK'}
140
+ ]
141
+ }]
142
+ end
143
+
144
+ def trading_days_result
145
+ [
146
+ {date: '2012-08-13', display_date: '2012-08-13'},
147
+ {date: '2012-08-14', display_date: '2012-08-14'}
148
+ ]
149
+ end
150
+
151
+ def indices_result
152
+ [{longname: 'test', source: 'test', id: 'test', type: 'INDEX', country: 'SE'}]
153
+ end
154
+
155
+ def ticksizes_result
156
+ [
157
+ {tick: 1.0, above: 1000.0, decimals: 0},
158
+ {tick: 5.0, above: 5000.0, decimals: 0},
159
+ {tick: 10.0, above: 10000.0, decimals: 0},
160
+ {tick: 50.0, above: 50000.0, decimals: 0}
161
+ ]
162
+ end
163
+
164
+ def countries_result
165
+ ['SE', 'NO', 'FI']
166
+ end
167
+
168
+ def underlyings_result
169
+ [
170
+ {shortname: 'SKF B', marketID: '11', identifier: '285'},
171
+ {shortname: 'SCA B', marketID: '11', identifier: '323'},
172
+ {shortname: 'STE R', marketID: '11', identifier: '2170'},
173
+ ]
174
+ end
175
+
176
+ def derivatives_result
177
+ [{
178
+ kind: 'WNT',
179
+ shortname: 'MINISHRT MTG A',
180
+ strikeprice: '99999.000000',
181
+ multiplier: '1',
182
+ expirydate: '2020-01-01 00:00:00',
183
+ marketID: '35',
184
+ expirytype: 'European',
185
+ currency: 'SEK',
186
+ callPut: 'Warrant Put',
187
+ identifier: 'LJV'
188
+ }]
189
+ end
190
+
191
+ def related_markets_result
192
+ [{marketID: 11, identifier: '101'}, {marketID: 30, identifier: '1965'}]
193
+ end
194
+
195
+ def create_order_result
196
+ { orderID: 6670, resultCode: 'OK', orderState: 'LOCAL', actionState: 'INS_PEND' }
197
+ end
198
+
199
+ def modify_order_result
200
+ pending "Needs request result"
201
+ end
202
+
203
+ def destroy_order_result
204
+ { orderID: 6670, resultCode: 'OK', orderState: 'LOCAL', actionState: 'DEL_PEND' }
205
+ end
@@ -0,0 +1,137 @@
1
+ def stub_get url, result
2
+ json = MultiJson.dump result
3
+ stub_request(:get, url).
4
+ with(authorization_headers).
5
+ to_return body: json, status: 200
6
+ end
7
+
8
+ def stub_login
9
+ json = MultiJson.dump login_result
10
+ stub_request(:post, login_url).
11
+ with(default_headers).
12
+ to_return body: json, status: 200
13
+ end
14
+
15
+ def stub_touch(session)
16
+ json = MultiJson.dump touch_result
17
+ stub_request(:put, touch_url(session)).
18
+ with(default_headers).
19
+ to_return body: json, status: 200
20
+ end
21
+
22
+ def stub_realtime_access
23
+ stub_get realtime_access_url, realtime_access_result
24
+ end
25
+
26
+ def stub_news_sources
27
+ stub_get news_sources_url, news_sources_result
28
+ end
29
+
30
+ def stub_news_items params
31
+ stub_get news_items_url(params), news_items_result
32
+ end
33
+
34
+ def stub_news_item news_item_id
35
+ stub_get news_item_url(news_item_id), news_item_result
36
+ end
37
+
38
+ def stub_accounts
39
+ stub_get accounts_url, accounts_result
40
+ end
41
+
42
+ def stub_account account_id
43
+ stub_get account_url(account_id), account_result
44
+ end
45
+
46
+ def stub_ledgers account_id
47
+ stub_get ledgers_url(account_id), ledgers_result
48
+ end
49
+
50
+ def stub_positions account_id
51
+ stub_get positions_url(account_id), positions_result
52
+ end
53
+
54
+ def stub_orders account_id
55
+ stub_get orders_url(account_id), orders_result
56
+ end
57
+
58
+ def stub_trades account_id
59
+ stub_get orders_url(account_id), trades_result
60
+ end
61
+
62
+ def stub_instrument_search params
63
+ stub_get instruments_url(params), instrument_search_result
64
+ end
65
+
66
+ def stub_instrument_lookup params
67
+ stub_get instruments_url(params), instrument_lookup_result
68
+ end
69
+
70
+ def stub_multiple_instrument_lookup list
71
+ stub_get instruments_url(list: list), multiple_instrument_lookup_result
72
+ end
73
+
74
+ def stub_chart_data params
75
+ stub_get chart_data_url(params), chart_data_result
76
+ end
77
+
78
+ def stub_lists
79
+ stub_get lists_url, lists_result
80
+ end
81
+
82
+ def stub_list_items list_id
83
+ stub_get list_items_url(list_id), list_items_result
84
+ end
85
+
86
+ def stub_markets
87
+ stub_get markets_url, markets_result
88
+ end
89
+
90
+ def stub_trading_days market_id
91
+ stub_get trading_days_url(market_id), trading_days_result
92
+ end
93
+
94
+ def stub_indices
95
+ stub_get indices_url, indices_result
96
+ end
97
+
98
+ def stub_ticksizes instrument_id
99
+ stub_get ticksizes_url(instrument_id), ticksizes_result
100
+ end
101
+
102
+ def stub_countries derivative_type
103
+ stub_get countries_url(derivative_type), countries_result
104
+ end
105
+
106
+ def stub_underlyings derivative_type, country
107
+ stub_get underlyings_url(derivative_type, country), underlyings_result
108
+ end
109
+
110
+ def stub_derivatives derivative_type, params
111
+ stub_get derivatives_url(derivative_type, params), derivatives_result
112
+ end
113
+
114
+ def stub_related_markets params
115
+ stub_get related_markets_url(params), related_markets_result
116
+ end
117
+
118
+ def stub_create_order account_id, params
119
+ json = MultiJson.dump create_order_result
120
+ stub_request(:post, orders_url(account_id, params)).
121
+ with(post_authorization_headers).
122
+ to_return body: json, status: 200
123
+ end
124
+
125
+ def stub_modify_order account_id, order_id, params
126
+ json = MultiJson.dump modify_order_result
127
+ stub_request(:put, order_url(account_id, order_id)).
128
+ with(post_authorization_headers).
129
+ to_return body: json, status: 200
130
+ end
131
+
132
+ def stub_destroy_order account_id, order_id
133
+ json = MultiJson.dump destroy_order_result
134
+ stub_request(:delete, order_url(account_id, order_id)).
135
+ with(delete_authorization_headers).
136
+ to_return body: json, status: 200
137
+ end