Bitcoin Forum
May 09, 2024, 06:15:28 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: BitBay 3.0 API - problem z POST request  (Read 39 times)
wrzadkos (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
July 18, 2018, 02:51:46 PM
 #1

Witam,

Na wstepie.
Mam problem z API request ktore wymaga podania parametrow (np. placing orders). Problem tyczy sie nowego API 3.0 na gieldzie bitbay.net.
Przepisuje dzialajacy kod z API 2.0 do API 3.0. Trzymam sie oficjalnej dokumentacji https://docs.bitbay.net/v3.1.0/docs

Moj kod w python3.6

    import requests
    import json
    import uuid
    import time
    import hashlib
    import hmac

    credentials = {'priv': 'xxx', 'pub': 'xxx'}
    payload = {
            'url':'https://api.bitbay.net/rest/trading/offer/BTC-PLN',
            'params':{
                    'mode':'limit',
                    'offerType':'Sell',
                    'amount':'0.01',
                    'rate':'30000.0',
                    }
            }
    timestamp =  str(int(time.time()))
    string_data = credentials ['pub'] + timestamp + str(payload['params'])
    sign = hmac.new(
            credentials['priv'].encode(),
            string_data.encode(),
            hashlib.sha512
            )   
    payload['headers'] = {
            'API-Hash':sign.hexdigest(),
            'API-Key': credentials['pub'],
            'Request-Timestamp': timestamp,
            'Operation-Id': str(uuid.uuid4())}
    server_response = requests.post(**payload).json()


Problem
Powyzszy kod zwraca blad: INVALID_HASH_SIGNATURE
Zaznaczam ze podobny kod tylko bez parametrow, ktory korzysta z requests.get() dziala poprawnie (np. balance query), wiec domyslam sie ze problem tkwi w tym jak przekazuje parametry. Kontaktowalem sie juz z supportem z bitbay ale sa malo pomocni, mam wrazenie ze przydzielili do mnie jakiegos praktykanta...

Czy ktos bylby w stanie mi w tym pomoc?

Pozdrawiam,
Wojtek

1715235328
Hero Member
*
Offline Offline

Posts: 1715235328

View Profile Personal Message (Offline)

Ignore
1715235328
Reply with quote  #2

1715235328
Report to moderator
Bitcoin addresses contain a checksum, so it is very unlikely that mistyping an address will cause you to lose money.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715235328
Hero Member
*
Offline Offline

Posts: 1715235328

View Profile Personal Message (Offline)

Ignore
1715235328
Reply with quote  #2

1715235328
Report to moderator
1715235328
Hero Member
*
Offline Offline

Posts: 1715235328

View Profile Personal Message (Offline)

Ignore
1715235328
Reply with quote  #2

1715235328
Report to moderator
wrzadkos (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
July 19, 2018, 09:19:48 AM
 #2

Problem rozwiazany.

W powyzszym kodzie sa dwa bledy.
1. dane do requesta nalezy podac jako "data" a nie "params"
2. "data" nalezy podac jako string (albo json.dumps()) a nie dict
3. nie jest to obowiazkowe ale powinno sie rowniez okreslic parametry 'postOnly', 'hidden' oraz 'fillOrKill'
4. rowniez nie obowiazkowo, ale w nowej dokumentacji znalazlem ze nalezy rowniez podac header 'Content-Type' - nie wiem po co to jest, dziala bez tego

Poprawiony, dzialajacy kod:

Quote
    import requests
    import json
    import uuid
    import time
    import hashlib
    import hmac
   
    credentials = {'priv': 'xxx', 'pub': 'xxx'}
    payload = {
            'url':'https://api.bitbay.net/rest/trading/offer/BTC-PLN',
            'data':str(
                    {
                            'amount':0.01,
                            'rate':30000.0,
                            'offerType':'sell',
                            'mode':'limit',
                            'postOnly':False,
                            'hidden':False,
                            'fillOrKill':False,
                            }
                    )
            }

    timestamp =  str(int(time.time()))
    string_data = credentials['pub'] + timestamp + payload['data']
    sign = hmac.new(
            credentials['priv'].encode(),
            string_data.encode(),
            hashlib.sha512
            )   
    payload['headers'] = {
            'API-Hash':sign.hexdigest(),
            'API-Key': credentials['pub'],
            'Request-Timestamp': timestamp,
            'operation-id': str(uuid.uuid4()),
            'Content-Type':'application/json',
            }
    raw_response = requests.post(**payload).json()

Pozatym bitbay udostepnil wzbogacona dokumentacje ktora jest o wiele bardziej kompletna
https://docs.bitbay.net/v3.2.1/

Pozdrawiam,
Wojtek;)
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!