Skip to content

Commit 4825469

Browse files
committed
add logout
1 parent 7e20eec commit 4825469

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ ig = igapi.IG(apikey, username, password, account, acc_type)
2727
```
2828
print(ig.getVersion())
2929
```
30-
- login
30+
- Login
3131
```
3232
ig.login()
3333
```
34+
- Logout
35+
```
36+
ig.logout()
37+
```
3438
- Get account information
3539
```
3640
account = ig.account()

igapi/__init__.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class Config:
88
def __init__(self, account_type):
9-
if account_type == 'Live':
9+
if account_type == 'LIVE':
1010
self.acc_type = 'LIVE'
1111
self.endpoint = 'https://api.ig.com/gateway/deal'
1212
else:
@@ -26,7 +26,7 @@ def __init__(self, key, username, password, account, acc_type='DEMO'):
2626
self.s = requests.Session()
2727
self.config = Config(self.account_type)
2828
self.ls_client = None
29-
self.version = '1.0.2'
29+
self.version = '1.0.3'
3030

3131
def getVersion(self):
3232
return self.version
@@ -36,7 +36,10 @@ def login(self):
3636
self.CST = response.headers['CST']
3737
self.X_SECURITY_TOKEN = response.headers['X-SECURITY-TOKEN']
3838

39-
39+
def logout(self):
40+
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'})
41+
return response.text
42+
4043
def account(self):
4144
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'})
4245
time.sleep(0.5)

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="ig-trading-api",
8-
version="1.0.2",
8+
version="1.0.3",
99
author="Hurin Hu",
1010
author_email="[email protected]",
1111
description="Simple IG trading API for Python",

0 commit comments

Comments
 (0)