Advanced: fees

Customize fees with the API

Keep your own fee chains through the API, from reading the fee workspace to binding a chain and restoring the official fee.

Use the fee operations to keep your own fee chains: read the fee workspace, find or build a chain, preview it, bind it to a marketplace purpose, and restore the official fee.

Before you begin

  • Complete Your first request. The commands below use the CSCHEAP_API_KEY environment variable set there.
  • Saving your own fee operators, currencies, chains, and bindings needs an active subscription. Without one, these writes return 403 subscription_required. Reading, validating, and previewing stay available.
  • Fee operations cost no credits.
  • Your records are private unless you share them.
  • Your own chains change the fee workspace and previews. They never change the price quotes. See Marketplace fees.

The IDs and sequence numbers in the commands are illustrative. Replace 42 with a chain you can access, and read the current workspace sequences before you bind or reset a slot. The binding requests change your saved settings.

Read the fee workspace

Call Get the fee workspace. The response contains:

  • Your home currency.
  • Whether you can save (personal_writable).
  • The currencies you can use.
  • Every marketplace with three slots: deposit, sale, and withdraw.

Each slot holds the official binding, your binding, and which one is applied. It also holds the official_sequence and personal_sequence values that you send back when you change the slot.

Find or build a chain

To start from an existing chain:

  1. Search chains. The result lists official, shared, and your own chains, most used first. Each chain has a readable formula.
  2. Fork the chain. The copy is yours, starts at revision 1, and references the same operators.

To build a chain from scratch:

  1. Create fee operators. Where you change currency, also create convert operators.
  2. Validate the inline chain to see structural issues.
  3. Create the chain with its steps in order.

Preview an amount

Preview an amount through the chain:

curl 'https://api.cs.cheap/calculation-chains/preview' \
  --header "Authorization: Bearer $CSCHEAP_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{"calculation_chain_id": 42, "start_amount": "100", "start_currency": "USD"}'

A step that cannot compute still returns 200. In that case final is null, and the failing ledger entry carries an error.

Bind the chain to a marketplace purpose

Set the binding for one marketplace and purpose:

curl --request PUT 'https://api.cs.cheap/website-calculation-chain-bindings/BUFF/sale' \
  --header "Authorization: Bearer $CSCHEAP_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{"calculation_chain_id": 42, "expected_sequence": 0}'
  • Send the personal_sequence of the slot from the workspace as expected_sequence. Use 0 for a slot you never wrote.
  • If the slot changed since you read it, the request returns 409 conflict and nothing changes.
  • Without calculation_chain_revision, the current revision of the chain is bound.

You can also bind slots with apply_to when you create or update a chain. Either every listed slot is bound, or nothing is saved.

Restore the official fee

To follow the official fee again, remove your binding. Send both sequences you read, so that you restore the official binding you saw:

curl --request DELETE --get 'https://api.cs.cheap/website-calculation-chain-bindings/BUFF/sale' \
  --header "Authorization: Bearer $CSCHEAP_API_KEY" \
  --data-urlencode 'expected_sequence=1' \
  --data-urlencode 'expected_official_sequence=3'

Change a chain later

  1. Update the chain. Send the sequence you last read as expected_sequence.
  2. Bind the new revision, for example with apply_to. A new name, step list, or conversion setting is saved as a new revision. Bound slots keep their revision until you bind the new one.
  3. List the revisions to see the history.

When nothing uses a chain any more, you can deprecate it. Deprecation is final.

Handle errors

What you seeWhat to do
400 with error.details.missingA step references something you cannot use. Each entry names its kind, id, and reason. Fix the reference.
409 conflictA slot or chain changed since you read it, or a chain is still bound. Read it again, then retry.
422 with error.details.issuesThe steps of the chain do not line up. For example, a step expects a different currency than the amount is in. Fix the steps.

See API errors for the general rules.