From 48254690f9b052c02bd96bd2716ef4e0acf0b1ba Mon Sep 17 00:00:00 2001 From: HurinHu Date: Wed, 23 Nov 2022 22:22:12 +1300 Subject: [PATCH] add logout --- README.md | 6 +++++- igapi/__init__.py | 9 ++++++--- setup.py | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6d2e04c..7504dca 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,14 @@ ig = igapi.IG(apikey, username, password, account, acc_type) ``` print(ig.getVersion()) ``` -- login +- Login ``` ig.login() ``` +- Logout +``` +ig.logout() +``` - Get account information ``` account = ig.account() diff --git a/igapi/__init__.py b/igapi/__init__.py index 3d21732..1e1f5c9 100644 --- a/igapi/__init__.py +++ b/igapi/__init__.py @@ -6,7 +6,7 @@ class Config: def __init__(self, account_type): - if account_type == 'Live': + if account_type == 'LIVE': self.acc_type = 'LIVE' self.endpoint = 'https://api.ig.com/gateway/deal' else: @@ -26,7 +26,7 @@ def __init__(self, key, username, password, account, acc_type='DEMO'): self.s = requests.Session() self.config = Config(self.account_type) self.ls_client = None - self.version = '1.0.2' + self.version = '1.0.3' def getVersion(self): return self.version @@ -36,7 +36,10 @@ def login(self): self.CST = response.headers['CST'] self.X_SECURITY_TOKEN = response.headers['X-SECURITY-TOKEN'] - + def logout(self): + response = self.s.post(self.config.endpoint+'/session', headers={'X-IG-API-KEY': self.api_key, 'CST': self.CST, 'X-SECURITY-TOKEN': self.X_SECURITY_TOKEN, 'Content-Type': 'application/json; charset=UTF-8', 'Accept': 'application/json; charset=UTF-8', '_method':'DELETE', 'VERSION': '1'}) + return response.text + def account(self): response = self.s.get(self.config.endpoint+'/accounts', headers={'X-IG-API-KEY': self.api_key, 'CST': self.CST, 'X-SECURITY-TOKEN': self.X_SECURITY_TOKEN, 'Content-Type': 'application/json;', 'Accept': 'application/json; charset=UTF-8', 'VERSION': '1'}) time.sleep(0.5) diff --git a/setup.py b/setup.py index b51e08d..f0f99c8 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="ig-trading-api", - version="1.0.2", + version="1.0.3", author="Hurin Hu", author_email="hurin@live.ca", description="Simple IG trading API for Python",