Autonity CAX interactive tutorial

Recipes for how to interact with the Centralized Auton Exchange (CAX). Create an account on CAX with your participant key and transact on the exchange in the round’s On-chain Tasks!

1. Installation of necessary tools

sudo apt install jq

sudo apt install httpie

2. Get api key

1. Get nonce


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

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

2. Signature

aut account sign-message $MESSAGE message.sig

# output 0xa340cb7bb3...

3. Get 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="
}

3. CAX interaction

1. Check current account balance

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. Get the order book

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. Get current quotes

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. Transaction: Buy 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. Check order status

# 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. Cancel an order

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

7. Other commands

# Get all historical transaction records

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

# Get all order information

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

4. Withdraw from CAX to auton account

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
}
2
0