Skip to main content

zerocap_api

Project description

zerocap-api-new-test

Jump restapi

Jump websocket


Introduction

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

sdk install
pip install zerocap-api-new-test 



restapi

from 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, envion='uat')

timestamp = int(time.time())
signature = hmac.new(api_secret.encode("utf-8"), str(timestamp).encode("utf-8"), hashlib.sha256).hexdigest()

1. Create an order


result = client.create_order(
                    symbol='USDT/AUD', 
                    side='buy', 
                    type='limit', 
                    amount='100', 
                    price='1000', 
                    coinroutes_customer_id=5,
                    )

Request parameters:

Parameter required data type describe Value range
symbol true string Instrument USDT/AUD
side true string Side buy sell
type true string Type limit
amount true string Quantity
price true string Price
coinroutes_customer_id false int coinroutes_customer_id
client_order_id false string client_order_id

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),
}

data = 
{
    "symbol": "USDT/AUD",
    "side": "buy",
    "type": "limit",
    "amount": "1000",
    "price": "1000",
    "coinroutes_customer_id": 5,
}


Response data:

Parameter required data type describe Value range
id true string Transaction ID
timestamp true long Time
lastTradeTimestamp true long Time
status true string Status
type true string Type
timeInForce true string timeInForce
side true string Side
price true float Price
average true float average
amount true float Quantity
filled true float filled
remaining true float remaining
cost true float cost
fee true float fee
error_message true string error_message
trades true string trades
client_order_id true string client_order_id

Response 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 orders

result = client.fetch_order(
                        id='',
                        )

Request parameters:

Parameter required data type describe Value range
id true string Transaction ID

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),
}

data = 
{
    "id": "d8dabfbd-e541-4262-b6c2-9f841ef220f6",
}


Response data:

Parameter required data type describe Value range
id true string Transaction ID
timestamp true long Time
lastTradeTimestamp true long Time
status true string Status
type true string Type
timeInForce true string timeInForce
side true string Side
price true float Price
average true float average
amount true float Quantity
filled true float filled
remaining true float remaining
cost true float cost
fee true float fee
error_message true string error_message
trades true string trades
client_order_id true string client_order_id

Response 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 order

result = 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:

Parameter required data type describe Value range
symbol false string symbol
start_datetime false string start_datetime
end_datetime false string end_datetime
page false string page
limit false string limit
ids false string Transaction ids(null character string or id1,id2...)
status false string status
sort_order false string sort_order
order_type false string order_type
side false string side

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),
}

data = 
{
    "symbol": "USDT/AUD",
    "start_datetime": 0,
    "end_datetime": 0,
    "page": 0,
    "limit": 0,
    "ids": "",
    "status": "",
    "sort_order": "",
    "order_type": "",
    "side": "",
}

Response data:

Parameter required data type describe Value range
id true string Transaction ID
timestamp true long timestamp
last_trade_timestamp true long last_trade_timestamp
status true string status
symbol true string symbol
type true string type
time_in_force true string time_in_force
side true string side
price true float price
average true float average
amount true float amount
filled true float filled
remaining true float remaining
cost true float cost
fee true float fee
error_message true string fee
trades true list trades
total true int total
page true int page
client_order_id true string client_order_id

Response 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 quote


result = client.request_for_quote(
                    symbol='USDT/AUD', 
                    side='buy', 
                    quantity='100', 
                    client_order_id='', 
                    )

Request parameters:

Parameter required data type describe Value range
symbol true string Symbol USDT/AUD
side true string Side buy sell
quantity true string Quantity
client_order_id false string Price

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),
}

data = 
{
    "symbol": "USDT/AUD",
    "side": "buy",
    "quantity": "100",
    "client_order_id": ""
}


Response data:

Parameter required data type describe Value range
rfq_id true string Transaction ID
client_order_id true string Client Order ID
quantity true float Quantity
side true string Side
symbol true string Symbol
price true float price
created true string Side

Response 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 Instruments

result = 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:

Parameter required data type describe Value range
name true string Name
type true string ype
is_tradable true bool Is Ttradable
quantity_precision true float Quantity Precision
max_quantity true float Max Quantity
min_quantity true float Min Quantity
price_precision true float Price Precision

Response 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 Balances

result = 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:

Parameter required data type describe Value range
balances_data true json string Balances Data

Response 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"
}

websocket

import 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, envion='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 data


websocket.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:

Parameter required data type describe Value range
type true str Subscription type price
symbol true str Transaction pairs USDT/AUD

Request 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/v2

Response data:

Parameter required data type describe Value range
type true str type price, message, error
data false json data
data['timestamp'] true str time
data['symbol'] true str symbol
data['exchange'] true str exchange
data['bids'] true list bids
data['asks'] true list asks
message false str description
error_code false str error code
error_message false str error message

Response 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 records


websocket.send({"type": 'order'})
while True:
    # Get  messages
    message = websocket.recv(websocket_connect)
    
    print(f"Receiving message from server: \n{message}")

Request parameters:

Parameter required data type describe Value range
type true str Subscribed type order

Request 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/v2

order Response data:

Parameter required data type describe Value range
type true str type order, message, error
data false json data
data['id'] true str id
data['timestamp'] true str timestamp
data['last_trade_timestamp'] true str last_trade_timestamp
data['status'] true str status
data['symbol'] true str symbol
data['type'] true str type
data['time_in_force'] true str time_in_force
data['side'] true str side
data['price'] true float price
data['average'] true float average
data['amount'] true float amount
data['filled'] true float filled
data['remaining'] true str remaining
data['cost'] true float cost
data['error_message'] true str error_message
data['fee'] true str fee
data['trades'] true list trades
message false str description
error_code false str error code
error_message false str error message

Response 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 records


websocket.send({"type": 'trade'})
while True:
    # Get  messages
    message = websocket.recv(websocket_connect)
    
    print(f"Receiving message from server: \n{message}")

Request parameters:

Parameter required data type describe Value range
type true str Subscribed type trade

Request 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/v2

Transaction Record Response data:

Parameter required data type describe Value range
type true str type trade,message, error
data false json data
data['id'] true str id
data['timestamp'] true str timestamp
data['datetime'] true str datetime
data['symbol'] true str symbol
data['order'] true str order
data['type'] true str type
data['side'] true str side
data['takerOrMaker'] true str takerOrMaker
data['price'] true float price
data['amount'] true float amount
data['cost'] true float cost
data['orderFrom'] true str orderFrom
message false str description
error_code false str error code
error_message false str error message

Response 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"
    }
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zerocap_api_new_test-0.1.43.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

zerocap_api_new_test-0.1.43-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file zerocap_api_new_test-0.1.43.tar.gz.

File metadata

  • Download URL: zerocap_api_new_test-0.1.43.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.6

File hashes

Hashes for zerocap_api_new_test-0.1.43.tar.gz
Algorithm Hash digest
SHA256 fc3ccf5e9bfab23fe88bbe070fe43dda2aca5d10fbad52fcb663d3a9c2e5eda6
MD5 f3dadbec6e6f68b043bb93bbca812e44
BLAKE2b-256 2dd8141f8473a7701bd37dca6feb37ee5758bc6f8858af227bb329d65fcd43ef

See more details on using hashes here.

File details

Details for the file zerocap_api_new_test-0.1.43-py3-none-any.whl.

File metadata

File hashes

Hashes for zerocap_api_new_test-0.1.43-py3-none-any.whl
Algorithm Hash digest
SHA256 df8b22127507e7bed31fdc198f4088d8f2115adaa8a0d2ee6b95cc32e9a6cf2b
MD5 a3e38c5c7f790ed7a18eaf68a60f2498
BLAKE2b-256 7064bf855bb89393a9ab069d4bc3a1fb04d21d7dc48b2e05a86aa5426c9e3c31

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page