Advertisement
den4ik2003

Untitled

Nov 1st, 2024
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. import requests
  2. import json
  3. import copy
  4. import hashlib
  5. import hmac
  6.  
  7. api_key = '7bf3c1fd-f3a3-4412-b7fb-148f6bbcd0fd'
  8. secret_key = 'e11f47c3-3237-426c-9d9f-dbae226cae5d'
  9.  
  10. def get_best_book(symbol):
  11. response = requests.get(f'https://api.biconomy.com/api/v1/depth?symbol={symbol}')
  12. if response.status_code != 200:
  13. return (0, 0, returnresponse.status_code)
  14. else:
  15. content = json.loads(response.content)
  16. if len(content['asks']) > 0 and len(content['bids']) > 0:
  17. return (content['bids'][0][0], content['asks'][0][0], 200)
  18. elif len(content['asks']) > 0:
  19. return (0, content['asks'][0][0], 200)
  20. elif len(content['bids']) > 0:
  21. return (content['bids'][0][0], 0, 200)
  22. else:
  23. return (0, 0, 200)
  24.  
  25.  
  26. def get_info(symbol):
  27. base = symbol[0:symbol.find('_')]
  28. quote = symbol[0:symbol.find('_') + 1:]
  29. response = requests.get('https://api.biconomy.com/api/v1/exchangeInfo')
  30. if response.status_code == 200:
  31. for element in json.loads(response.content):
  32. if element['baseAsset'] == base and element['quoteAsset']:
  33. return element
  34.  
  35.  
  36. def get_balance(params, token):
  37. signature_dict = copy.deepcopy(params)
  38. signature_dict['api_key'] = api_key
  39. signature_dict['secret_key'] = secret_key
  40. sorted_signature_dict = {key: signature_dict[key] for key in sorted(signature_dict.keys())}
  41. signature_str = ''
  42. for key, val in sorted_signature_dict.items():
  43. signature_str += (key + '=' + val + '&')
  44. signature_str = signature_str[:-1]
  45.  
  46. print(signature_str)
  47.  
  48. signature_str = hmac.new(
  49. secret_key.encode('utf-8'),
  50. msg=signature_str.encode('utf-8'),
  51. digestmod=hashlib.sha256
  52. ).hexdigest().capitalize()
  53.  
  54. print(signature_str)
  55.  
  56. body = copy.deepcopy(params)
  57. body['api_key'] = api_key
  58. body['sign'] = signature_str
  59. sorted_body = {key: body[key] for key in sorted(body.keys())}
  60. url = 'https://api.biconomy.com/api/v2/private/user?'
  61. for key, value in sorted_body.items():
  62. url += (key + '=' + value + '&')
  63.  
  64. content = json.loads(requests.post(url[:-1]).content)
  65. if content['code'] == 0:
  66. for coin in content['result'].keys():
  67. if coin == token:
  68. return content['result'][coin]
  69. else:
  70. print(content['message'])
  71.  
  72. params = {}
  73. get_balance(params, 'USDT')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement