Flash Liquidity Example

Start Web Socket Connection

Connect to the websocket-based Flash Liquidity API with your ANTHIC-API-KEY.

Reconcile Past Fills

Your client most likely needs to reconcile the state of its not-yet-completed fills (because they may have been e.g. settled on-ledger since your previous session got disconnected).

Let's assume that your database has stored the latest fill update of sequence number 1337, and while your client was offline, Anthic has recorded that 3 of your pending fills have been settled on-ledger.

This means that you should call the platform.fill_execution.start_stream with a configuration of historical_starting_point.at_sequence_number of 1338.

{
  "method": "platform.fill_execution.start_stream",
  "params": {
    "enabled": true,
    "historical_starting_point": 1338
  }
}

Anthic will immediately call the maker.fill_execution.next method 3 times (with sequence numbers 1338, 1339 and 1340), allowing you to apply these changes and bring your database to the current state.

{
  "method": "maker.fill_execution.next",
  "params": {
    "sequence_number": 1338,
    "occurred_at": 1733248268,
    "order_id": "abc123",
    "change": {
      "completed": {
        "outcome": "Settled"
      }
    }
  }
}

If another fill gets settled during this session, Anthic will call the same maker.fill_execution.next with sequence number 1341.

Publish Your Prices

At this point, your books are up-to-date and you know your available liquidity. Thus, you can begin streaming your prices. This is done by continuously sending platform.price_books.on_change notifications.

{
  "method": "platform.price_books.on_change",
  "params": {
    "pair": {
      "base": "xwBTC",
      "quote": "xUSDC"
    },
    "bids": [
      [ "95086", "0.000013" ],
      [ "95075", "0.000254" ],
      [ "95072", "3.522345" ]
    ],
    "asks": [
      [ "95263", "4.151835" ],
      [ "95264", "0.229412" ]
    ]
  }
}

It is fine to only include pairs which actually changed (i.e. each call is treated as a "delta", not a complete re-definition of an entire catalog of pricebooks).

It is also expected that you only send pricebooks for the pairs that you actually want to trade at the moment (i.e. if you do not trade the xwBTC/XRD pair, you never include its order book in the pricebook update).

If you stop trading a particular pair, it is okay to simply update its order book with {asks: [], bids: []}.

Subscribe to New Orders

Since you are now ready to trade and Anthic knows your pricing, you can start the new orders live stream by calling platform.new_orders.start_stream.

{
  "method": "platform.new_orders.start_stream",
  "params": {
  }
}

Optionally, you can customize the configuration here, e.g. only allow new orders of certain token pair.

Fill New Orders

From this point on, Anthic will keep sending you platform.new_orders.new notifications for each newly-created order.

{
  "method": "platform.new_orders.new",
  "params": {
    "id": "abc123",
    "created_at": 1733248268,
    "fill_before": 1733248278,
    "limit_order": {
      "sell": {
         "symbol": "xwBTC",
         "amount": "0.0003"
      },
      "buy": {
         "symbol": "xUSDC",
         "amount": "25.385284"
      }
    }
  }
}

Anthic will only forward orders which match your most recent pricebook (in particular, if you do not currently trade the xwBTC/XRD pair, the corresponding orders will not be offered).

You actively decide to fill some order, by calling the platform.fills.fill and providing a signed Limit Order Subintent for on-ledger settlement.

Track Status of Fills

If the fill is valid, Anthic sends you a maker.fill_execution.next notification with change.started details. This is a de facto confirmation that Anthic began the efforts to settle your fill on-ledger.

After some time, Anthic sends you another maker.fill_execution.next notification, this time with change.completed details. This is a de facto notification of a successful settlement (allowing you to update your books and adjust the token's availability).