we responded you, but we cannot help with every programming problem everyone. Code examples shown in API documentation work. The whole authenticatation simply comes to use DgtmarketApiAuth class set with proper credentials (API keys received from https://dgtmarket.com/api/public/token/ endpoint). Below you have complete working example in which you 1) obtain API keys, 2) initialize authentication object used by requests library with given API keys and 3) call the endpoint responsing with wallets summary:
Kod: Zaznacz cały
import hmac
import hashlib
import time
import requests
from requests.auth import AuthBase
r = requests.post('https://dgtmarket.com/api/public/token/',
data={'username': 'your_username_lowercase', 'password': 'your_password'},
verify=False
)
r = r.json()
key, secret = r['key'], r['secret']
class DgtmarketApiAuth(AuthBase):
def __init__(self, key, secret):
self.key = key
self.secret = secret
def __call__(self, request):
timestamp = str(int(time.time()))
message = timestamp + request.method + request.path_url + (request.body or '')
signature = hmac.new(str(self.secret), message, hashlib.sha256).hexdigest()
request.headers.update({
'ACCESS-SIGN': signature,
'ACCESS-TIMESTAMP': timestamp,
'ACCESS-KEY': self.key,
})
return request
# create DgtmarketApiAuth callable instance
auth = DgtmarketApiAuth(key, secret)
# example private API request using auth. Using verify=False to simplify.
r = requests.get('https://dgtmarket.com/api/private/wallets/', auth=auth, verify=False)
print(r.json())
Best regards!
PS. This example code is for Python 2.7. You also have to take into account that generating new API keys is throttled.