Advertisement
den4ik2003

Untitled

Nov 1st, 2024
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.46 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 form_signed_url(url, params):
  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.        
  45.     signature_str = hmac.new(
  46.         secret_key.encode('utf-8'),
  47.         msg=signature_str[:-1].encode('utf-8'),
  48.         digestmod=hashlib.sha256
  49.     ).hexdigest().capitalize()
  50.  
  51.    
  52.     body = copy.deepcopy(params)
  53.     body['api_key'] = api_key
  54.     sorted_body = {key: body[key] for key in sorted(body.keys())}
  55.  
  56.     url += '?'
  57.     for key, value in sorted_body.items():
  58.         url += (key + '=' + value + '&')
  59.     url += ('sign=' + signature_str)
  60.  
  61.     return url
  62.  
  63.  
  64. def get_balance(params, token):
  65.     url = form_signed_url('https://api.biconomy.com/api/v2/private/user', params)
  66.  
  67.     content = json.loads(requests.post(url).content)
  68.     if content['code'] == 0:
  69.         for coin in content['result'].keys():
  70.             if coin == token:
  71.                 return content['result'][coin]
  72.     else:
  73.         print(content['message'])
  74.  
  75. params = {}
  76. get_balance(params, 'USDT')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement