# Overview

Integrating with Atomicals Market API

The Atomicals Market API assists developers in building cool things like trading bots or NFT sales analysis sites using our capabilities in indexing and marketplace. We offer a set of endpoints that allow you to retrieve ARC20 tokens, Realms, NFTs, as well as key components of our marketplace, such as listings, statistical data, and more. Let's build together. 💪

## Apply for an API Key

<https://forms.gle/iqjSDfiEhEYrTXu88>&#x20;

## Use API Key for API request

`curl -H "x-api-key: YOUR_API_KEY" https://api.atomicalmarket.com/health -i`

## API Endpoints & Documents

### Mainnet

<https://api.atomicalmarket.com/swagger>

### Testnet

<https://api-testnet.atomicalmarket.com/swagger>\
API-KEY: `WORMb3tunQDo0oN05AaW55GqaFH03wr5vC5Lt7Li`<br>


# Guides


# Assets Listing

Workflow for listing creation, fetching and deletion.

1. Prepare listing (to generate unsigned psbt for client to sign)

{% openapi src="/files/EhlQrEhRJOmoaUrfFxb2" path="/market/v1/bid/bulk-new" method="post" %}
[json 1503.json](https://46173898-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcsPhR6KWjYNyFUZFICd3%2Fuploads%2FrqrormeBCVFGy4pYGT5A%2Fjson%201503.json?alt=media\&token=7a15ade9-9f83-44b3-8706-a5b0232c8309)
{% endopenapi %}

2. Client sign `psbt` from last step's response

```javascript
import { Psbt, Transaction } from "bitcoinjs-lib";
const sellerPsbt = Psbt.fromHex(psbt);
const toSignInputs = sellerPsbt.data.inputs.map((_, index) => ({
  address, // seller address
  index,
  sighashTypes: [
    Transaction.SIGHASH_SINGLE | Transaction.SIGHASH_ANYONECANPAY,
  ],
}));
// injectProvider could be unisat (https://docs.unisat.io/dev/unisat-wallet-api)
const signedSellerPsbt = await injectProvider.signPsbt(psbt, {
  autoFinalized: false,
  toSignInputs: toSignInputs,
});
```

3. Confirm listing\
   `psbt` in the post body is last step's `signedSellerPsbt`

{% openapi src="/files/EhlQrEhRJOmoaUrfFxb2" path="/market/v1/bid/bulk-confirm" method="post" %}
[json 1503.json](https://46173898-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcsPhR6KWjYNyFUZFICd3%2Fuploads%2FrqrormeBCVFGy4pYGT5A%2Fjson%201503.json?alt=media\&token=7a15ade9-9f83-44b3-8706-a5b0232c8309)
{% endopenapi %}

4. Get listings by address

{% openapi src="/files/EhlQrEhRJOmoaUrfFxb2" path="/market/v1/{market}/listHistory" method="get" %}
[json 1503.json](https://46173898-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcsPhR6KWjYNyFUZFICd3%2Fuploads%2FrqrormeBCVFGy4pYGT5A%2Fjson%201503.json?alt=media\&token=7a15ade9-9f83-44b3-8706-a5b0232c8309)
{% endopenapi %}

5. Delist listing
   1. Generate the message to be signed by the client:\
      `const generateSigningMessage = (bidId) => You are signing this message to unlist your asset (Listing ID: ${bidId}) from AM.`
   2. Get `sig` by signing the message (eg using <https://docs.unisat.io/dev/unisat-developer-service/unisat-wallet#signmessage>)
   3. Post by /market/v1/token\_atom/unlist

{% openapi src="/files/EhlQrEhRJOmoaUrfFxb2" path="/market/v1/{market}/unlist" method="post" %}
[json 1503.json](https://46173898-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcsPhR6KWjYNyFUZFICd3%2Fuploads%2FrqrormeBCVFGy4pYGT5A%2Fjson%201503.json?alt=media\&token=7a15ade9-9f83-44b3-8706-a5b0232c8309)
{% endopenapi %}


# Assets Buying&#x20;

Workflow for assets buying.

1. Prepare buying

{% openapi src="/files/EhlQrEhRJOmoaUrfFxb2" path="/market/v1/{market}/bulk-buy" method="post" %}
[json 1503.json](https://46173898-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcsPhR6KWjYNyFUZFICd3%2Fuploads%2FrqrormeBCVFGy4pYGT5A%2Fjson%201503.json?alt=media\&token=7a15ade9-9f83-44b3-8706-a5b0232c8309)
{% endopenapi %}

2. Client sign `psbt` from last step's response

```javascript
const signedPsbt = await unisat.signPsbt(psbt, {
	autoFinalized: false
})
```

3. Confirm buying\
   `psbt` in the post body is last step's `signedPsbt`

{% openapi src="/files/EhlQrEhRJOmoaUrfFxb2" path="/market/v1/bid/bulk-confirm" method="post" %}
[json 1503.json](https://46173898-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcsPhR6KWjYNyFUZFICd3%2Fuploads%2FrqrormeBCVFGy4pYGT5A%2Fjson%201503.json?alt=media\&token=7a15ade9-9f83-44b3-8706-a5b0232c8309)
{% endopenapi %}


# Error Codes

<table><thead><tr><th width="322">Error Code</th><th>Description</th></tr></thead><tbody><tr><td>UNKNOWN</td><td></td></tr><tr><td>NOT_FOUND</td><td>URL path not found.</td></tr><tr><td>INTERNAL_SERVER_ERROR</td><td></td></tr><tr><td>VALIDATION</td><td>Query , body or response data validation error.</td></tr><tr><td>PARSE</td><td>Body parse error.</td></tr><tr><td>INDEXER_SERVICE_ERROR</td><td></td></tr><tr><td>INVALID_CONTAINER</td><td>Invalid atomicals container</td></tr><tr><td>WALLET_ADDRESS_NOT_MATCH</td><td>Listing validation error. When a malicious user try to list an UTXO he/she doesn't own.</td></tr><tr><td>LISTINGS_NOT_AVAILABLE</td><td>Happens when a user try to buy an listing which already unlisted or the UTXO is no longer unavailable (Might be already sold in another market)</td></tr><tr><td>LISTING_ALREADY_EXIST</td><td>Listing validation error. Wen a user try to list a UTXO which has already been listed.</td></tr><tr><td>INVALID_PSBT</td><td></td></tr><tr><td>INVALID_ADDRESS</td><td></td></tr><tr><td>TRANSACTION_FAILED</td><td></td></tr><tr><td>PRICE_TOO_LOW</td><td>Listing validation error. When seller price is lower than 1000 sats for a listing.</td></tr><tr><td>INVALID_UTXO</td><td></td></tr><tr><td>MULTIPLY_ATOMICALS_UTXO</td><td>Listing validation error. Happens when a user try to list an UTXO with multiple atomicals in it. For example an NFT and 1000 atom in an UTXO. Need to notify user we don't support this for now. </td></tr><tr><td>ATOMICALS_ID_MISMATCH</td><td>Listing validation error. Wen a malicious user try to list token "A" as token "B". </td></tr><tr><td>INSUFFICIENT_BALANCE</td><td>Buying validation error. When a user don't have enough balance to make the purchase.</td></tr><tr><td>TICKER_NOT_FOUND</td><td>Cannot find token info by name from the indexer. Maybe a wrong token name. </td></tr><tr><td>INVALID_SERVICE_FEE</td><td>Buying validation error. When a malicious user doesn't put the right amount of service fee in the signed psbt. </td></tr></tbody></table>


# Token split upgrade

\#ARC20 Partial token coloring protocol upgrade

### [/mainnet/v1/atomical/balance/{address}​](https://api-testnet.atomicalmarket.com/swagger#tag/default/get/mainnet/v1/atomical/balance/{address})

Added a **tokenAmount** filed to **TokenBalance.utxos .** Clients should use this **tokenAmount** instead **value** to get the token amount in this utxo. &#x20;

\
\
testnet usage guide: <https://docs.atomicalmarket.com/#testnet>


