Advertisement
Guest User

Untitled

a guest
Jul 16th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. from functions import *
  2.  
  3. def sellStocks(auth, ag):
  4. securityAccount=getSecurityAccount(ag)
  5. portfolio=getPortfolio(securityAccount)
  6. n=0
  7. while n<len(portfolio['positions']):
  8. securityIdentifier=portfolio['positions'][i]['securityIdentifier']
  9. askPrice=portfolio['positions'][i]['currentAskPrice']
  10. print(securityIdentifier)
  11. sell=0
  12. price=0
  13. if portfolio['positions'][i]['currentAskPrice'] is None and securityIdentifier.startswith("ST"):
  14. if portfolio['positions'][i]['currentBidPrice'] is None:
  15. price=portfolio['positions'][i]['lastPrice']['value']
  16. print("last")
  17. print(price)
  18. else:
  19. price=portfolio['positions'][i]['currentBidPrice']*0.99
  20. price=str(price)
  21. print("bid")
  22. sell=1
  23. elif securityIdentifier.startswith("ST"):
  24. price=portfolio['positions'][i]['currentAskPrice']
  25. price=float(price)
  26. count=portfolio['positions'][i]['numberOfShares']
  27. price=round(price, 2)
  28. if sell==1:
  29. sellSecurity(securityIdentifier, securityAccount, count, price, auth)
  30. output="SELL "+str(count)+" "+str(securityIdentifier)+" with "+str(securityAccount)+" for "+str(price)
  31. print(output)
  32. n=n+1
  33.  
  34.  
  35. allBonds=getAllBonds()
  36. i=0
  37. usernames=loadUsers(bondbuyerfile)
  38. password="plBL7r4aiU"
  39. while i<len(allBonds):
  40. cash=getCash(allBonds[i]['issuer']['listing']['name'])
  41. faceValue=allBonds[i]['faceValue']
  42. volume=allBonds[i]['volume']
  43. timestamp = int(time.time())
  44. maturityDate=int(allBonds[i]['maturityDate']/1000)
  45. securityIdentifier=allBonds[i]['listing']['securityIdentifier']
  46. if cash<volume*faceValue and maturityDate-timestamp<90000:
  47. a=randint(0,2)
  48. username=usernames[a]['user']
  49. ag=usernames[a]['ag']
  50. auth=authGen(username, password)
  51. if getCash(ag)-getCommitedCash(ag)<10000:
  52. deleteAllOrders(getSecurityAccount(ag), auth)
  53. volume=getCash(ag)-getCommitedCash(ag)
  54. price=100
  55. if allBonds[i]['priceSpread']['askPrice'] is None:
  56. price=100+allBonds[i]['interestRate']
  57. else:
  58. price=allBonds[i]['priceSpread']['askPrice']
  59. count=volume/(faceValue*price)
  60. count=count*100
  61. count=int(count)
  62. price=round(price, 4)
  63. buySecurity(securityIdentifier, getSecurityAccount(ag), count, price, auth)
  64. sellStocks(auth, ag)
  65. i=i+1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement