Autonity CAX 交互教程

有关如何与集中式 Auton Exchange (CAX) 交互的秘诀。 使用您的参与者密钥在 CAX 上创建一个帐户,并在该轮的链上任务中在交易所进行交易!

一、安装必备工具

sudo apt install jq

sudo apt install httpie

二、获取 api key

1. 获取 nonce


MESSAGE=$(jq -nc --arg nonce "$(date +%s%N)" '$ARGS.named')

echo $MESSAGE
# output: {"nonce":"xxxxx"}

2. 签名

aut account sign-message $MESSAGE message.sig

# output 0xa340cb7bb3...

3. 获取 api key

# # message.sign is the result obtained in the second step
echo -n $MESSAGE | https https://cax.piccadilly.autonity.org/api/apikeys api-sig:0xa340cb7bb3...

# output
{
 "account": "0xF6e02381184E13Cbe0222eEDe0D12B61E2DF8bE5",
 "apikey": "o7JESIcMBgH7sfc7piRkZuqT7HgCW7hPiU3GpbaiSVoqBcYqGByQ7LvIqm0GNI/DLvdfAkWxKLUdpc/VfpcyuRw="
}

三、CAX 交互

1. 查询当前账户余额

https GET https://cax.piccadilly.autonity.org/api/balances API-Key:[API-key]

# output

HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 236
Content-Type: application/json
Date: Wed, 13 Mar 2024 00:59:40 GMT
Server: nginx/1.22.0 (Ubuntu)
access-control-allow-origin: *

[
    {
        "available": "0.000000000000000000",
        "balance": "0.000000000000000000",
        "symbol": "ATN"
    },
    {
        "available": "0.000000000000000000",
        "balance": "0.000000000000000000",
        "symbol": "NTN"
    },
    {
        "available": "1000000.00",
        "balance": "1000000.00",
        "symbol": "USD"
    }
]

2. 获取订单薄

https GET https://cax.piccadilly.autonity.org/api/orderbooks API-Key:[API-KEY]

#output

HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 171
Content-Type: application/json
Date: Wed, 13 Mar 2024 01:00:45 GMT
Server: nginx/1.22.0 (Ubuntu)
access-control-allow-origin: *

[
    {
        "base": "ATN",
        "min_amount": "0.01",
        "pair": "ATN-USD",
        "quote": "USD",
        "tick_size": "0.01"
    },
    {
        "base": "NTN",
        "min_amount": "0.01",
        "pair": "NTN-USD",
        "quote": "USD",
        "tick_size": "0.01"
    }
]

3. 获取当前报价

https GET https://cax.piccadilly.autonity.org/api/orderbooks/NTN-USD/quote API-Key:[API-KEY]

#output

HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 138
Content-Type: application/json
Date: Wed, 13 Mar 2024 01:02:01 GMT
Server: nginx/1.22.0 (Ubuntu)
access-control-allow-origin: *

{
    "ask_amount": "133333.33",
    "ask_price": "10.46",
    "bid_amount": "111111.11",
    "bid_price": "10.44",
    "timestamp": "2024-03-13T01:02:01.123813+00:00"
}

4. 交易:购买 NTN

https POST https://cax.piccadilly.autonity.org/api/orders API-Key:[API-KEY] pair=NTN-USD side=bid price=10.41 amount=10

# pair NTN-USD or ATN-USD
# price price obtained from step 3
# amount Purchase quantity

HTTP/1.1 201 Created
Connection: keep-alive
Content-Length: 180
Content-Type: application/json
Date: Wed, 13 Mar 2024 01:06:59 GMT
Server: nginx/1.22.0 (Ubuntu)
access-control-allow-origin: *

{
    "amount": "10.00",
    "order_id": 325160,
    "pair": "NTN-USD",
    "price": "10.44",
    "remain": "10.00",
    "side": "bid",
    "status": "pending",
    "timestamp": "2024-03-13T01:06:59.417627+00:00",
    "type": "limit"
}

5. 查看订单状态

# order_id is the order_id in the result returned in the previous step
https GET https://cax.piccadilly.autonity.org/api/orders/[order_id] API-Key:[API-KEY]

6. 取消一个订单

https DELETE https://cax.piccadilly.autonity.org/api/orders/[order_id] API-Key:[API-KEY]

7. 其他命令

# 获取所有的历史交易记录

https GET https://cax.piccadilly.autonity.org/api/trades API-Key:[API-KEY]

# 获取所有的订单信息

https GET  https://cax.piccadilly.autonity.org/api/orders API-Key:[API-KEY]

四、从 CAX 提取到 auton 账户

https POST https://cax.piccadilly.autonity.org/api/withdraws API-Key:[API-KEY] symbol=NTN  amount=10

#output
HTTP/1.1 202 Accepted
Connection: keep-alive
Content-Length: 197
Content-Type: application/json
Date: Wed, 13 Mar 2024 01:15:15 GMT
Server: nginx/1.22.0 (Ubuntu)
access-control-allow-origin: *

{
    "account": "0x0807...",
    "amount": "10.000000000000000000",
    "status": "accepted",
    "symbol": "NTN",
    "timestamp": "2024-03-13T01:15:15.067455+00:00",
    "txhash": null,
    "txid": 1463
}
0
0