NAV Navbar
json

更新日志

版本 时间 内容
V1.0.0 2022-04-26 初始版本

介绍

用户手册

在Matrixport我们提供数字资产理财、借贷服务。 有两种方式可以调用我们的API接口:Rest 和 Websocket。

测试环境访问地址

生产环境访问地址

访问限制

为了保证系统运行效率,Matrixport实施API访问限流措施。公有接口按IP进行频率限制,私有接口按UID进行频率限制。当请求频率超限时,会返加“429 too many requests” 提示。

鉴权

私有接口必填字段


如果鉴权失败,会返回错误码412“AkID is valid”。

签名算法

    #########
    # Python code to calc BIT.COM API signature
    #########
    import hashlib
    import hmac

    def encode_list(self, item_list):
        list_val = []
        for item in item_list:
            obj_val = self.encode_object(item)
            list_val.append(obj_val)
        sorted_list = sorted(list_val)
        output = '&'.join(sorted_list)
        output = '[' + output + ']'
        return output

    def encode_object(self, param_map):
        sorted_keys = sorted(param_map.keys())
        ret_list = []
        for key in sorted_keys:
            val = param_map[key]
            if isinstance(val, list):
                list_val = self.encode_list(val)
                ret_list.append(f'{key}={list_val}')
            elif isinstance(val, dict):
                # call encode_object recursively
                dict_val = self.encode_object(val)
                ret_list.append(f'{key}={dict_val}')
            elif isinstance(val, bool):
                bool_val = str(val).lower()
                ret_list.append(f'{key}={bool_val}')
            else:
                general_val = str(val)
                ret_list.append(f'{key}={general_val}')

        sorted_list = sorted(ret_list)
        output = '&'.join(sorted_list)
        return output

    def get_signature(self, http_method, api_path, param_map):
        str_to_sign = api_path + '&' + self.encode_object(param_map)
        print('str_to_sign = ' + str_to_sign)
        sig = hmac.new(self.secret_key.encode('utf-8'), str_to_sign.encode('utf-8'), digestmod=hashlib.sha256).hexdigest()
        return sig

    #########
    # END
    #########

  1. 请求参数:POST为JSON,其余部分为查询字符串
  2. 对签名进行编码,对于简单的json对象,请按字母顺序对参数进行排序,并把他们用“&”连接,如'param1=value1&param2=value2', then get str_to_sign = api_path + '&' + 'param1=value1&param2=value2'
  3. 对嵌套数组对象,对每个对象进行编码,并按字母顺序进行排序,使用“&”符号连接,并用[ ]括起来,如 str_to_sign = api_path + '&' + 'param1=value1&array_key1=[array_item1&array_item2]', 参见下面的例子
  4. 签名使用哈希算法,hex(hmac_sha256(str_to_sign, secret_key))
  5. 在请求参数中添加签名字段:对查询字符串,添加“&signature=YOUR_SIGNATURE”, 对JOSN请求体, 添加 {'signature':YOUR_SIGNATURE}


































GET 请求示例:

*Secret Key: eabc3108-dd2b-43df-a98d-3e2054049b73
*HTTP method: GET
*API Path: /v1/margins
*Query string: price=8000&qty=30&instrument_id=BTC-PERPETUAL&timestamp=1588242614000
*得到 str_to_sign = /v1/margins&instrument_id=BTC-PERPETUAL&price=8000&qty=30&timestamp=1588242614000

> echo -n "/v1/margins&instrument_id=BTC-PERPETUAL&price=8000&qty=30&timestamp=1588242614000" | openssl dgst -sha256 -hmac "eabc3108-dd2b-43df-a98d-3e2054049b73"

> e3be96fdd18b5178b30711e16d13db406e0bfba089f418cf5a2cdef94f4fb57d

sig = hex(hmac_sha256(str_to_sign, secret_key)) = e3be96fdd18b5178b30711e16d13db406e0bfba089f418cf5a2cdef94f4fb57d

*最后JSON请求体为: { "instrument_id": "BTC-27MAR20-9000-C", "order_type": "limit", "price": "0.021", "qty": "3.14", "side": "buy", "time_in_force": "gtc", "stop_price": "", "stop_price_trigger": "", "auto_price": "", "auto_price_type": "", "timestamp": 1588242614000, "signature": "e3be96fdd18b5178b30711e16d13db406e0bfba089f418cf5a2cdef94f4fb57d" }

POST 请求示例:

Secret Key: eabc3108-dd2b-43df-a98d-3e2054049b73
HTTP method: POST
API Path: /v1/orders
JSON body:
{ "instrument_id": "BTC-27MAR20-9000-C", "order_type": "limit", "price": "0.021", "qty": "3.14", "side": "buy", "time_in_force": "gtc", "stop_price": "", "stop_price_trigger": "", "auto_price": "", "auto_price_type": "", "timestamp": 1588242614000 }

得到 str_to_sign = /v1/orders&auto_price=&auto_price_type=&instrument_id=BTC-27MAR20-9000-C&order_type=limit&price=0.021&qty=3.14&side=buy&stop_price=&stop_price_trigger=&time_in_force=gtc&timestamp=1588242614000

> echo -n "/v1/orders&auto_price=&auto_price_type=&instrument_id=BTC-27MAR20-9000-C&order_type=limit&price=0.021&qty=3.14&side=buy&stop_price=&stop_price_trigger=&time_in_force=gtc&timestamp=1588242614000" | openssl dgst -sha256 -hmac "eabc3108-dd2b-43df-a98d-3e2054049b73"

> 34d9afa68830a4b09c275f405d8833cd1c3af3e94a9572da75f7a563af1ca817

sig = hex(hmac_sha256(str_to_sign, secret_key)) = 34d9afa68830a4b09c275f405d8833cd1c3af3e94a9572da75f7a563af1ca817

最后JSON请求体为: { "instrument_id": "BTC-27MAR20-9000-C", "order_type": "limit", "price": "0.021", "qty": "3.14", "side": "buy", "time_in_force": "gtc", "stop_price": "", "stop_price_trigger": "", "auto_price": "", "auto_price_type": "", "timestamp": 1588242614000, "signature": "34d9afa68830a4b09c275f405d8833cd1c3af3e94a9572da75f7a563af1ca817" }

POST 请求带 boolean 字段

例如以POST /v1/orders 为例 (post_only 字段),

例子

request

得到 string to sign

POST 请求带 array 字段

for item in object_array:
    str_list.add(encode(item))
str_list.sorted()
str_to_sign = '&'.join(str_list)

以 POST /v1/blocktrades 为例:

私钥是 eabc3108-dd2b-43df-a98d-3e2054049b73

例子

request

得到 string to sign

接口目录

Path Method Description Scope Rate Limit Type Permission
/mapi/v1/wallet/withdraw POST 提现 private 钱包 钱包
/mapi/v1/wallet/withdrawals GET 提现记录 private 查询 钱包
/mapi/v1/wallet/deposits POST 充值记录 private 查询 钱包
/mapi/v1/wallet/balance POST 查询余额 private 查询 钱包

钱包

提现

POST /mapi/v1/wallet/withdraw

curl -X POST "https://api.matrixport.com/mapi/v1/wallet/withdraw" -H "Content-Type: application/json" -H "X-MatrixPort-Access-Key: Your Access Key" -d '{"currency": "BTC", "address": "Your address", "amount": "1.2", "pwd": "Your password", "timestamp": 1589523989378, "signature": "signature"}'

返回数据


{
    "code": 0,
    "message": "",
    "data": {
        "withdraw_id": "b61c2b93-8a25-44d4-9715-023cce61dc50"
    }
}

通过此接口,可从matrixport余额账户进行提现。
提现地址首先要Matrixport App提现页面 设置为白名单地址。
资金密码pwd字段需要通过base64(sha256(pwd))进行编码。例如,假设密码是123456,编码后的密码为“jZae727K08KaOmKSgOaGzww/XVqGr/PKEgIMkjrcbJI=”

请求参数

字段名称 数据类型 是否必填 默认值 说明
currency string true "" 币种,如BTC
address string true "" 提现地址
amount string true "" 提现金额
pwd string true "" 资金密码
chain string false "" 链名 提现USDT时,要提到USDTERC应填ETH,要提到USDTTRE应填TRX
tag string false ""

返回数据

字段名称 数据类型 说明
withdraw_id string 提现订单ID, 可用于后续的查询

提现记录

GET /mapi/v1/wallet/withdrawals

curl -H "X-MatrixPort-Access-Key: Your Access Key" "https://api.matrixport.com/mapi/v1/wallet/withdrawals?currency=BTC&limit=10&offset=0&timestamp=1589522687689&signature=signature"

返回数据


{
    "code": 0,
    "data": {
        "items": [{
            "address": "mfaFpdVCb6UFS5AXUhC8VGXgj9dnJ37nLP",
            "amount": "0.001",
            "code": 0,
            "confirmations": 0,
            "currency": "BTC",
            "fee": "0.00001",
            "state": "confirmed",
            "transaction_id": "52e1537002f51acbf5f52b9dfeab6a9e7cc185a669cda2573e768420b0839523",
            "created_at": 1608606000000,
            "updated_at": 1608606000000,
            "is_onchain": true
        }, {
            "address": "mfaFpdVCb6UFS5AXUhC8VGXgj9dnJ37nLP",
            "amount": "0.11",
            "code": 13100100,
            "confirmations": 0,
            "currency": "BTC",
            "fee": "0.00001",
            "state": "rejected",
            "transaction_id": "",
            "created_at": 1608606000000,
            "updated_at": 1608606000000,
            "is_onchain": false
        }]
    }
}

查询余额账户的提现记录。

请求参数

字段名称 数据类型 是否必填 默认值 说明
currency String true "" 币种名称
limit int false 10 分页大小,最大50
offset int false 1 分页偏移

返回数据

字段名称 数据类型 说明
code int 错误码,0代表正常,其他值代表失败
state string 提现状态 pending/confirmed/rejected/failed
address string 提现目标地址
amount string 提现金额
confirmations int 确认数,如果是内部地址,由于不会上链,一直为0
currency string 币种
fee string 提现手续费
transaction_id string 链上交易哈希
created_at int 订单创建时间戳
updated_at int 订单更新时间戳
is_onchain bool 订单是否上链(内部地址提现不上链)

充值记录

GET /mapi/v1/wallet/deposits

curl -H "X-MatrixPort-Access-Key: Your Access Key" "https://api.matrixport.com/mapi/v1/wallet/deposits?currency=BTC&limit=10&offset=0&timestamp=1589522687689&signature=signature"

返回数据


{
    "code": 0,
    "data": {
        "items": [{
            "address": "mfaFpdVCb6UFS5AXUhC8VGXgj9dnJ37nLP",
            "amount": "0.001",
            "code": 0,
            "confirmations": 0,
            "currency": "BTC",
            "state": "confirmed",
            "transaction_id": "52e1537002f51acbf5f52b9dfeab6a9e7cc185a669cda2573e768420b0839523",
            "created_at": 1608606000000,
            "updated_at": 1608606000000,
            "is_onchain": true
        }]
    }
}

查询提现记录

Query parameters

字段名称 数据类型 是否必填 默认值 说明
currency String true "" 币种名称
limit int false 10 分页大小,最大50
offset int false 1 分页偏移

返回数据

字段名称 数据类型 说明
code int 错误码,0代表正常,其他值代表失败
state string 充值状态 mempool/rollback/pending/confirmed/rejected
address string 充值来源地址
amount string 充值金额
confirmations int 确认数,如果是内部地址,由于不会上链,一直为0
currency string 币种
transaction_id string 链上交易哈希
created_at int 订单创建时间戳
updated_at int 订单更新时间戳
is_onchain bool 订单是否上链(内部地址充值不上链)

查询余额

GET /mapi/v1/wallet/balance

curl -H "X-MatrixPort-Access-Key: Your Access Key" "https://api.matrixport.com/mapi/v1/wallet/balance?timestamp=1589522687689&signature=signature"

返回数据



{
    "code": 0,
    "data": {
        "items": [{
            "currency": "BTC",
            "balance": "1.2",
            "available_balance": "1.2",
            "frozen_balance": "0",
            "unconfirmed_balance": "0.5"
        }]
    }
}

查询余额账户的所有余额。

查询参数

返回数据

字段名称 数据类型 说明
currency string 币种名称
balance string 余额
available_balance string 可用余额
frozen_balance string 冻结余额
unconfirmed_balance string unconfirmed 余额