Bitcoin Forum
June 08, 2024, 11:55:13 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Bittrex API V3 via Python  (Read 99 times)
neuri (OP)
Newbie
*
Offline Offline

Activity: 8
Merit: 2


View Profile
December 28, 2020, 09:45:16 PM
Merited by hugeblack (2)
 #1

Hello,

i'm trying to use the Bittrex WEB API V3 via a simple Python Script for placing Orders or getting the actual User Balance without !!! using any Bittrex spec. Library.
Unfortunately i have no Chance to have success with this.

I'm using this method for the Finance API without any Problems...

Code:
def getBalanceBN(curr):
    import requests, time, hmac, hashlib, json, base64, urllib
    from urllib.parse import urlencode

    BASE_URL = 'https://api.binance.com'
    url_path = '/api/v3/account'


    payload = {
    }

    query_string = urlencode(payload, True)
    if query_string:
        query_string = "{}&timestamp={}".format(query_string, int(time.time() * 1000))
    else:
        query_string = 'timestamp={}'.format(int(time.time() * 1000))

    hashstr = hmac.new(bin_secret.encode('utf-8'), query_string.encode('utf-8'), hashlib.sha256).hexdigest()
    url = BASE_URL + url_path + '?' + query_string + '&signature=' + hashstr

    params = {'url': url, 'params': {}}

    session = requests.Session()
    session.headers.update({
        'Content-Type': 'application/json;charset=utf-8',
        'X-MBX-APIKEY': bin_key
    })

    try:
        r = r = session.get(**params)
        balance_array = (json.loads(r.text)['balances'])
        #print(r.text)

        for i in range(len(balance_array)):
            if balance_array[i]['asset'] == curr:
                Balance = balance_array[i]['free']
                log('Binance Balance for ' + curr + ' = ' + str(Balance))
                return (Balance)

        if r.status_code != 200:
            print("API Error Code " + str(r.status_code))
            log("Error querying Binane API for User Balance API Error Code " + str(r.status_code))
            log(r.text)
            return ('error')

        return(0)

    except requests.ConnectionError:
        log("Error querying Binane API for getting User Balance " )
        return ('error')

I'm not able to find a simple example script where i can see how i have to change this for the Bittrex Authentication
Does anyone have an example Python Code who show's me how this would work for BITTREX (Place Orders or get Balance...)

Thank a lot

Neuri
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!