hashnest api v1.1


SUBMITTED BY: Guest

DATE: March 10, 2015, 1:41 a.m.

FORMAT: Python

SIZE: 3.1 kB

HITS: 1720

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

comments powered by Disqus