Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- import copy
- import hashlib
- import hmac
- api_key = '7bf3c1fd-f3a3-4412-b7fb-148f6bbcd0fd'
- secret_key = 'e11f47c3-3237-426c-9d9f-dbae226cae5d'
- def get_best_book(symbol):
- response = requests.get(f'https://api.biconomy.com/api/v1/depth?symbol={symbol}')
- if response.status_code != 200:
- return (0, 0, returnresponse.status_code)
- else:
- content = json.loads(response.content)
- if len(content['asks']) > 0 and len(content['bids']) > 0:
- return (content['bids'][0][0], content['asks'][0][0], 200)
- elif len(content['asks']) > 0:
- return (0, content['asks'][0][0], 200)
- elif len(content['bids']) > 0:
- return (content['bids'][0][0], 0, 200)
- else:
- return (0, 0, 200)
- def get_info(symbol):
- base = symbol[0:symbol.find('_')]
- quote = symbol[0:symbol.find('_') + 1:]
- response = requests.get('https://api.biconomy.com/api/v1/exchangeInfo')
- if response.status_code == 200:
- for element in json.loads(response.content):
- if element['baseAsset'] == base and element['quoteAsset']:
- return element
- def form_signed_url(url, params):
- signature_dict = copy.deepcopy(params)
- signature_dict['api_key'] = api_key
- signature_dict['secret_key'] = secret_key
- sorted_signature_dict = {key: signature_dict[key] for key in sorted(signature_dict.keys())}
- signature_str = ''
- for key, val in sorted_signature_dict.items():
- signature_str += (key + '=' + val + '&')
- signature_str = hmac.new(
- secret_key.encode('utf-8'),
- msg=signature_str[:-1].encode('utf-8'),
- digestmod=hashlib.sha256
- ).hexdigest().capitalize()
- body = copy.deepcopy(params)
- body['api_key'] = api_key
- sorted_body = {key: body[key] for key in sorted(body.keys())}
- url += '?'
- for key, value in sorted_body.items():
- url += (key + '=' + value + '&')
- url += ('sign=' + signature_str)
- return url
- def get_balance(params, token):
- url = form_signed_url('https://api.biconomy.com/api/v2/private/user', params)
- content = json.loads(requests.post(url).content)
- if content['code'] == 0:
- for coin in content['result'].keys():
- if coin == token:
- return content['result'][coin]
- else:
- print(content['message'])
- params = {}
- get_balance(params, 'USDT')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement