Cryptopia API - LabMazurokCom/Blockchain GitHub Wiki

Intro

Website: https://www.cryptopia.co.nz/

Public API documentation: https://www.cryptopia.co.nz/Forum/Thread/255

Private API documentation: https://www.cryptopia.co.nz/Forum/Thread/256

Rate limits: 1000 req/minute, 1000000 req/day for private API

Fee used in bot: 0.2% (maker and taker, found here: https://www.cryptopia.co.nz/api/GetTradePairs)

Order book

https://www.cryptopia.co.nz/api/GetMarketOrders/BTC_USDT/50

Response:

{
    "Success": true,
    "Message": null,
    "Data": {
        "Buy": [{
            "TradePairId": 4909,
            "Label": "BTC/USDT",
            "Price": 8100.00000000,
            "Volume": 1.02904337,
            "Total": 8335.25129700
        }, {
            "TradePairId": 4909,
            "Label": "BTC/USDT",
            "Price": 8080.00000000,
            "Volume": 0.02691900,
            "Total": 217.50552000
        }],
        "Sell": [{
            "TradePairId": 4909,
            "Label": "BTC/USDT",
            "Price": 8130.00000000,
            "Volume": 0.00187624,
            "Total": 15.25383120
        }, {
            "TradePairId": 4909,
            "Label": "BTC/USDT",
            "Price": 8139.99999999,
            "Volume": 0.00021472,
            "Total": 1.74782080
        }]
    },
    "Error": null
}

Ticker

https://www.cryptopia.co.nz/api/GetMarket/BTC_USDT

Param: hours (optional, default: 24)

Response

{
    "Success": true,
    "Message": null,
    "Data": {
        "TradePairId": 4909,
        "Label": "BTC/USDT",
        "AskPrice": 8130.00000000,
        "BidPrice": 8100.00000000,
        "Low": 7955.77155422,
        "High": 8374.23054810,
        "Volume": 75.81483883,
        "LastPrice": 8125.93500000,
        "BuyVolume": 1310252836.73423267,
        "SellVolume": 52.83036486,
        "Change": -2.45,
        "Open": 8330.00000000,
        "Close": 8125.93500000,
        "BaseVolume": 615071.16347120,
        "BuyBaseVolume": 479268.17590728,
        "SellBaseVolume": 1961457.27535369
    },
    "Error": null
}

Order types

Trade order

User can set price and amount. Such order may be partially executed. Similar to limit orders at other exchanges.

Currency limits

https://www.cryptopia.co.nz/api/GetCurrencies

API request example

#!/usr/bin/python

import time
import hmac
import urllib.parse
import requests
import hashlib
import base64
import sys
import json

API_KEY = 'api_key'
API_SECRET = 'api_secret'


def api_query(method, req = None):
 if not req:
         req = {}
 #print "def api_query( method = " + method + ", req = " + str( req ) + " ):"
 #time.sleep(1)
 public_set = set(["GetCurrencies", "GetTradePairs", "GetMarkets", "GetMarket", "GetMarketHistory", "GetMarketOrders"])
 private_set = set(["GetBalance", "GetDepositAddress", "GetOpenOrders", "GetTradeHistory", "GetTransactions", "SubmitTrade", "CancelTrade", "SubmitTip"])
 if method in public_set:
         url = "https://www.cryptopia.co.nz/api/" + method
         if req:
             for param in req:
                 url += '/' + str(param)
         r = requests.get(url)
 elif method in private_set:
         url = "https://www.cryptopia.co.nz/Api/" + method
         nonce = str(int(time.time()))
         post_data = json.dumps(req).encode('utf-8')
         m = hashlib.md5()
         #m.update(bytes(post_data, encoding='utf-8'))
         m.update(post_data)
         requestContentBase64String = base64.b64encode(m.digest()).decode('utf-8')
         signature = API_KEY + "POST" + urllib.parse.quote_plus(url).lower() + nonce + requestContentBase64String
         hmacsignature = base64.b64encode(hmac.new(base64.b64decode(API_SECRET), signature.encode('utf-8'), hashlib.sha256).digest())
         header_value = "amx " + API_KEY + ":" + hmacsignature.decode('utf-8') + ":" + nonce
         headers = {
             'Authorization': header_value,
             'Content-Type':'application/json; charset=utf-8'
         }
         r = requests.post( url, data = post_data, headers = headers )
 response = r.text
 print("Response: " + response)
 return response.replace("false","False").replace("true","True").replace('":null','":None' )


# Public:
# +
# print api_query("GetCurrencies")

# +
print(api_query("GetMarket", [100, 6]))
# {"Success":True,"Message":None,"Data":{"TradePairId":100,"Label":"DOT/BTC","AskPrice":0.00000020,"BidPrice":0.00000019,"Low":0.00000019,"High":0.00000021,"Volume":1263556.65136394,"LastPrice":0.00000019,"LastVolume":774.83684404,"BuyVolume":50896673.08961847,"SellVolume":33046510.52562918,"Change":0.0},"Error":None}

# Private:
print(api_query("GetBalance"))

# +
# print api_query("GetBalance", {'CurrencyId':2} )