Package: zerocap-api-new-test
zerocap-api-new-testJump restapiJump websocketIntroduction

Websocket sdk dependency
pip install websocket>=0.2.1
pip install websocket-client>=1.6.1

sdk install
pip install zerocap-api-new-testrestapifrom zerocap_api_new_test import ZerocapRestClient
import uuid
import time
import hmac
import hashlib

# API key and secret are required, please contact zerocap to register.

api_key = "***" 
api_secret = "***"
client = ZerocapRestClient(api_key, api_secret, env='uat')

timestamp = int(time.time())
signature = hmac.new(api_secret.encode("utf-8"), str(timestamp).encode("utf-8"), hashlib.sha256).hexdigest()1. Create an orderresult = client.create_order(
                    symbol='USDT/AUD', 
                    side='buy', 
                    type='limit', 
                    amount='100', 
                    price='1000', 
                    coinroutes_customer_id=5,
                    )Request parameters:Parameterrequireddata typedescribeValue rangesymboltruestringInstrumentUSDT/AUDsidetruestringSidebuy selltypetruestringTypelimitamounttruestringQuantitypricetruestringPricecoinroutes_customer_idfalseintcoinroutes_customer_idclient_order_idfalsestringclient_order_idRequest parameters: examples (cannot be used directly, you need to replace your own parameters)headers = {
    'api-key': api_key,
    'signature': signature,
    'Content-Type': 'application/json',
    'timestamp': str(timestamp),
}

data = 
{
    "symbol": "USDT/AUD",
    "side": "buy",
    "type": "limit",
    "amount": "1000",
    "price": "1000",
    "coinroutes_customer_id": 5,
}Response data:Parameterrequireddata typedescribeValue rangeidtruestringTransaction IDtimestamptruelongTimelastTradeTimestamptruelongTimestatustruestringStatustypetruestringTypetimeInForcetruestringtimeInForcesidetruestringSidepricetruefloatPriceaveragetruefloataverageamounttruefloatQuantityfilledtruefloatfilledremainingtruefloatremainingcosttruefloatcostfeetruefloatfeeerror_messagetruestringerror_messagetradestruestringtradesclient_order_idtruestringclient_order_idResponse example:{
	"id": "d8dabfbd-e541-4262-b6c2-9f841ef220f6",
	"timestamp": 1692346145000,
	"last_trade_timestamp": 1692346145000,
	"status": "closed",
	"symbol": "USDT/AUD",
	"type": "limit",
	"time_in_force": "FOK",
	"side": "sell",
	"price": 1,
	"average": 1.48249,
	"amount": 500,
	"filled": 500,
	"remaining": 0,
	"cost": 741.245,
	"fee": 0,
	"error_message": "",
	"client_order_id": "",
	"trades": [
		{
			"id": "e86fcf94-88e6-46d8-8cc6-e06891eab6cf",
			"timestamp": 1692346145000,
			"symbol": "USDT/AUD",
			"order": "d8dabfbd-e541-4262-b6c2-9f841ef220f6",
			"type": "limit",
			"side": "sell",
			"taker_or_maker": "taker",
			"price": 1.48249,
			"amount": 500,
			"cost": 741.245,
			"order_from": "coinroutes",
			"fee": 0,
			"counterparty": "Wu Han"
		}
	]
}2. Fetch specific ordersresult = client.fetch_order(
                        id='',
                        )Request parameters:Parameterrequireddata typedescribeValue rangeidtruestringTransaction IDRequest parameters: examples (cannot be used directly, you need to replace your own parameters)headers = {
    'api-key': api_key,
    'signature': signature,
    'Content-Type': 'application/json',
    'timestamp': str(timestamp),
}

data = 
{
    "id": "d8dabfbd-e541-4262-b6c2-9f841ef220f6",
}Response data:Parameterrequireddata typedescribeValue rangeidtruestringTransaction IDtimestamptruelongTimelastTradeTimestamptruelongTimestatustruestringStatustypetruestringTypetimeInForcetruestringtimeInForcesidetruestringSidepricetruefloatPriceaveragetruefloataverageamounttruefloatQuantityfilledtruefloatfilledremainingtruefloatremainingcosttruefloatcostfeetruefloatfeeerror_messagetruestringerror_messagetradestruestringtradesclient_order_idtruestringclient_order_idResponse example:{
	"id": "d8dabfbd-e541-4262-b6c2-9f841ef220f6",
	"timestamp": 1692346145000,
	"last_trade_timestamp": 1692346145000,
	"status": "closed",
	"symbol": "USDT/AUD",
	"type": "limit",
	"time_in_force": "FOK",
	"side": "sell",
	"price": 1,
	"average": 1.48249,
	"amount": 500,
	"filled": 500,
	"remaining": 0,
	"cost": 741.245,
	"fee": 0,
	"error_message": "",
	"trades": [
		{
			"id": "e86fcf94-88e6-46d8-8cc6-e06891eab6cf",
			"timestamp": 1692346145000,
			"symbol": "USDT/AUD",
			"order": "d8dabfbd-e541-4262-b6c2-9f841ef220f6",
			"type": "limit",
			"side": "sell",
			"taker_or_maker": "taker",
			"price": 1,
			"amount": 500,
			"cost": 741.245,
			"order_from": "coinroutes",
			"fee": 0,
			"counterparty": "Wu Han"
		}
	]
}3. Batch fetch orderresult = client.fetch_orders(
                    symbol='USDT/AUD',
                    end_datetime=int(time.time() * 1000),
                    start_datetime=int(time.time() * 1000 - 10*86400*1000),
                    limit=10,
                    )Request parameters:Parameterrequireddata typedescribeValue rangesymbolfalsestringsymbolstart_datetimefalsestringstart_datetimeend_datetimefalsestringend_datetimepagefalsestringpagelimitfalsestringlimitidsfalsestringTransaction ids(null character string or id1,id2...)statusfalsestringstatussort_orderfalsestringsort_orderorder_typefalsestringorder_typesidefalsestringsideRequest parameters: examples (cannot be used directly, you need to replace your own parameters)headers = {
    'api-key': api_key,
    'signature': signature,
    'Content-Type': 'application/json',
    'timestamp': str(timestamp),
}

data = 
{
    "symbol": "USDT/AUD",
    "start_datetime": 0,
    "end_datetime": 0,
    "page": 0,
    "limit": 0,
    "ids": "",
    "status": "",
    "sort_order": "",
    "order_type": "",
    "side": "",
}Response data:Parameterrequireddata typedescribeValue rangeidtruestringTransaction IDtimestamptruelongtimestamplast_trade_timestamptruelonglast_trade_timestampstatustruestringstatussymboltruestringsymboltypetruestringtypetime_in_forcetruestringtime_in_forcesidetruestringsidepricetruefloatpriceaveragetruefloataverageamounttruefloatamountfilledtruefloatfilledremainingtruefloatremainingcosttruefloatcostfeetruefloatfeeerror_messagetruestringfeetradestruelisttradestotaltrueinttotalpagetrueintpageclient_order_idtruestringclient_order_idResponse example:{
	"order_list": [
		{
			"id": "e1af8ae0-3247-4755-87ad-f683fed3aff5",
			"timestamp": 1690797504000,
			"last_trade_timestamp": 1690797504000,
			"status": "closed",
			"symbol": "USDT/AUD",
			"type": "market",
			"time_in_force": "FOK",
			"side": "buy",
			"price": 21.1,
			"average": 2.98442,
			"amount": 101,
			"filled": 101,
			"remaining": 0,
			"cost": 301.426,
			"fee": 0,
			"error_message": "",
			"client_order_id": "",
			"trades": [
				{
					"id": "e1b3329c-4fc3-455a-82ed-ab5497b286cc",
					"timestamp": 1690797504000,
					"symbol": "USDT/AUD",
					"order": "e1af8ae0-3247-4755-87ad-f683fed3aff5",
					"type": "market",
					"side": "buy",
					"taker_or_maker": "taker",
					"price": 21.1,
					"amount": 101,
					"cost": 301.426,
					"order_from": "coinroutes",
					"fee": 0,
					"counterparty": "zeal anonymous"
				}
			]
		}
	],
	"status": "success",
	"total": 14087,
	"page": 1
}4. Request For quoteresult = client.request_for_quote(
                    symbol='USDT/AUD', 
                    side='buy', 
                    amount='100', 
                    client_order_id='', 
                    )Request parameters:Parameterrequireddata typedescribeValue rangesymboltruestringSymbolUSDT/AUDsidetruestringSidebuy sellamounttruestringAmountclient_order_idfalsestringPriceRequest parameters: examples (cannot be used directly, you need to replace your own parameters)headers = {
    'api-key': api_key,
    'signature': signature,
    'Content-Type': 'application/json',
    'timestamp': str(timestamp),
}

data = 
{
    "symbol": "USDT/AUD",
    "side": "buy",
    "amount": "100",
    "client_order_id": ""
}Response data:Parameterrequireddata typedescribeValue rangerfq_idtruestringRFQ IDclient_order_idtruestringClient Order IDquantitytruefloatQuantitysidetruestringSidesymboltruestringSymbolpricetruefloatpricecreatedtruestringSideResponse example:{
    "rfq_id": "3ec2f335-1995-4c59-9d3a-8e3a4d048d23",
    "client_order_id": "",
    "quantity": 100.0,
    "side": "buy",
    "symbol": "USDT/AUD",
    "price": 1.4882,
    "created": "2024-01-15T02:49:17.658142Z"
}5. Get Instrumentsresult = client.get_instruments()Request parameters: examples (cannot be used directly, you need to replace your own parameters)headers = {
    'api-key': api_key,
    'signature': signature,
    'Content-Type': 'application/json',
    'timestamp': str(timestamp),
}Response data:Parameterrequireddata typedescribeValue rangenametruestringNametypetruestringTypeis_tradabletrueboolIs Ttradablequantity_precisiontruefloatQuantity Precisionmax_quantitytruefloatMax Quantitymin_quantitytruefloatMin Quantityprice_precisiontruefloatPrice PrecisionResponse example:{
    "status": "successful",
    "instruments": [
        {
            "name": "USDT/AUD",
            "type": "SPOT",
            "is_tradable": false,
            "quantity_precision": 2.0,
            "max_quantity": 50000.0,
            "min_quantity": 1.0,
            "price_precision": 4.0
        }
    ]
}6. Get Balancesresult = client.get_balances()Request parameters: examples (cannot be used directly, you need to replace your own parameters)headers = {
    'api-key': api_key,
    'signature': signature,
    'Content-Type': 'application/json',
    'timestamp': str(timestamp),
}Response data:Parameterrequireddata typedescribeValue rangebalances_datatruejson stringBalances DataResponse example:{
    "balances_data": "{\"$AFLOKI\":{\"custody\":{\"free\":\"100.0\",\"total\":\"100.0\",\"used\":\"0\"}},\"$BOMB\":{\"Yield Exit Notes\":{\"free\":\"2.1516\",\"total\":\"2.1516\",\"used\":\"0\"},\"custody\":{\"free\":\"24.0\",\"total\":\"24.0\",\"used\":\"0\"},\"unlock\":{\"free\":\"999.4399\",\"total\":\"999.4399\",\"used\":\"0\"}},\"$CRAMER\":{\"unlock\":{\"free\":\"1.90\",\"total\":\"1.90\",\"used\":\"0\"}},\"$HD\":{\"custody\":{\"free\":\"90.0\",\"total\":\"90.0\",\"used\":\"0\"}},\"0NE\":{\"unlock\":{\"free\":\"1.0100\",\"total\":\"1.0100\",\"used\":\"0\"}},\"1INCH-WORMHOLE\":{\"unlock\":{\"free\":\"0.4087\",\"total\":\"0.4087\",\"used\":\"0\"}},\"AAVE\":{\"ZII\":{\"free\":\"8.0\",\"total\":\"8.0\",\"used\":\"0\"}},\"ATOM\":{\"ZII\":{\"free\":\"2.0\",\"total\":\"2.0\",\"used\":\"0\"}},\"AUD\":{\"Discount Note\":{\"free\":\"90\",\"total\":\"90\",\"used\":\"0\"},\"Yield Entry Notes\":{\"free\":\"2\",\"total\":\"2\",\"used\":\"0\"},\"custody\":{\"free\":\"3092.07032787879\",\"total\":\"3092.07032787879\",\"used\":\"0\"}",
    "status": "successful"
}7. Get Transfersresult = client.get_transfers(start_datetime=1706767455959,
                          end_datetime=1706770184310,
                          asset_id="ETH,AUD",
                          type="external_deposit,external_withdrawal",
                          page=1,
                          limit=20,
                          sort_order="desc")Request parameters:Parameterrequireddata typedescribeValue rangestart_datetimefalseintStart Datetimeend_datetimefalseintEnd Datetimeasset_idfalsestringAsset IdtypefalsestringTypeexternal_deposit,external_withdrawal,yield_deposit,create_term_yield,settled_term_yield, trading_transfer,trading_settlement,yield_interestpagefalsestringPagelimitfalsestringLimitsort_orderfalsestringSort Orderdesc, ascRequest parameters: examples (cannot be used directly, you need to replace your own parameters)headers = {
    'api-key': api_key,
    'signature': signature,
    'Content-Type': 'application/json',
    'timestamp': str(timestamp),
}

data = {
    "start_datetime": 1706767455959,
    "end_datetime": 1706770184310,
    "asset_id": "ETH,AUD",
    "type": "external_deposit,external_withdrawal",
    "page": 1,
    "limit": 20,
    "sort_order": "desc"
}Response data:Parameterrequireddata typedescribeValue rangestatustruestringInterface request status.totaltrueintThe total number of matching data.asset_idtruestringAsset IDamounttruefloatAmounttypetruestringTypefrom_account_typetruestringFrom Account Typeto_account_typetruestringTo Account Typeamount_usdtruefloatAmount USDinterest_earnedtruestringInterest Earnedtx_hashtruestringTx Hashsource_addresstruestringSource Addressdestination_addresstruestringDestination Addresstx_idtruestringTx IDfeetruefloatFeefee_currencytruestringFee Currencyname_referencetruestringName Referencebank_accounttruestringBank AccountcommenttruestringCommentstatustruestringStatuscreated_attruestringCreated AtResponse example:{
    "status": "successful",
    "total": 78,
    "user_id": "",
    "fiat_transactions": [
        {
            "user_id": "",
            "asset_id": "AUD",
            "amount": 1.22,
            "type": "",
            "from_account_type": "",
            "to_account_type": "",
            "amount_usd": 0.8004786,
            "note": "",
            "source_address": "",
            "destination_address": "",
            "tx_id": "a7ff3ee8-d62e-413d-8bf1-1e1305604883auto_sweep",
            "fee": 0.0,
            "fee_currency": "",
            "comment": "",
            "status": "COMPLETED",
            "created_at": 1702267616000
        },
    ],
    "fireblocks_transactions": [
        {
            "user_id": "",
            "asset_id": "AUD",
            "amount": 1.22,
            "type": "",
            "from_account_type": "",
            "to_account_type": "",
            "amount_usd": 0.8004786,
            "interest_earned": 0.0,
            "note": "",
            "tx_hash": "",
            "source_address": "",
            "destination_address": "",
            "tx_id": "a7ff3ee8-d62e-413d-8bf1-1e1305604883auto_sweep",
            "fee": 0.0,
            "fee_currency": "",
            "comment": "",
            "status": "COMPLETED",
            "created_at": 1702267616000
        },
    ]
}8. Get Timeresult = client.get_time()Request parameters: examples (cannot be used directly, you need to replace your own parameters)headers = {
    'api-key': api_key,
    'signature': signature,
    'Content-Type': 'application/json',
    'timestamp': str(timestamp),
}Response data:Parameterrequireddata typedescribeValue rangeResponse example:{
    "server_time": "2024-02-05 16:03:42"
}9. Get Riskresult = client.get_risk()Request parameters: examples (cannot be used directly, you need to replace your own parameters)headers = {
    'api-key': api_key,
    'signature': signature,
    'Content-Type': 'application/json',
    'timestamp': str(timestamp),
}Response data:Parameterrequireddata typedescribeValue rangemax_risk_limittruestringMax Risk Limitrisk_exposuretruestringRisk ExposureequitytruestringEquityResponse example:{
    "max_risk_limit": "100000",
    "risk_exposure": "0",
    "equity": "17048.35"
}websocketimport hmac
import hashlib
from zerocap_api_new_test import ZerocapWebsocketClient

# API key and secret are required, please contact zerocap to register.

api_key = "***" 
api_secret = "***"
websocket = ZerocapWebsocketClient(api_key, api_secret, env='uat')

# Create Ws Connection

timestamp = int(time.time())
websocket_connect = websocket.create_connection(timestamp)
connect_result = websocket.recv(websocket_connect)
print(connect_result)


signature = hmac.new(api_secret.encode("utf-8"), str(timestamp).encode("utf-8"), hashlib.sha256).hexdigest()Response example:{
    "type": "message",
    "message":"Successfully connected."
}

{
    "type": "error",
    "error_code": "401",
    "error_message":"Unauthorized"
}1. Subscribe to Market datawebsocket.send({"type": 'price', "symbol": "USDT/AUD"})
while True:
    # Get messages
    message = websocket.recv(websocket_connect)
    print(f"Receiving message from server: \n{message}")Request parameters:Parameterrequireddata typedescribeValue rangetypetruestrSubscription typepricesymboltruestrTransaction pairsUSDT/AUDRequest parameters: examples (cannot be used directly, you need to replace your own parameters)header={"api-key": api_key, "signature": signature, "timestamp": str(timestamp)}

wss://dma-uat-ws.defi.wiki/v2Response data:Parameterrequireddata typedescribeValue rangetypetruestrtypeprice, message, errordatafalsejsondatadata['timestamp']truestrtimedata['symbol']truestrsymboldata['exchange']truestrexchangedata['bids']truelistbidsdata['asks']truelistasksmessagefalsestrdescriptionerror_codefalsestrerror codeerror_messagefalsestrerror messageResponse example:{
    "type": "error",
    "error_code": "400",
    "error_message":"invalid message"
}

{
    "type": "message",
    "message":"price Subscription successful."
}

{

    "type": "message",
    "message": "pong"
}

{
    "type": "price",
    "data": {
        'timestamp': 1692340935.4283478,
        'symbol': 'USDT/AUD',
        'exchange': 'zerocap',
        'bids': [
            [1.47386, 5000.0],
            [1.47238, 10000.0],
            [1.4709, 20000.0],
            [1.46941, 30000.0]
        ],
        'asks': [
            [1.57236, 5000.0],
            [1.57392, 10000.0],
            [1.57548, 20000.0],
            [1.57705, 30000.0]
        ]
    }
}

{
    "type": "message",
    "message":"Price stream unavailable."
}2.  Subscribe Order updates or transaction recordswebsocket.send({"type": 'order'})
while True:
    # Get  messages
    message = websocket.recv(websocket_connect)
    
    print(f"Receiving message from server: \n{message}")Request parameters:Parameterrequireddata typedescribeValue rangetypetruestrSubscribed typeorderRequest parameters: examples (cannot be used directly, you need to replace your own parameters)header={"api-key": api_key, "signature": signature, "timestamp": str(timestamp)}

wss://dma-uat-ws.defi.wiki/v2order Response data:Parameterrequireddata typedescribeValue rangetypetruestrtypeorder, message, errordatafalsejsondatadata['id']truestriddata['timestamp']truestrtimestampdata['last_trade_timestamp']truestrlast_trade_timestampdata['status']truestrstatusdata['symbol']truestrsymboldata['type']truestrtypedata['time_in_force']truestrtime_in_forcedata['side']truestrsidedata['price']truefloatpricedata['average']truefloataveragedata['amount']truefloatamountdata['filled']truefloatfilleddata['remaining']truestrremainingdata['cost']truefloatcostdata['error_message']truestrerror_messagedata['fee']truestrfeedata['trades']truelisttradesmessagefalsestrdescriptionerror_codefalsestrerror codeerror_messagefalsestrerror messageResponse example:{
    "type": "error",
    "error_code": "400",
    "error_message":"invalid message"
}

{
    "type": "message",
    "message":"order Subscription successful."
}

{
    "type": "message",
    "message": "pong"
}

{
"type":"order",
"data":{
    "id":"f7fc4e4f-c099-4b18-a231-f032adc8ae87",
    "timestamp":1692354083000,
    "last_trade_timestamp":1692354083000,
    "status":"open",
    "symbol":"USDT/AUD",
    "type":"limit",
    "time_in_force":"FOK",
    "side":"buy",
    "price":3,
    "average":0,
    "amount":3,
    "filled":0,
    "remaining":3,
    "cost":9,
    "error_message":"",
    "fee":"0",
    "trades":[]
    }
}

{
"type":"order",
"data":{
    "id":"f7fc4e4f-c099-4b18-a231-f032adc8ae87",
    "timestamp":1692354083000,
    "last_trade_timestamp":1692354083000,
    "status":"closed",
    "symbol":"USDT/AUD",
    "type":"limit",
    "time_in_force":"FOK",
    "side":"buy",
    "price":3,
    "average":1.474899,
    "amount":3",
    "filled":3,
    "remaining":0,
    "cost":9,
    "error_message":"",
    "fee":"0",
    "trades":[{
        "id":"fa9cbef5-54ce-4a3a-8115-3db8af1f1617",
        "timestamp":1692354083000,
        "symbol":"USDT/AUD",
        "order":"f7fc4e4f-c099-4b18-a231-f032adc8ae87",
        "type":"limit",
        "side":"buy",
        "taker_or_maker":"taker",
        "price":1.474899,
        "amount":3,
        "cost":4.424,
        "order_from":"coinroutes",
        "counterparty":"Wu Han",
        "fee":"0"
        }]
    }
}3.  Subscribe transaction recordswebsocket.send({"type": 'trade'})
while True:
    # Get  messages
    message = websocket.recv(websocket_connect)
    
    print(f"Receiving message from server: \n{message}")Request parameters:Parameterrequireddata typedescribeValue rangetypetruestrSubscribed typetradeRequest parameters: examples (cannot be used directly, you need to replace your own parameters)header={"api-key": api_key, "signature": signature, "timestamp": str(timestamp)}

wss://dma-uat-ws.defi.wiki/v2Transaction Record Response data:Parameterrequireddata typedescribeValue rangetypetruestrtypetrade,message, errordatafalsejsondatadata['id']truestriddata['timestamp']truestrtimestampdata['datetime']truestrdatetimedata['symbol']truestrsymboldata['order']truestrorderdata['type']truestrtypedata['side']truestrsidedata['takerOrMaker']truestrtakerOrMakerdata['price']truefloatpricedata['amount']truefloatamountdata['cost']truefloatcostdata['orderFrom']truestrorderFrommessagefalsestrdescriptionerror_codefalsestrerror codeerror_messagefalsestrerror messageResponse example:{
    "type": "error",
    "error_code": "400",
    "error_message":"invalid message"
}

{
    "type": "message",
    "message":"trade Subscription successful."
}

{

    "type": "message",
    "message": "pong"
}

{
"type":"trade",
"data":{
    "id":"fa9cbef5-54ce-4a3a-8115-3db8af1f1617",
    "timestamp":"1692354083000",
    "symbol":"USDT/AUD",
    "order":"f7fc4e4f-c099-4b18-a231-f032adc8ae87",
    "type":"limit",
    "side":"buy",
    "takerOrMaker":"taker",
    "price":1.474899,
    "amount":3,
    "cost":4.424,
    "orderFrom":"coinroutes",
    "counterparty":"Wu Han"
    }
}