HASHNEST API Helper


SUBMITTED BY: Guest

DATE: March 9, 2015, 12:21 p.m.

FORMAT: Python

SIZE: 3.0 kB

HITS: 1693

  1. #DONATION 16RdQZ86NUWQbE6rM86JbxnnaCDcAKqa9
  2. ####HASHNET API HELPER####
  3. from urllib import urlencode
  4. import urllib2
  5. import time
  6. from datetime import datetime
  7. import hashlib
  8. import hmac
  9. import base64
  10. import json
  11. USERNAME=''
  12. ACCESS_KEY=''
  13. SECRET_KEY=''
  14. BASEURL='https://www.hashnest.com/api/'
  15. APIVERSION='v1'
  16. URL=BASEURL+APIVERSION+'/'
  17. def get_nonce():
  18. return int(time.time()*100000);
  19. def get_signature(nonce):
  20. global ACCESS_KEY,USERNAME,SECRET_KEY
  21. message = str(nonce) + USERNAME + ACCESS_KEY
  22. return hmac.new(SECRET_KEY, msg=message, digestmod=hashlib.sha256).hexdigest()
  23. def check_result(result):
  24. pass
  25. def get_verification():
  26. out={}
  27. global ACCESS_KEY
  28. out['access_key']=ACCESS_KEY
  29. out['nonce']=get_nonce()
  30. out['signature']=get_signature(out['nonce'])
  31. return out
  32. def build_query(req={}):
  33. req.update(get_verification())
  34. post_data = urlencode(req)
  35. headers = {}
  36. headers['User-Agent'] = 'ApeGoxApi'
  37. return (post_data, headers)
  38. def perform_query(url,data,headers={}):
  39. global URL
  40. url=URL+url
  41. count=0
  42. while True:
  43. if count==3: exit(0)
  44. count+=1
  45. try:
  46. req = urllib2.Request(url, data, headers)
  47. res = urllib2.urlopen(req,data)
  48. return json.load(res)
  49. except Exception,e:
  50. print 'ERROR:' + str(Exception) + '---' + str(e)+"\n"+url+"\n"+data
  51. time.sleep(10)
  52. def perform_private(url,req={}):
  53. data, headers = build_query(req)
  54. return perform_query(url,data,headers)
  55. def get_account_info():
  56. return perform_private('account');
  57. def get_account_balance():
  58. return perform_private('currency_accounts')
  59. def get_account_hashrate():
  60. return perform_private('hash_accounts')
  61. def get_orders(cmi):
  62. param={'currency_market_id':cmi}
  63. return perform_private('orders/active',param)
  64. def get_history(cmi,page=None,page_amount=None):
  65. param={'currency_market_id':cmi}
  66. if page is not None:param['page']=page
  67. if page_amount is not None:param['page_per_amount']=page_amount
  68. return perform_private('orders/history',param)
  69. def create_order(cmi,amount,ppc,category):
  70. param={'currency_market_id':cmi}
  71. param['amount']=amount
  72. param['ppc']=ppc
  73. param['category']=category
  74. return perform_private('orders')
  75. def cancel_order(order_id):
  76. param={'order_id':order_id}
  77. return perform_private('orders/revoke')
  78. def cancell_all_orders(cmi):
  79. param={'currency_market_id':cmi}
  80. return perform_private('orders/quick_revoke',param)
  81. def get_opened_markets():
  82. return perform_private('currency_markets')
  83. def get_currency_orders(cmi,category):
  84. param={'currency_market_id':cmi}
  85. param['category']=category
  86. return perform_private('currency_markets/order_history',param)

comments powered by Disqus