Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Mon Aug 15 19:24:17 2016
- @author: Malte
- """
- import requests
- import json
- import base64
- import time
- from datetime import datetime
- urlbasis="http://stable.alpha-trader.com/"
- def dateTime(days):
- # datetime helpfunction
- now=datetime.now()
- now=time.mktime(now.timetuple())
- maturityDate=now+days*60*60*24
- maturityDate=int(maturityDate)
- maturityDate=str(maturityDate)+"000"
- return maturityDate
- print(maturityDate)
- class ApiCom:
- partnerID = "986ffb5a-430e-4cf6-82c3-044f30052548"
- def __init__(self, user, password):
- self.user = user
- if password == "password":
- self.password = "pw!"+user
- else:
- self.password = password
- self.mail=self.user+"qwertzuiolfh@gmx.de"
- self.header()
- self.headerShort()
- def __str__(self):
- self.header= "No header yet"
- self.headerShort = "No header yet"
- self.chatstring = "no Account"
- def header(self):
- auth="Basic " + base64.encodestring(self.user+":" + self.password)
- auth=auth.replace('\n', '')
- header={
- 'authorization': auth,
- 'x-authorization': self.partnerID,
- 'cache-control': "no-cache",
- }
- self.header = header
- def headerShort(self):
- auth="Basic " + base64.encodestring(self.user+":" + self.password)
- auth=auth.replace('\n', '')
- header={
- 'x-authorization': self.partnerID,
- 'cache-control': "no-cache",
- }
- self.headerShort = header
- def register(self):
- url=urlbasis+"user/register"
- querystring={"username": self.user, "emailAddress": self.mail,"password": self.password}
- requests.request("POST", url, headers=self.headerShort, params=querystring)
- time.sleep(2)
- self.quitChat()
- def newCompany(self):
- url=urlbasis+"api/companies/"
- compName=self.user+" Limited"
- querystring={"name": compName, "cashDeposit": "50000"}
- requests.request("POST", url, headers=self.header, params=querystring)
- def getChatstring(self):
- url=urlbasis+"api/chats"
- response=requests.request("GET", url, headers=self.header)
- parsed_json=json.loads(response.text)
- chatstring=parsed_json[0]['id']
- self.chatstring=chatstring
- def quitChat(self):
- self.getChatstring()
- url=urlbasis+"api/chats/quitchat/"+self.chatstring
- requests.put(url, headers=self.header)
- class Company(ApiCom):
- def __init__(self, compName):
- self.compName=compName
- def masterUser(self):
- UserName="Malte"
- password="dvQ-bYV-pbW-s6D"
- auth="Basic " + base64.encodestring(UserName+":" + password)
- auth=auth.replace('\n', '')
- header={
- 'authorization': auth,
- 'x-authorization': "986ffb5a-430e-4cf6-82c3-044f30052548",
- 'cache-control': "no-cache",
- }
- self.masterUser=header
- def newCompany(CompName, user):
- url=urlbasis+"api/companies/"
- querystring={"name": CompName, "cashDeposit": "50000"}
- header=user.header
- requests.request("POST", url, headers=header, params=querystring)
- def account(self):
- url=urlbasis+"api/search/companies/"+self.compName
- response=requests.request("GET", url, headers=self.masterUser)
- parsed_json=json.loads(response.text)
- self.securitiesAccountID=parsed_json[0]['securitiesAccountId']
- self.user=parsed_json[0]['ceo']['username']
- self.userID=parsed_json[0]['ceo']['id']
- self.compID=parsed_json[0]['id']
- def header(self):
- pass
- def order(self, securityIdentifier, action, type2, price, numberOfShares):
- querystring={"owner": self.securitiesAccountID, "securityIdentifier": securityIdentifier, "action": action, "type": type2, "price": price, "numberOfShares":numberOfShares}
- url=urlbasis+"api/securityorders/?"
- response=requests.request("POST", url, headers=self.header, params=querystring)
- print(response)
- def newBond(self, numberOfBonds, faceValue, interestRate, maturityDate):
- url=urlbasis+"api/bonds/"
- maturityDate=dateTime(maturityDate)
- querystring={"companyId": self.compID, "numberOfBonds": numberOfBonds, "faceValue": faceValue, "interestRate": interestRate, "maturityDate": maturityDate}
- response=requests.request("POST", url, headers=self.header, params=querystring)
- if str(response.status_code) == "201":
- print("Bond erstellt")
- else:
- print("Bond nicht erstellt")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement