Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import base64
- import json
- import os
- import time
- import string
- import random
- import names
- from data import*
- #content of data.py
- #egelauth="Basic XXXXXX"
- #egelaccountid="XXXXXX" #stable
- #i=0
- #password="XXX" #password for bots
- #urlbasis="http://stable.alpha-trader.com/"
- #partnerid="XXXXX" #stable
- #headeregel={
- # 'authorization': egelauth,
- # 'x-authorization': partnerid,
- # 'cache-control': "no-cache",
- # }
- #auth=""
- def getPortfolio(securityAccount):
- url = urlbasis+"api/portfolios/"+securityAccount
- response = requests.request("GET", url, headers=headeregel, timeout=50)
- parsed_json = json.loads(response.text)
- return parsed_json
- def getOrderbook(securityIdentifier):
- #timestamp = int(time.time())
- url = urlbasis+"api/orderbook/"+securityIdentifier
- #try:
- # response = requests.request("GET", url, headers=headeregel, timeout=50)
- # parsed_json = json.loads(response.text)
- #except:
- # parsed_json="[]"
- #print(parsed_json)
- response = requests.request("GET", url, headers=headeregel, timeout=50)
- parsed_json = json.loads(response.text)
- #timeneeded=int(time.time())-timestamp
- #print(timeneeded)
- #print("timeneeded")
- return parsed_json
- def createUser(username, password):
- print("createUser")
- print("\n")
- url = urlbasis+"user/register"
- mail=username+"@gmx.de"
- companyname="comp"+username
- querystring = {"username":username,"emailAddress":mail,"password":password}
- headers = {
- 'x-authorization': partnerid,
- 'cache-control': "no-cache",
- }
- response = requests.request("POST", url, headers=headers, params=querystring)
- print(response.text)
- print("\n")
- print(querystring)
- def createCompany(companyname, username, auth):
- print("createCompany")
- print("\n")
- url = urlbasis+"api/companies/"
- querystring = {"name":companyname,"cashDeposit":"50000"}
- headers = {
- 'authorization': auth,
- 'x-authorization': partnerid,
- 'cache-control': "no-cache",
- }
- response = requests.request("POST", url, headers=headers, params=querystring)
- print(response.text)
- print("\n")
- def getcompanyIDbyUser(username):
- print("getcompanyIDbyUser")
- print("\n")
- url = urlbasis+"api/companies/ceo/username/"+username
- response = requests.request("GET", url, headers=headeregel)
- parsed_json = json.loads(response.text)
- companyid=parsed_json[0]['id']
- return companyid
- def employEgelAsCeo(companyid, auth):
- print("employEgelAsCeo")
- print("\n")
- url = urlbasis+"api/polls/employceo"
- querystring = {"companyId":companyid,"dailyWage":"150"}
- print("test")
- print(auth)
- print("\n")
- print(querystring)
- response = requests.request("POST", url, headers=headeregel, params=querystring)
- print("test")
- #print(response.text)
- print("\n")
- url = urlbasis+"api/polls/"
- headers = {
- 'authorization': auth,
- 'x-authorization': partnerid,
- 'cache-control': "no-cache",
- }
- response = requests.request("GET", url, headers=headers)
- #print(response.text)
- #input()
- #print(json.loads(response))
- parsed_json = json.loads(response.text)
- #input()
- pollid=parsed_json[0]['id']
- print(pollid)
- url = urlbasis+"api/polls/"+pollid
- querystring = {"voices":"50000","votingType":"YES"}
- headers = {
- 'authorization': auth,
- 'x-authorization': partnerid,
- 'cache-control': "no-cache",
- }
- response = requests.request("POST", url, headers=headers, params=querystring)
- print(response.text)
- print("\n")
- #print(response.text)
- url = urlbasis+"api/polls/execute/"+pollid
- response = requests.request("POST", url, headers=headeregel)
- def getSecurityIdentifier(companyname):
- print("getSecurityIdentifier")
- print("\n")
- url = urlbasis+"api/search/companies/"+companyname
- headers = {
- 'authorization': egelauth,
- 'x-authorization': partnerid,
- 'cache-control': "no-cache",
- }
- response = requests.request("GET", url, headers=headers)
- print(response.text)
- print("\n")
- parsed_json = json.loads(response.text)
- securityidentifier=parsed_json[0]['securityIdentifier']
- return securityidentifier
- def getSecurityAccount(companyname):
- #print("getSecurityAccount")
- #print("\n")
- url = urlbasis+"api/search/companies/"+companyname
- headers = {
- 'authorization': egelauth,
- 'x-authorization': partnerid,
- 'cache-control': "no-cache",
- }
- response = requests.request("GET", url, headers=headers)
- #print(response.text)
- #print("\n")
- parsed_json = json.loads(response.text)
- securityaccount=parsed_json[0]['securitiesAccountId']
- return securityaccount
- def getCompanyIDbyName(companyname):
- print("getCompanyIDbyName")
- print("\n")
- url = urlbasis+"api/search/companies/"+companyname
- headers = {
- 'authorization': egelauth,
- 'x-authorization': partnerid,
- 'cache-control': "no-cache",
- }
- response = requests.request("GET", url, headers=headers)
- print(response.text)
- print("\n")
- parsed_json = json.loads(response.text)
- securityaccount=parsed_json[0]['id']
- return securityaccount
- def otcOrderSell(company1, company2):
- print("otcOrderSell")
- print("\n")
- url = urlbasis+"api/securityorders/"
- querystring = {"owner":getSecurityAccount(company1),"securityIdentifier":getSecurityIdentifier(company1),"action":"SELL","type":"LIMIT","price":"1","numberOfShares":"50000","counterparty":getSecurityAccount(company2)}
- headers = {
- 'authorization': egelauth,
- 'x-authorization': partnerid,
- 'cache-control': "no-cache",
- }
- response = requests.request("POST", url, headers=headers, params=querystring)
- print(response.text)
- print("\n")
- querystring = {"owner":getSecurityAccount(company2),"securityIdentifier":getSecurityIdentifier(company1),"action":"BUY","type":"LIMIT","price":"1","numberOfShares":"50000","counterparty":getSecurityAccount(company1)}
- response = requests.request("POST", url, headers=headers, params=querystring)
- print(response.text)
- print("\n")
- def intitiateLiquidationPoll(company):
- print("initiateliquidationpoll")
- print("\n")
- url = urlbasis+"api/polls/liquidation"
- querystring = {"companyId":getCompanyIDbyName(company)}
- headers = {
- 'authorization': egelauth,
- 'x-authorization': partnerid,
- 'cache-control': "no-cache",
- }
- response = requests.request("POST", url, headers=headers, params=querystring)
- print(response.text)
- print("\n")
- #def acceptliquidationpoll(company)
- def sellowncompany(company, auth):
- print("sellowncompany")
- print("\n")
- url = urlbasis+"api/securityorders/"
- querystring = {"owner":getSecurityAccount(company),"securityIdentifier":getSecurityIdentifier(company),"action":"SELL","type":"LIMIT","price":"1","numberOfShares":"50000","counterparty":""}
- headers = {
- 'authorization': auth,
- 'x-authorization': partnerid,
- 'cache-control': "no-cache",
- }
- response = requests.request("POST", url, headers=headers, params=querystring)
- print(response.text)
- print("\n")
- def getlastpoll():
- print("getlastpoll")
- print("\n")
- url = urlbasis+"api/initiatedpolls/"
- response = requests.request("GET", url, headers=headeregel)
- parsed_json = json.loads(response.text)
- #print(parsed_json.lentgh())
- pollid=parsed_json[-1]['id']
- return pollid
- def votepoll (pollid):
- print("votepoll")
- print("\n")
- url = urlbasis+"api/polls/"+pollid
- querystring = {"voices":"50000","votingType":"YES"}
- response = requests.request("POST", url, headers=headeregel, params=querystring)
- def expoll (pollid):
- print("createUser")
- print("\n")
- url = urlbasis+"api/polls/execute/"+pollid
- response = requests.request("POST", url, headers=headeregel)
- def id_generator(size=30, chars=string.ascii_uppercase + string.digits):
- return ''.join(random.choice(chars) for _ in range(size))
- def randomName(capitalize):
- bits=[]
- vowels="aeiou"
- letters="abcdefghijklmnopqrstuvwxyz"
- for ch in letters:
- for v in vowels:
- bits.append(ch+v)
- bits.remove("fu")
- bits.remove("hi")
- bits.remove("cu")
- bits.remove("co")
- bits.remove("mo")
- word=""
- rnd=len(bits)-1
- numOfBits=random.randint(2,3)
- for i in range(0,numOfBits):
- word=word+bits[random.randint(1,rnd)]
- word=word+letters[random.randrange(0,25)]
- if (capitalize==True):
- word=word.capitalize()
- return word
- def otcOrderSellNormalAuth(company1, company2, auth):
- print("otcOrderSell")
- print("\n")
- url = urlbasis+"api/securityorders/"
- querystring = {"owner":getSecurityAccount(company1),"securityIdentifier":getSecurityIdentifier(company1),"action":"SELL","type":"LIMIT","price":"1","numberOfShares":"50000","counterparty":getSecurityAccount(company2)}
- headers = {
- 'authorization': auth,
- 'x-authorization': partnerid,
- 'cache-control': "no-cache",
- }
- response = requests.request("POST", url, headers=headers, params=querystring)
- print(response.text)
- print("\n")
- querystring = {"owner":getSecurityAccount(company2),"securityIdentifier":getSecurityIdentifier(company1),"action":"BUY","type":"LIMIT","price":"1","numberOfShares":"50000","counterparty":getSecurityAccount(company1)}
- response = requests.request("POST", url, headers=headeregel, params=querystring)
- print(response.text)
- print("\n")
- def foundCompanysAndSell():
- i=0
- runid=id_generator()
- while i<100:
- username=runid+"ZZZ"+str(i)
- #username="Baby"
- #username=names.get_first_name()
- ag=username
- auth=username+":"+password
- auth= base64.encodestring(auth)
- auth="Basic "+auth
- auth=auth.replace('\n', '')
- createUser(username)
- createCompany(ag, username, auth)
- print(username)
- #time.sleep(2)
- employEgelAsCeo(getcompanyIDbyUser(username), auth)
- #input("emplox")
- otcOrderSellNormalAuth(ag, "1GK6VPBI1LJ4E2142IJIDS8Q00PNPVZZZ0", egelauth)
- #input("otc")
- time.sleep(2)
- intitiateLiquidationPoll(ag)
- #input("liquidation")
- lastpoll=getlastpoll()
- votepoll(lastpoll)
- #input("input")
- expoll(getlastpoll())
- #input("input")
- i=i+1
- print(username)
- #input()
- #i=0
- #while i<100:
- # username=runid+"ZZZ"+str(i)
- # #username=names.get_first_name()
- # #username="Baby"
- # ag=username
- # auth=username+":"+password
- # auth= base64.encodestring(auth)
- # auth="Basic "+auth
- # auth=auth.replace('\n', '')
- # #createUser(username)
- # #createCompany(ag, username)
- # print(username)
- # #employEgelAsCeo(getcompanyIDbyUser(username))
- # otcOrderSellNormalAuth(ag, "Bender", auth)
- # #time.sleep(2)
- # intitiateLiquidationPoll(ag)
- # lastpoll=getlastpoll()
- # votepoll(lastpoll)
- # expoll(getlastpoll())
- # i=i+1
- # print(username)
- def createAndSaveUsers(file):
- i=0
- usernames = [
- {'user' : '1', 'ag' : '1-AG'},
- {'user' : '1', 'ag' : '1-AG'},
- {'user' : '1', 'ag' : '1-AG'},
- {'user' : '1', 'ag' : '1-AG'},
- {'user' : '1', 'ag' : '1-AG'},
- {'user' : '1', 'ag' : '1-AG'},
- {'user' : '1', 'ag' : '1-AG'},
- {'user' : '1', 'ag' : '1-AG'},
- {'user' : '1', 'ag' : '1-AG'},
- {'user' : '1', 'ag' : '1-AG'}
- ]
- while i<10:
- username=names.get_last_name()
- ag=username+"-AG"
- auth=username+":"+password
- auth= base64.encodestring(auth)
- auth="Basic "+auth
- auth=auth.replace('\n', '')
- createUser(username)
- createCompany(ag, username, auth)
- usernames[i]['user']=username
- usernames[i]['ag']=ag
- i=i+1
- with open(file, 'w') as f: #writing
- json.dump(usernames, f)
- def loadUsers(file):
- data={}
- with open(file, 'r') as f:
- data = json.load(f)
- return data
- def deleteAllOrders(securityAccount, auth):
- url = urlbasis+"api/securityorders/"
- querystring = {"owner":securityAccount}
- headers = {
- 'authorization': auth,
- 'x-authorization': "7cd22613-45f3-436a-8f84-fd1f47ed42b8",
- 'cache-control': "no-cache",
- }
- response = requests.request("DELETE", url, headers=headers, params=querystring)
- def buySecurity(securityIdentifier, securityAccount, count, price, auth):
- url = urlbasis+"api/securityorders/"
- print(auth)
- querystring = {"owner":securityAccount,"securityIdentifier":securityIdentifier,"action":"BUY","type":"LIMIT","price":price,"numberOfShares":count,"counterparty":""}
- headers = {
- 'authorization': auth,
- 'x-authorization': partnerid,
- 'cache-control': "no-cache",
- }
- response = requests.request("POST", url, headers=headers, params=querystring)
- print(querystring)
- print(response.text)
- def sellSecurity(securityIdentifier, securityAccount, count, price, auth):
- url = urlbasis+"api/securityorders/"
- querystring = {"owner":securityAccount,"securityIdentifier":securityIdentifier,"action":"SELL","type":"LIMIT","price":price,"numberOfShares":count,"counterparty":""}
- headers = {
- 'authorization': auth,
- 'x-authorization': partnerid,
- 'cache-control': "no-cache",
- }
- response = requests.request("POST", url, headers=headers, params=querystring)
- print(response.text)
- def tradeSecurityOtc(securityIdentifier, securityAccount1, securityAccount2, count, price, auth, action):
- url = urlbasis+"api/securityorders/"
- querystring = {"owner":securityAccount1,"securityIdentifier":securityIdentifier,"action":action,"type":"LIMIT","price":price,"numberOfShares":count,"counterparty":securityAccount2}
- headers = {
- 'authorization': auth,
- 'x-authorization': partnerid,
- 'cache-control': "no-cache",
- }
- response = requests.request("POST", url, headers=headers, params=querystring)
- print(response.text)
- def authGen(username, password):
- print(username)
- print(password)
- auth=username+":"+password
- auth= base64.encodestring(auth)
- auth="Basic "+auth
- auth=auth.replace('\n', '')
- return auth
- def getAllListings():
- url = urlbasis+"api/listings/"
- response = requests.request("GET", url, headers=headeregel)
- listings= json.loads(response.text)
- return listings
- def getAllSpreads():
- url = urlbasis+"api/pricespreads/"
- response = requests.request("GET", url, headers=headeregel)
- listings= json.loads(response.text)
- return listings
- def getCommitedCash(companyname):
- url = urlbasis+"api/portfolios/"+getSecurityAccount(companyname)
- response = requests.request("GET", url, headers=headeregel)
- account= json.loads(response.text)
- cash=account['committedCash']
- return int(cash)
- def getCash(companyname):
- url = urlbasis+"api/portfolios/"+getSecurityAccount(companyname)
- response = requests.request("GET", url, headers=headeregel)
- account= json.loads(response.text)
- cash=account['cash']
- return int(cash)
- def getListingProfile(identifier):
- url = urlbasis+"api/listingprofiles/"+identifier
- response = requests.request("GET", url, headers=headeregel, timeout=50)
- parsed_json = json.loads(response.text)
- return parsed_json
- def getAllBonds():
- url = urlbasis+"api/bonds/"
- response = requests.request("GET", url, headers=headeregel, timeout=5000)
- parsed_json = json.loads(response.text)
- return parsed_json
- def buyBondsWithUsers(file):
- users=loadUsers(file)
- listings=getAllListings()
- cash=1
- j=0
- i=0
- while i<10:
- #input()
- username=users[i]['user']
- ag=users[i]['ag']
- auth=authGen(username)
- print(ag)
- securityAccount=getSecurityAccount(ag)
- print(getCommitedCash(ag))
- #input()
- volume=1100
- if getCash(ag)-getCommitedCash(ag)>volume :
- cash=1
- else:
- cash=0
- while cash==1:
- if getCash(ag)-getCommitedCash(ag)>volume :
- cash=1
- else:
- cash=0
- if j<len(listings) and listings[j]['type']=="BOND":
- print (listings[j]['securityIdentifier'])
- print ("found bond")
- profile=getListingProfile(listings[j]['securityIdentifier'])
- print(profile['systemBond'])
- sysbond=0
- if profile['systemBond'] is not None:
- print ("system Bond")
- sysbond=1
- if sysbond==0:
- print "test1"
- try :
- print(profile['bond']['faceValue'])
- faceValue=profile['bond']['faceValue']
- url = urlbasis+"api/securityorders/"
- percent=100
- countShares=volume/(faceValue*percent)
- countShares=int(countShares)
- #querystring = {"owner":securityAccount,"securityIdentifier":listings[j]['securityIdentifier'],"action":"BUY","type":"LIMIT","price":percent,"numberOfShares":countShares,"counterparty":''}
- querystring = {"owner":securityAccount,"securityIdentifier": "BOHDE7C3","action":"BUY","type":"LIMIT","price":110,"numberOfShares":10,"counterparty":''}
- print (querystring)
- headers = {
- 'authorization': auth,
- 'x-authorization': partnerid,
- 'cache-control': "no-cache",
- }
- response = requests.request("POST", url, headers=headers, params=querystring)
- print(response.text)
- if response.text is not NONE:
- input()
- print(securityAccount)
- #input()
- #input()
- except :
- pass
- if j>len(listings):
- i=10
- cash=0
- print (getCash(ag)-getCommitedCash(ag))
- j=j+1
- i=i+1
- def unCommittedCashOfUsers(file):
- users=loadUsers(file)
- listings=getAllListings()
- cash=1
- j=0
- i=0
- while i<10:
- username=users[i]['user']
- ag=users[i]['ag']
- auth=authGen(username)
- print(ag)
- print(getCash(ag))
- print(getCommitedCash(ag))
- i=i+1
- #print(getComittedCash("Bender"))
- def bondtest(file):
- file=file+".json"
- #createAndSaveUsers(file)
- buyBondsWithUsers(file)
- def issueBond(ag, numberOfBonds, faceValue, interestRate, maturityDate, auth):
- url = urlbasis+"api/bonds/"
- querystring = {"companyId":getCompanyIDbyName(ag),"numberOfBonds":numberOfBonds,"faceValue":faceValue,"interestRate":interestRate,"maturityDate":maturityDate}
- headers = {
- 'x-authorization': "7cd22613-45f3-436a-8f84-fd1f47ed42b8",
- 'authorization': auth,
- 'cache-control': "no-cache",
- }
- response = requests.request("POST", url, headers=headers, params=querystring)
- print(response.text)
- def getChats(auth):
- url = urlbasis+"api/chats"
- headers = {
- 'x-authorization': "7cd22613-45f3-436a-8f84-fd1f47ed42b8",
- 'authorization': auth,
- 'cache-control': "no-cache",
- }
- response = requests.request("GET", url, headers=headers)
- parsed_json = json.loads(response.text)
- #print(parsed_json.lentgh())
- return parsed_json
- def quitChat(auth, chatId):
- url = urlbasis+"api/chats/quitchat/"+chatId
- headers = {
- 'x-authorization': "7cd22613-45f3-436a-8f84-fd1f47ed42b8",
- 'authorization': auth,
- 'cache-control': "no-cache",
- 'postman-token': "cff2c724-ec2f-1a6e-4cd8-5b0bbbff3083"
- }
- response = requests.request("PUT", url, headers=headers)
- print (response)
- def quitAllChats(auth):
- chats=getChats(auth)
- l=0
- while l<len(chats):
- quitChat(auth, chats[i]['id'])
- l=l+1
- #bondtest("johnsbots.json")
- #unCommittedCashOfUsers("users2.json")
- #foundCompanysAndSell()
- #password="plBL7r4aiU"
- #getAllListings()
- #createAndSaveUsers("users2.json")
- #employEgelAsCeo(getcompanyIDbyUser(username))
- #auth=egelauth
- #comp="Bis%20zum%20naechsten%20reset"
- #otcOrderSell(comp, "Bender")
- #intitiateLiquidationPoll(comp)
- #getlastpoll()
- #print(getCompanyIDbyName(comp))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement