Author

Topic: Nova Exchange API (Read 97 times)

full member
Activity: 241
Merit: 107
April 05, 2019, 02:00:30 AM
#1
Hi,

I am looking for a PHP example to make use of the Nova Exchange API.

Each request send to the server need to be signed, the example provided is for Python;

Code:
#!/usr/bin/python

import time
import hmac
import hashlib
import base64
import requests

API_KEY = "YOUR_API_KEY"
API_SECRET = "YOUR_API_SECRET"

public_set = set([ "markets", "market/info", "market/orderhistory", "market/openorders" ]) # optional
private_set = set([ "getbalances", "getbalance", "getdeposits", "getwithdrawals", "getnewdepositaddress", "getdepositaddress", "myopenorders", "myopenorders_market", "cancelorder", "withdraw", "trade", "tradehistory", "getdeposithistory", "getwithdrawalhistory", "walletstatus" ])

url = "https://novaexchange.com/remote/v2/"

def api_query( method, req = None ):
        url = "https://novaexchange.com/remote/v2/"
        if not req:
                req = {}
        if method.split('/')[0][0:6] == 'market':
                r = requests.get( url + method + '/', timeout = 60 )
        elif method.split('/')[0] in private_set:
                url += 'private/' + method + '/' + '?nonce=' + str( int( time.time() ) )
                req["apikey"] = API_KEY
                req["signature"] = base64.b64encode( hmac.new( API_SECRET, msg = url, digestmod = hashlib.sha512 ).digest() )
                headers = {'content-type': 'application/x-www-form-urlencoded'}
                r = requests.post( url, data = req, headers = headers, timeout = 60 )
        return r.text

# Eample usage:

# Public:
# print api_query( "markets" )
print api_query( "market/orderhistory/" + "LTC_DOGE" )

Any assistance appreciated.

H
Jump to: