Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add session usage #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions degiroapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from degiroapi.datatypes import Data
from degiroapi.intervaltypes import Interval

session = requests.Session()

class DeGiro:
__LOGIN_URL = 'https://trader.degiro.nl/login/secure/login'
Expand Down Expand Up @@ -72,17 +73,17 @@ def __request(url, cookie=None, payload=None, headers=None, data=None, post_para
error_message='An error occurred.'):

if request_type == DeGiro.__DELETE_REQUEST:
response = requests.delete(url, json=payload)
response = session.delete(url, json=payload)
elif request_type == DeGiro.__GET_REQUEST and cookie:
response = requests.get(url, cookies=cookie)
response = session.get(url, cookies=cookie)
elif request_type == DeGiro.__GET_REQUEST:
response = requests.get(url, params=payload)
response = session.get(url, params=payload)
elif request_type == DeGiro.__POST_REQUEST and headers and data:
response = requests.post(url, headers=headers, params=payload, data=data)
response = session.post(url, headers=headers, params=payload, data=data)
elif request_type == DeGiro.__POST_REQUEST and post_params:
response = requests.post(url, params=post_params, json=payload)
response = session.post(url, params=post_params, json=payload)
elif request_type == DeGiro.__POST_REQUEST:
response = requests.post(url, json=payload)
response = session.post(url, json=payload)
else:
raise Exception(f'Unknown request type: {request_type}')

Expand Down