Advertisement
Guest User

Untitled

a guest
Jul 11th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.26 KB | None | 0 0
  1. import requests
  2. import base64
  3. import json
  4. import os
  5. egelauth="Basic XXXXXXXXXXXX"
  6. egelaccountid="a63a36e4-1f7a-434a-983c-0b916bc9ecf1" #stable
  7. i=0
  8. password="t"
  9. urlbasis="http://stable.alpha-trader.com/"
  10. partnerid="XXXXXX" #stable
  11. headeregel={
  12. 'authorization': egelauth,
  13. 'x-authorization': partnerid,
  14. 'cache-control': "no-cache",
  15. }
  16. auth=""
  17.  
  18. def createuser(username):
  19. url = urlbasis+"user/register"
  20. mail=username+"@gmx.de"
  21. companyname="comp"+username
  22. querystring = {"username":username,"emailAddress":mail,"password":password}
  23. headers = {
  24. 'x-authorization': partnerid,
  25. 'cache-control': "no-cache",
  26. }
  27. response = requests.request("POST", url, headers=headers, params=querystring)
  28.  
  29. def createcompany(companyname, username):
  30. url = urlbasis+"api/companies/"
  31. querystring = {"name":companyname,"cashDeposit":"50000"}
  32. headers = {
  33. 'authorization': auth,
  34. 'x-authorization': partnerid,
  35. 'cache-control': "no-cache",
  36. }
  37. response = requests.request("POST", url, headers=headers, params=querystring)
  38. print(response.text)
  39.  
  40. def getcompanyidbyuser(username):
  41. url = urlbasis+"api/companies/ceo/username/"+username
  42. response = requests.request("GET", url, headers=headeregel)
  43. parsed_json = json.loads(response.text)
  44. companyid=parsed_json[0]['id']
  45. return companyid
  46.  
  47. def employegelasceo(companyid):
  48. url = urlbasis+"api/polls/employceo"
  49. querystring = {"companyId":companyid,"dailyWage":"150"}
  50. response = requests.request("POST", url, headers=headeregel, params=querystring)
  51. url = urlbasis+"api/polls/"
  52. headers = {
  53. 'authorization': auth,
  54. 'x-authorization': partnerid,
  55. 'cache-control': "no-cache",
  56. }
  57.  
  58. response = requests.request("GET", url, headers=headers)
  59. parsed_json = json.loads(response.text)
  60. pollid=parsed_json[0]['id']
  61. print(pollid)
  62.  
  63. url = urlbasis+"api/polls/"+pollid
  64.  
  65. querystring = {"voices":"50000","votingType":"YES"}
  66. headers = {
  67. 'authorization': auth,
  68. 'x-authorization': partnerid,
  69. 'cache-control': "no-cache",
  70. }
  71. response = requests.request("POST", url, headers=headers, params=querystring)
  72. #print(response.text)
  73.  
  74. url = urlbasis+"api/polls/execute/"+pollid
  75. response = requests.request("POST", url, headers=headeregel)
  76.  
  77. def getsecurityidentifier(companyname):
  78. url = urlbasis+"api/search/companies/"+companyname
  79.  
  80. headers = {
  81. 'authorization': egelauth,
  82. 'x-authorization': partnerid,
  83. 'cache-control': "no-cache",
  84. }
  85. response = requests.request("GET", url, headers=headers)
  86. parsed_json = json.loads(response.text)
  87. securityidentifier=parsed_json[0]['securityIdentifier']
  88. return securityidentifier
  89.  
  90. def getsecurityaccount(companyname):
  91. url = urlbasis+"api/search/companies/"+companyname
  92.  
  93. headers = {
  94. 'authorization': egelauth,
  95. 'x-authorization': partnerid,
  96. 'cache-control': "no-cache",
  97. }
  98. response = requests.request("GET", url, headers=headers)
  99. parsed_json = json.loads(response.text)
  100. securityaccount=parsed_json[0]['securitiesAccountId']
  101. return securityaccount
  102.  
  103. def getcompanyidbyname(companyname):
  104. url = urlbasis+"api/search/companies/"+companyname
  105.  
  106. headers = {
  107. 'authorization': egelauth,
  108. 'x-authorization': partnerid,
  109. 'cache-control': "no-cache",
  110. }
  111. response = requests.request("GET", url, headers=headers)
  112. parsed_json = json.loads(response.text)
  113. securityaccount=parsed_json[0]['id']
  114. return securityaccount
  115.  
  116. def otcordersell(company1, company2):
  117. url = urlbasis+"api/securityorders/"
  118. querystring = {"owner":getsecurityaccount(company1),"securityIdentifier":getsecurityidentifier(company1),"action":"SELL","type":"LIMIT","price":"1","numberOfShares":"50000","counterparty":getsecurityaccount(company2)}
  119. headers = {
  120. 'authorization': egelauth,
  121. 'x-authorization': partnerid,
  122. 'cache-control': "no-cache",
  123.  
  124. }
  125. response = requests.request("POST", url, headers=headers, params=querystring)
  126. querystring = {"owner":getsecurityaccount(company2),"securityIdentifier":getsecurityidentifier(company1),"action":"BUY","type":"LIMIT","price":"1","numberOfShares":"50000","counterparty":getsecurityaccount(company1)}
  127. response = requests.request("POST", url, headers=headers, params=querystring)
  128.  
  129. def intitiateliquidationpoll(company):
  130. url = urlbasis+"api/polls/liquidation"
  131. querystring = {"companyId":getcompanyidbyname(company)}
  132. headers = {
  133. 'authorization': egelauth,
  134. 'x-authorization': partnerid,
  135. 'cache-control': "no-cache",
  136. }
  137. response = requests.request("POST", url, headers=headers, params=querystring)
  138.  
  139. #def acceptliquidationpoll(company)
  140. def sellowncompany(company, auth):
  141. url = urlbasis+"api/securityorders/"
  142. querystring = {"owner":getsecurityaccount(company),"securityIdentifier":getsecurityidentifier(company),"action":"SELL","type":"LIMIT","price":"1","numberOfShares":"50000","counterparty":""}
  143. headers = {
  144. 'authorization': auth,
  145. 'x-authorization': partnerid,
  146. 'cache-control': "no-cache",
  147.  
  148. }
  149. response = requests.request("POST", url, headers=headers, params=querystring)
  150.  
  151. def getlastpoll():
  152. url = urlbasis+"api/initiatedpolls/"
  153. response = requests.request("GET", url, headers=headeregel)
  154. parsed_json = json.loads(response.text)
  155. #print(parsed_json.lentgh())
  156. pollid=parsed_json[-1]['id']
  157. return pollid
  158.  
  159. def votepoll (pollid):
  160. url = urlbasis+"api/polls/"+pollid
  161. querystring = {"voices":"50000","votingType":"YES"}
  162. response = requests.request("POST", url, headers=headeregel, params=querystring)
  163.  
  164. def expoll (pollid):
  165. url = urlbasis+"api/polls/execute/"+pollid
  166. response = requests.request("POST", url, headers=headeregel)
  167.  
  168. i=0
  169. while i<1:
  170. username="12345678910"+str(i)
  171. ag=username
  172. auth=username+":"+password
  173. auth= base64.encodestring(auth)
  174. auth="Basic "+auth
  175. auth=auth.replace('\n', '')
  176. createuser(username)
  177. createcompany(ag, username)
  178. print(username)
  179. employegelasceo(getcompanyidbyuser(username))
  180. otcordersell(ag, "Bender")
  181. intitiateliquidationpoll(ag)
  182. lastpoll=getlastpoll()
  183. votepoll(lastpoll)
  184. expoll(getlastpoll())
  185. i=i+1
  186. print(username)
  187.  
  188.  
  189.  
  190. #employegelasceo(getcompanyidbyuser(username))
  191. #auth=egelauth
  192. #comp="Bis%20zum%20naechsten%20reset"
  193. #otcordersell(comp, "Bender")
  194. #intitiateliquidationpoll(comp)
  195. #getlastpoll()
  196. #print(getcompanyidbyname(comp))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement