degiro_client 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da9cf0fe579f0f1c213a32b17c2901db5381d1d0b8b4098eea76a5df983f8cef
4
- data.tar.gz: e35647671e6e281746b231a0d0c988b32daa46c22375451a72db36ec1b97d11d
3
+ metadata.gz: 89680b852755e037aff1d51e84abbc4bee529c240904c4a3359d60a225a581f7
4
+ data.tar.gz: 50754758a586d5816eb45b0037989d77e8fdea620a14f8293c21ec24d9267e90
5
5
  SHA512:
6
- metadata.gz: a69fc835f4f1cbb58cdb361a8edfca33eaada0c8db553f6b0a8fb9ff83550451ca5c877d2ee52361ce55bcc3f07eab19b4d8c3819e8848c04a3e97075d9a5c97
7
- data.tar.gz: decada6030e3f01130769a877266998708b2dbf8452f6c996e7535ce16a72d9b21269242ccd8a6a45e13d3a461a452d88b511ad2516d8b671369cb0d153bbc79
6
+ metadata.gz: ccc8137c988a69429de2069354c76c3887eefe5489759603582ee6606f697582e441c8442f8107f471ade685074d2bce40b24439e535e35100bf564b3cc58899
7
+ data.tar.gz: 2b84e410fc3a476aefaf023d6a74d45f6dd3911a871281963ffa2cd891e98e1f8924ccdc6d66cedee50ce81416cae03c8ae9ba52cd419b1da6485f07f5eccc95
@@ -0,0 +1,2 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'degiro_client/client.rb'
@@ -2,6 +2,7 @@ require 'forwardable'
2
2
 
3
3
  require_relative 'connection.rb'
4
4
  require_relative 'create_order.rb'
5
+ require_relative 'delete_order.rb'
5
6
  require_relative 'find_product_by_id.rb'
6
7
  require_relative 'find_products.rb'
7
8
  require_relative 'get_cash_funds.rb'
@@ -14,6 +15,7 @@ module DeGiro
14
15
  extend Forwardable
15
16
 
16
17
  def_delegators :@create_order, :create_buy_order, :create_sell_order
18
+ def_delegators :@delete_order, :delete_order
17
19
  def_delegators :@find_product_by_id, :find_product_by_id
18
20
  def_delegators :@find_products, :find_products
19
21
  def_delegators :@get_cash_funds, :get_cash_funds
@@ -25,6 +27,7 @@ module DeGiro
25
27
  connection = Connection.new(login, password)
26
28
 
27
29
  @create_order = CreateOrder.new(connection)
30
+ @delete_order = DeleteOrder.new(connection)
28
31
  @find_product_by_id = FindProductById.new(connection)
29
32
  @find_products = FindProducts.new(connection)
30
33
  @get_cash_funds = GetCashFunds.new(connection)
@@ -1,6 +1,8 @@
1
1
  require 'json'
2
2
  require 'faraday'
3
+ require 'faraday/detailed_logger'
3
4
  require 'faraday-cookie_jar'
5
+ require 'logger'
4
6
 
5
7
  require_relative 'urls_map.rb'
6
8
  require_relative 'user_data.rb'
@@ -10,15 +12,20 @@ module DeGiro
10
12
  class Connection
11
13
  extend Forwardable
12
14
 
13
- def_delegators :@conn, :get, :post
15
+ def_delegators :@conn, :get, :post, :delete
14
16
  attr_reader :urls_map, :user_data, :session_id
15
17
 
16
18
  BASE_TRADER_URL = 'https://trader.degiro.nl'.freeze
17
19
 
18
20
  def initialize(login, password)
21
+
22
+ my_logger = Logger.new("degiro_client.log")
23
+ my_logger.level = Logger::DEBUG
24
+
19
25
  @conn = Faraday.new(url: BASE_TRADER_URL) do |builder|
20
26
  builder.use :cookie_jar
21
27
  builder.use Faraday::Response::RaiseError
28
+ builder.response :detailed_logger, my_logger
22
29
  builder.adapter Faraday.default_adapter
23
30
  end
24
31
 
@@ -37,7 +44,8 @@ module DeGiro
37
44
  raise MissingSessionIdError, 'Could not find valid session id' if @session_id == '' || @session_id.nil?
38
45
 
39
46
  @urls_map = UrlsMap.new(JSON.parse(@conn.get('/login/secure/config').body))
40
- @user_data = UserData.new(JSON.parse(@conn.get("#{@urls_map['pa_url']}/client?sessionId=#{@session_id}").body)["data"])
47
+ url = "#{@urls_map['pa_url']}/client?sessionId=#{@session_id}"
48
+ @user_data = UserData.new(JSON.parse(@conn.get(url).body)["data"])
41
49
  end
42
50
  end
43
51
  end
@@ -2,7 +2,7 @@ require 'json'
2
2
 
3
3
  module DeGiro
4
4
  class CreateOrder
5
- BUY_SELL = { buy: 0, sell: 1 }.freeze
5
+ BUY_SELL = { buy: "BUY", sell: "SELL" }.freeze
6
6
  ORDER_TYPES = { limited: 0, stop_limited: 1, market_order: 2, stop_loss: 3 }.freeze
7
7
  TIME_TYPES = { day: 1, permanent: 3 }.freeze
8
8
 
@@ -11,24 +11,27 @@ module DeGiro
11
11
  end
12
12
 
13
13
  def create_buy_order(product_id:, size:, price:)
14
- order = order(BUY_SELL[:buy], product_id, size, price)
15
- confirmation_id = JSON.parse(check_order(order).body)['confirmationId']
16
- confirm_order(order, confirmation_id)
14
+ create_order_with_confirmation(BUY_SELL[:buy], product_id, size, price)
17
15
  end
18
16
 
19
17
  def create_sell_order(product_id:, size:, price:)
20
- order = order(BUY_SELL[:sell], product_id, size, price)
21
- confirmation_id = JSON.parse(check_order(order).body)['confirmationId']
22
- confirm_order(order, confirmation_id)
18
+ create_order_with_confirmation(BUY_SELL[:sell], product_id, size, price)
23
19
  end
24
20
 
25
21
  private
26
22
 
23
+ def create_order_with_confirmation(buy_sell, product_id, size, price)
24
+ order = order(buy_sell, product_id, size, price)
25
+ response = check_order(order)
26
+ confirmation_id = JSON.parse(response.body)['data']['confirmationId']
27
+ confirm_order(order, confirmation_id)
28
+ end
29
+
27
30
  def order(type, product_id, size, price)
28
31
  {
29
- buysell: type,
32
+ buySell: type,
30
33
  orderType: ORDER_TYPES[:limited],
31
- productId: product_id,
34
+ productId: product_id.to_i,
32
35
  size: size,
33
36
  timeType: TIME_TYPES[:permanent],
34
37
  price: price
@@ -0,0 +1,24 @@
1
+ require 'json'
2
+
3
+ module DeGiro
4
+ class DeleteOrder
5
+
6
+ def initialize(connection)
7
+ @connection = connection
8
+ end
9
+
10
+ def delete_order(id)
11
+ @connection.delete(url(id))
12
+ end
13
+
14
+ private
15
+
16
+ def url(confirmation_id)
17
+ "#{@connection.urls_map['trading_url']}/v5/order/#{confirmation_id}" \
18
+ ";jsessionid=#{@connection.session_id}" \
19
+ "?intAccount=#{@connection.user_data['int_account']}" \
20
+ "&sessionId=#{@connection.session_id}"
21
+ end
22
+
23
+ end
24
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -7,7 +7,7 @@ module DeGiro
7
7
  @connection = connection
8
8
  end
9
9
 
10
- def get_transactions(from: (Date.today - (365 * 5)).strftime('%d/%m/%Y'), to: Date.today.strftime('%d/%m/%Y'))
10
+ def get_transactions(from: (Date.zone.today - (365 * 5)).strftime('%d/%m/%Y'), to: Date.zone.today.strftime('%d/%m/%Y'))
11
11
  params = URI.encode_www_form(fromDate: from, toDate: to)
12
12
  parse_transactions(JSON.parse(@connection.get(url(params)).body))
13
13
  end
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ module DeGiro
2
+ VERSION = '0.0.4'.freeze
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: degiro_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grzegorz Błaszczyk
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-08-15 00:00:00.000000000 Z
12
+ date: 2019-08-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -39,6 +39,20 @@ dependencies:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
41
  version: 0.0.6
42
+ - !ruby/object:Gem::Dependency
43
+ name: faraday-detailed_logger
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 2.1.3
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 2.1.3
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: pry
44
58
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +81,8 @@ dependencies:
67
81
  - - "~>"
68
82
  - !ruby/object:Gem::Version
69
83
  version: 0.51.0
70
- description: Ruby Client for the unofficial DeGiro API
84
+ description: Ruby Client for the unofficial DeGiro API - working version with all
85
+ basic methods
71
86
  email:
72
87
  - grzegorz.blaszczyk@gmail.com
73
88
  - tomvaneyck@gmail.com
@@ -75,20 +90,21 @@ executables: []
75
90
  extensions: []
76
91
  extra_rdoc_files: []
77
92
  files:
78
- - lib/degiro.rb
79
- - lib/degiro/client.rb
80
- - lib/degiro/connection.rb
81
- - lib/degiro/create_order.rb
82
- - lib/degiro/errors.rb
83
- - lib/degiro/find_product_by_id.rb
84
- - lib/degiro/find_products.rb
85
- - lib/degiro/get_cash_funds.rb
86
- - lib/degiro/get_orders.rb
87
- - lib/degiro/get_portfolio.rb
88
- - lib/degiro/get_transactions.rb
89
- - lib/degiro/urls_map.rb
90
- - lib/degiro/user_data.rb
91
- - lib/degiro/version.rb
93
+ - lib/degiro_client.rb
94
+ - lib/degiro_client/client.rb
95
+ - lib/degiro_client/connection.rb
96
+ - lib/degiro_client/create_order.rb
97
+ - lib/degiro_client/delete_order.rb
98
+ - lib/degiro_client/errors.rb
99
+ - lib/degiro_client/find_product_by_id.rb
100
+ - lib/degiro_client/find_products.rb
101
+ - lib/degiro_client/get_cash_funds.rb
102
+ - lib/degiro_client/get_orders.rb
103
+ - lib/degiro_client/get_portfolio.rb
104
+ - lib/degiro_client/get_transactions.rb
105
+ - lib/degiro_client/urls_map.rb
106
+ - lib/degiro_client/user_data.rb
107
+ - lib/degiro_client/version.rb
92
108
  homepage: https://github.com/grzegorzblaszczyk/degiro
93
109
  licenses:
94
110
  - MIT
data/lib/degiro.rb DELETED
@@ -1 +0,0 @@
1
- require_relative 'degiro/client.rb'
@@ -1,3 +0,0 @@
1
- module DeGiro
2
- VERSION = '0.0.2'.freeze
3
- end