Skip to content

Commit

Permalink
add logout
Browse files Browse the repository at this point in the history
  • Loading branch information
HurinHu committed Nov 23, 2022
1 parent 7e20eec commit 4825469
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 6 additions & 3 deletions igapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="ig-trading-api",
version="1.0.2",
version="1.0.3",
author="Hurin Hu",
author_email="[email protected]",
description="Simple IG trading API for Python",
Expand Down

0 comments on commit 4825469

Please sign in to comment.