@axis-markets/client 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +134 -0
- package/lib/axisContractClient.js +2 -0
- package/package.json +36 -0
- package/src/api-client.js +340 -0
- package/src/contract-client.js +36 -0
- package/src/errors.js +29 -0
- package/src/index.d.ts +584 -0
- package/src/index.js +225 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 StellarExpert Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# @axis-markets/client
|
|
2
|
+
|
|
3
|
+
JavaScript SDK for [AXIS](https://axis.markets) Stellar DEX.
|
|
4
|
+
|
|
5
|
+
- **`AxisContractClient`** — wraps the on-chain AXIS smart contract for order management and trading (sign & send transactions, read orders).
|
|
6
|
+
- **`ApiClient`** — a dependency-free HTTP client for the AXIS Aggregator and Indexer REST API (quotes, orderbook depth, candles, ticker, market/order/trade data).
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
npm i @axis-markets/client
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Requires Node.js 20+ (or any modern browser).
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## AxisContractClient
|
|
18
|
+
|
|
19
|
+
Wraps the on-chain AXIS smart contract for trading and order management.
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import {AxisContractClient, OrderKind, TradeDirection} from '@axis-markets/client'
|
|
23
|
+
|
|
24
|
+
const client = new AxisContractClient({
|
|
25
|
+
publicKey: 'G...', // trader public key
|
|
26
|
+
contractId: 'C...', // AXIS contract id
|
|
27
|
+
rpcUrl: 'https://soroban-rpc.stellar.org', // Stellar RPC server
|
|
28
|
+
signTransaction: async (xdr, context) => ({signedTxXdr: await wallet.sign(xdr)}) // tx sign callback
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
// Read the last created order id
|
|
32
|
+
const lastId = await client.last()
|
|
33
|
+
|
|
34
|
+
// Fetch an order by id
|
|
35
|
+
const order = await client.order(lastId)
|
|
36
|
+
|
|
37
|
+
// Place a sell limit order (creates a limit order if not fully executed)
|
|
38
|
+
const [sold, bought, newOrderId] = await client.sell({
|
|
39
|
+
kind: OrderKind.Limit,
|
|
40
|
+
trader: 'G...',
|
|
41
|
+
amount: 1_000_0000n,
|
|
42
|
+
selling: 'C...selling',
|
|
43
|
+
buying: 'C...buying',
|
|
44
|
+
price: 5_000_000n,
|
|
45
|
+
orders: []
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
// Cancel orders
|
|
49
|
+
await client.cancel([lastId], 'G...')
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
See [`src/index.d.ts`](src/index.d.ts) for the full typed API (`buy`, `sell`, `swap`, `fill_order`, `cancel`, `order`, `last`).
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## ApiClient
|
|
56
|
+
|
|
57
|
+
HTTP client for the AXIS Aggregator REST API. Uses the standard `fetch` API - no extra dependencies.
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
import {ApiClient, AxisApiError} from '@axis-markets/client'
|
|
61
|
+
|
|
62
|
+
const api = new ApiClient('https://aggregator.axis.markets')
|
|
63
|
+
|
|
64
|
+
// Quote: sell a fixed amount of the source asset (strict send)
|
|
65
|
+
const sellQuote = await api.quoteSell({
|
|
66
|
+
sellingAsset: 'XLM',
|
|
67
|
+
buyingAsset: 'USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN',
|
|
68
|
+
amount: '10000000' // stroops (1 unit = 10,000,000 stroops)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
// Quote: buy a fixed amount of the destination asset (strict receive)
|
|
72
|
+
const buyQuote = await api.quoteBuy({
|
|
73
|
+
sellingAsset: 'XLM',
|
|
74
|
+
buyingAsset: 'USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN',
|
|
75
|
+
amount: '5000000'
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
// Order book depth around the mid price
|
|
79
|
+
const depth = await api.getDepth({market: 'XLM/USDC', depth: 20})
|
|
80
|
+
|
|
81
|
+
// OHLCVT candles
|
|
82
|
+
const candles = await api.getCandles({market: 'XLM/USDC', resolution: '1h', order: 'asc'})
|
|
83
|
+
|
|
84
|
+
// 24h ticker for every market
|
|
85
|
+
const {ticker} = await api.getTicker24h()
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### ApiClient Methods
|
|
89
|
+
|
|
90
|
+
| Method | Description |
|
|
91
|
+
|---|---|
|
|
92
|
+
| `quoteSell({sellingAsset, buyingAsset, amount, direct?})` | Best trade routes for selling a fixed amount of the source asset (strict send). |
|
|
93
|
+
| `quoteBuy({sellingAsset, buyingAsset, amount, direct?})` | Best trade routes for buying a fixed amount of the destination asset (strict receive). |
|
|
94
|
+
| `getDepth({market, depth?})` | Order book depth aggregated into price buckets around the mid price (`depth` is the ± band %, 0–100, default 20). |
|
|
95
|
+
| `getCandles({market, from?, to?, resolution?, order?})` | OHLCVT candlestick data. `resolution` accepts seconds or an alias (`5m`, `15m`, `30m`, `1h`, `2h`, `4h`, `12h`, `1d`, `3d`, `1w`, `2w`; default `auto`). |
|
|
96
|
+
| `getTicker24h()` | 24-hour ticker statistics for every available market. |
|
|
97
|
+
| `getMarkets({cursor?, limit?})` | List all active markets with pagination. |
|
|
98
|
+
| `getOrders({owner?, asset?, cursor?, limit?})` | Active orders, filterable by owner or asset (`asset` may be a string or string array). |
|
|
99
|
+
| `getOrder(id)` | A single active order by ID (`null` if not found). |
|
|
100
|
+
| `getOrderHistory({owner?, pair?, cursor?, limit?})` | Archived/historical orders (`pair` = `[base, quote]` contract ids). |
|
|
101
|
+
| `getTrades({trader?, pair?, cursor?, limit?})` | Recent trades (`pair` = `[base, quote]` contract ids). |
|
|
102
|
+
|
|
103
|
+
Assets accept Soroban contract id or classic asset string formats like `XLM`, `CODE:Issuer`, `CODE-Issuer`.
|
|
104
|
+
Markets use `BASE/QUOTE` convention. Amounts are expressed in stroops on input and returned as strings.
|
|
105
|
+
|
|
106
|
+
### Error handling
|
|
107
|
+
|
|
108
|
+
Non-success responses throw an `AxisApiError` carrying the HTTP `status` code:
|
|
109
|
+
|
|
110
|
+
```js
|
|
111
|
+
try {
|
|
112
|
+
await api.getOrder('123')
|
|
113
|
+
} catch (e) {
|
|
114
|
+
if (e instanceof AxisApiError && e.status === 404) {
|
|
115
|
+
// not found
|
|
116
|
+
}
|
|
117
|
+
throw e
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Development
|
|
122
|
+
|
|
123
|
+
Bundling script:
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
npm run prepare
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Bundles the ESM source (`src/`) into a UMD distributable (`lib/`) via webpack.
|
|
130
|
+
Type definitions are published from `src/index.d.ts`.
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
MIT
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(A,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@stellar/stellar-sdk")):"function"==typeof define&&define.amd?define(["@stellar/stellar-sdk"],t):"object"==typeof exports?exports.axisContractClient=t(require("@stellar/stellar-sdk")):A.axisContractClient=t(A["@stellar/stellar-sdk"])}(this,A=>(()=>{"use strict";var t={346(t){t.exports=A}},l={};function e(A){var c=l[A];if(void 0!==c)return c.exports;var r=l[A]={exports:{}};return t[A](r,r.exports,e),r.exports}e.d=(A,t)=>{for(var l in t)e.o(t,l)&&!e.o(A,l)&&Object.defineProperty(A,l,{enumerable:!0,get:t[l]})},e.o=(A,t)=>Object.prototype.hasOwnProperty.call(A,t);var c={};e.d(c,{default:()=>i});var r=e(346);class G extends r.contract.Client{options;constructor(A){super(new r.contract.Spec(["AAAAAAAAADJHZXQgbGF0IG9yZGVyIGlkCgojIFJldHVybnMKCkxhc3QgY3JlYXRlZCBvcmRlciBpZAAAAAAABGxhc3QAAAAAAAAAAQAAAAY=","AAAAAAAAA4ZTd2FwIHRva2VucyBhY3Jvc3Mgc2V2ZXJhbCBtYXJrZXRzLgpUaGUgc3dhcCBleGVjdXRlcyB3aXRoaW4gdGhlIGJvdW5kYXJpZXMsIG90aGVyd2lzZSB0cmFkZSBnZXQgY2FuY2VsZWQ6CiogYFNlbGxgOiBleGFjdGx5IGBzZWxsaW5nX2Ftb3VudGAgc29sZCwgdGh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XNzZXQgYWRkcmVzcwAAAAZidXlpbmcAAAAAABMAAAABAAAADVRyYWRlIGRldGFpbHMAAAAAAAAFdHJhZGUAAAAAAAfQAAAABVRyYWRlAAAAAAAAAAAAAAA="]),A),this.options=A}fromJSON={last:this.txFromJSON,order:this.txFromJSON,cancel:this.txFromJSON,trade:this.txFromJSON,swap:this.txFromJSON,fill_order:this.txFromJSON}}const s={701:{message:"NotAuthorized"},702:{message:"InsufficientBalance"},703:{message:"OrderNotFound"},704:{message:"Overflow"},705:{message:"InvalidMatch"},706:{message:"InvalidPrice"}};function Z(A){if(A.simulation.error){const t=/HostError: Error\(Contract, #(\d+)\)/.exec(A.simulation.error);if(t){const A=t[1],l=s[A];if(l)throw new Error(`Contract execution error: #${A} ${l.message} `)}throw A.simulation.error}}class B extends Error{constructor(A,t){super(A),this.name="AxisApiError",this.status=t}status}const a={Sell:1,Buy:2};async function n(A,t,l){const e={direction:t,kind:A.kind,trader:A.trader,amount:A.amount,selling:A.selling,buying:A.buying,price:A.price,orders:A.orders},c=await l.client.trade(e,{fee:l.fee});Z(c);const{result:r}=await c.signAndSend();return[r[0],r[1],r[2]]}const i={AxisContractClient:class{constructor(A){const t={publicKey:A.publicKey,signTransaction:A.signTransaction,rpcUrl:A.rpcUrl,allowHttp:!0,networkPassphrase:A.networkPassphrase||r.Networks.PUBLIC,contractId:A.contractId};this.client=new G(t),this.fee=A.fee||"100000"}async last(){const A=await this.client.last();return Z(A),A.result}async order(A){const t=await this.client.order({id:A});return Z(t),t.result}async cancel(A,t){const l=await this.client.cancel({ids:A,trader:t},{fee:this.fee});Z(l),await l.signAndSend()}async fill_order(A,t,l){const e=await this.client.fill_order({trader:A,taker_order_id:t,orders:l},{fee:this.fee});Z(e);const c=await e.signAndSend();return[c.result.sold,c.result.bought]}async buy(A){return await n(A,a.Buy,this)}async sell(A){return await n(A,a.Sell,this)}async swap(A){const t=await this.client.swap({direction:A.direction,trader:A.trader,selling:A.selling,selling_amount:A.sellingAmount,buying_amount:A.buyingAmount,path:A.path.map(A=>({asset:A.asset,orders:A.orders}))},{fee:this.fee});Z(t);const l=await t.signAndSend();return[l.result.sold,l.result.bought]}},ContractErrors:s,TradeDirection:a,OrderKind:{Limit:1,Fill:2,FillOrKill:3},ApiClient:class{constructor(A){if(!A||"string"!=typeof A)throw new TypeError("Aggregator server URL is required");this.serverUrl=A.replace(/\/+$/,"")}serverUrl;async quoteSell(A){return this.quote(A,"strict_send")}async quoteBuy(A){return this.quote(A,"strict_receive")}async quote({sellingAsset:A,buyingAsset:t,amount:l,direct:e},c){return this.request("/quote",{sellingAsset:A,buyingAsset:t,amount:l,direction:c,direct:e})}async getDepth({market:A,depth:t}){return this.request("/depth",{market:A,depth:t})}async getCandles({market:A,from:t,to:l,resolution:e,order:c}){return this.request("/candles",{market:A,from:t,to:l,resolution:e,order:c})}async getTicker24h(){return this.request("/ticker/24h")}async getMarkets({cursor:A,limit:t}={}){return this.request("/markets",{cursor:A,limit:t})}async getOrders({owner:A,asset:t,cursor:l,limit:e}={}){return this.request("/order",{owner:A,asset:t,cursor:l,limit:e})}async getOrder(A){return this.request(`/order/${encodeURIComponent(A.toString())}`)}async getOrderHistory({owner:A,pair:t,cursor:l,limit:e}={}){return this.request("/order-history",{owner:A,pair:t,cursor:l,limit:e})}async getTrades({trader:A,pair:t,cursor:l,limit:e}={}){return this.request("/trades",{trader:A,pair:t,cursor:l,limit:e})}async request(A,t){let l=this.serverUrl+A;if(t){const A=new URLSearchParams;for(const[l,e]of Object.entries(t))if(null!=e)if(Array.isArray(e))for(const t of e)A.append(l,t);else A.append(l,e);const e=A.toString();e&&(l+="?"+e)}const e=await fetch(l);let c;try{c=await e.json()}catch(A){c=null}if(!e.ok)throw new B(c?.error||e.statusText,c?.status||e.status);return c}},AxisApiError:B};return c.default})());
|
|
2
|
+
//# sourceMappingURL=axisContractClient.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@axis-markets/client",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "AXIS contract and API client",
|
|
5
|
+
"author": "team@stellar.expert",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"types": "lib/index.d.ts",
|
|
9
|
+
"main": "lib/axisContractClient.js",
|
|
10
|
+
"module": "src/index.js",
|
|
11
|
+
"homepage": "https://axis.markets",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/axis-markets/js-client.git"
|
|
15
|
+
},
|
|
16
|
+
"bugs": "https://github.com/axis-markets/js-client/issues",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"prepare": "webpack --mode=production --config webpack.config.cjs"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"@stellar/stellar-sdk": ">=15"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@babel/core": "^8.0.1",
|
|
25
|
+
"@babel/preset-env": "^8.0.2",
|
|
26
|
+
"babel-loader": "10.1.1",
|
|
27
|
+
"babel-jest": "^30.4.1",
|
|
28
|
+
"jest": "^30.4.2",
|
|
29
|
+
"webpack": "^5.107.2",
|
|
30
|
+
"webpack-cli": "^7.0.3"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"src/",
|
|
34
|
+
"!src/cjs.js"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown when the Aggregator API responds with a non-success HTTP status
|
|
3
|
+
*/
|
|
4
|
+
export class AxisApiError extends Error {
|
|
5
|
+
/**
|
|
6
|
+
* @param {string} message - Error message returned by the API
|
|
7
|
+
* @param {number} status - HTTP status code
|
|
8
|
+
*/
|
|
9
|
+
constructor(message, status) {
|
|
10
|
+
super(message)
|
|
11
|
+
this.name = 'AxisApiError'
|
|
12
|
+
this.status = status
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* HTTP status code associated with the error
|
|
17
|
+
* @type {number}
|
|
18
|
+
* @readonly
|
|
19
|
+
*/
|
|
20
|
+
status
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* HTTP client for the AXIS Aggregator REST API
|
|
25
|
+
*/
|
|
26
|
+
export class ApiClient {
|
|
27
|
+
/**
|
|
28
|
+
* @param {string} serverUrl - Base URL of the Aggregator server
|
|
29
|
+
*/
|
|
30
|
+
constructor(serverUrl) {
|
|
31
|
+
if (!serverUrl || typeof serverUrl !== 'string')
|
|
32
|
+
throw new TypeError('Aggregator server URL is required')
|
|
33
|
+
//trim trailing slashes to avoid double slashes when building request paths
|
|
34
|
+
this.serverUrl = serverUrl.replace(/\/+$/, '')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Base URL of the Aggregator server
|
|
39
|
+
* @type {string}
|
|
40
|
+
* @readonly
|
|
41
|
+
*/
|
|
42
|
+
serverUrl
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Price quote and candidate trade routes for selling a fixed amount of the source asset
|
|
46
|
+
* @param {QuoteParams} params - Quote request parameters
|
|
47
|
+
* @return {Promise<QuoteResult>} - Best routes ranked by profitability
|
|
48
|
+
* @throws {AxisApiError} - If the server is not ready or there is not enough liquidity
|
|
49
|
+
*/
|
|
50
|
+
async quoteSell(params) {
|
|
51
|
+
return this.quote(params, 'strict_send')
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Price quote and candidate trade routes for buying a fixed amount of the destination asset
|
|
56
|
+
* @param {QuoteParams} params - Quote request parameters
|
|
57
|
+
* @return {Promise<QuoteResult>} - Best routes ranked by profitability
|
|
58
|
+
* @throws {AxisApiError} - If the server is not ready or there is not enough liquidity
|
|
59
|
+
*/
|
|
60
|
+
async quoteBuy(params) {
|
|
61
|
+
return this.quote(params, 'strict_receive')
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Find viable multi-hop paths between two assets, simulate trades on each path, and return the best routes
|
|
66
|
+
* @param {QuoteParams} params - Quote request parameters
|
|
67
|
+
* @param {'strict_send'|'strict_receive'} direction - Trade direction
|
|
68
|
+
* @return {Promise<QuoteResult>}
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
async quote({sellingAsset, buyingAsset, amount, direct}, direction) {
|
|
72
|
+
return this.request('/quote', {sellingAsset, buyingAsset, amount, direction, direct})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Order book depth aggregated into price buckets around the mid price
|
|
77
|
+
* @param {DepthParams} params - Depth request parameters
|
|
78
|
+
* @return {Promise<OrderbookDepth>} - Aggregated bids and asks
|
|
79
|
+
*/
|
|
80
|
+
async getDepth({market, depth}) {
|
|
81
|
+
return this.request('/depth', {market, depth})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* OHLCVT candlestick data (open, high, low, close, base volume, quote volume, trade count)
|
|
86
|
+
* @param {CandlesParams} params - Candles request parameters
|
|
87
|
+
* @return {Promise<Candle[]>} - Time-bucketed candles, max 200 per response
|
|
88
|
+
*/
|
|
89
|
+
async getCandles({market, from, to, resolution, order}) {
|
|
90
|
+
return this.request('/candles', {market, from, to, resolution, order})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 24-hour ticker statistics for every available market
|
|
95
|
+
* @return {Promise<Ticker24hResult>} - Aggregated 24h stats per market
|
|
96
|
+
*/
|
|
97
|
+
async getTicker24h() {
|
|
98
|
+
return this.request('/ticker/24h')
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* List all active markets with pagination
|
|
103
|
+
* @param {MarketsParams} [params] - Pagination parameters
|
|
104
|
+
* @return {Promise<MarketInfo[]>} - Active markets
|
|
105
|
+
*/
|
|
106
|
+
async getMarkets({cursor, limit} = {}) {
|
|
107
|
+
return this.request('/markets', {cursor, limit})
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Retrieve active orders, filterable by owner or asset
|
|
112
|
+
* @param {OrdersParams} [params] - Filter parameters
|
|
113
|
+
* @return {Promise<ApiOrder[]>} - Active orders matching the filter
|
|
114
|
+
*/
|
|
115
|
+
async getOrders({owner, asset, cursor, limit} = {}) {
|
|
116
|
+
return this.request('/order', {owner, asset, cursor, limit})
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Retrieve a single order by ID
|
|
121
|
+
* @param {bigint|string|number} id - Order ID
|
|
122
|
+
* @return {Promise<ApiOrder|null>} - Order, or null if not found
|
|
123
|
+
*/
|
|
124
|
+
async getOrder(id) {
|
|
125
|
+
return this.request(`/order/${encodeURIComponent(id.toString())}`)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Retrieve archived/historical orders
|
|
130
|
+
* @param {OrderHistoryParams} [params] - Filter parameters
|
|
131
|
+
* @return {Promise<ApiOrder[]>} - Archived orders matching the filter
|
|
132
|
+
*/
|
|
133
|
+
async getOrderHistory({owner, pair, cursor, limit} = {}) {
|
|
134
|
+
return this.request('/order-history', {owner, pair, cursor, limit})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Retrieve recent trades
|
|
139
|
+
* @param {TradesParams} [params] - Filter parameters
|
|
140
|
+
* @return {Promise<ApiTrade[]>} - Recent trades matching the filter
|
|
141
|
+
*/
|
|
142
|
+
async getTrades({trader, pair, cursor, limit} = {}) {
|
|
143
|
+
return this.request('/trades', {trader, pair, cursor, limit})
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Execute a GET request against the Aggregator API
|
|
148
|
+
* @param {string} path - Relative route path
|
|
149
|
+
* @param {object} [query] - Query parameters (undefined/null values skipped, arrays expanded to repeated params)
|
|
150
|
+
* @return {Promise<*>} - Parsed JSON response
|
|
151
|
+
* @throws {AxisApiError} - If the API responds with a non-success status
|
|
152
|
+
* @private
|
|
153
|
+
*/
|
|
154
|
+
async request(path, query) {
|
|
155
|
+
let url = this.serverUrl + path
|
|
156
|
+
if (query) {
|
|
157
|
+
const search = new URLSearchParams()
|
|
158
|
+
for (const [key, value] of Object.entries(query)) {
|
|
159
|
+
if (value === undefined || value === null)
|
|
160
|
+
continue
|
|
161
|
+
if (Array.isArray(value)) {
|
|
162
|
+
for (const item of value)
|
|
163
|
+
search.append(key, item)
|
|
164
|
+
} else {
|
|
165
|
+
search.append(key, value)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const qs = search.toString()
|
|
169
|
+
if (qs)
|
|
170
|
+
url += '?' + qs
|
|
171
|
+
}
|
|
172
|
+
const response = await fetch(url)
|
|
173
|
+
let body
|
|
174
|
+
try {
|
|
175
|
+
body = await response.json()
|
|
176
|
+
} catch (e) {
|
|
177
|
+
//non-JSON response (e.g. proxy/gateway error) - fall back to status text
|
|
178
|
+
body = null
|
|
179
|
+
}
|
|
180
|
+
if (!response.ok)
|
|
181
|
+
throw new AxisApiError(body?.error || response.statusText, body?.status || response.status)
|
|
182
|
+
return body
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @typedef {{}} QuoteParams
|
|
188
|
+
* @property {string} sellingAsset - Asset to sell (`XLM` | `CODE:Issuer` | `CODE-Issuer` | contractId)
|
|
189
|
+
* @property {string} buyingAsset - Asset to buy (same format as `sellingAsset`)
|
|
190
|
+
* @property {string|number} amount - Trade amount in stroops (1 unit = 10,000,000 stroops)
|
|
191
|
+
* @property {boolean} [direct] - Restrict to the direct market only (no intermediate-asset routes)
|
|
192
|
+
*/
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* @typedef {{}} QuoteResult
|
|
196
|
+
* @property {string} id - Base58-encoded quote id
|
|
197
|
+
* @property {'success'|'unfeasible'|'rejected'} status - Quote status
|
|
198
|
+
* @property {'strict_send'|'strict_receive'} direction - Trade direction
|
|
199
|
+
* @property {string} sellingAsset - Selling asset contract id
|
|
200
|
+
* @property {string} buyingAsset - Buying asset contract id
|
|
201
|
+
* @property {number} ledger - Ledger sequence the quote was computed for
|
|
202
|
+
* @property {QuotePath[]} paths - Candidate routes ranked by profitability (up to 10)
|
|
203
|
+
* @property {string} [error] - Error message (present only if status is not `success`)
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @typedef {{}} QuotePath
|
|
208
|
+
* @property {string} sold - Amount sold, in stroops
|
|
209
|
+
* @property {string} bought - Amount bought, in stroops
|
|
210
|
+
* @property {QuotePathStep[]} path - Ordered list of hops in the route
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* @typedef {{}} QuotePathStep
|
|
215
|
+
* @property {string} selling - Selling asset contract id at this hop
|
|
216
|
+
* @property {string} buying - Buying asset contract id at this hop
|
|
217
|
+
* @property {string[]} orders - Maker order IDs matched at this hop
|
|
218
|
+
*/
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* @typedef {{}} DepthParams
|
|
222
|
+
* @property {string} market - Market identifier `BASE/QUOTE`
|
|
223
|
+
* @property {number} [depth] - Percentage band (±) around the center price (0 < depth ≤ 100, default 20)
|
|
224
|
+
*/
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* @typedef {{}} OrderbookDepth
|
|
228
|
+
* @property {number} ledger - Ledger sequence
|
|
229
|
+
* @property {number} timestamp - UNIX timestamp (seconds)
|
|
230
|
+
* @property {Array<[string, string]>} bids - `[price, quantity]` pairs sorted descending by price
|
|
231
|
+
* @property {Array<[string, string]>} asks - `[price, quantity]` pairs sorted ascending by price
|
|
232
|
+
*/
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* @typedef {{}} CandlesParams
|
|
236
|
+
* @property {string} market - Market identifier `BASE/QUOTE`
|
|
237
|
+
* @property {number} [from] - Lower boundary (UNIX seconds, default 0)
|
|
238
|
+
* @property {number} [to] - Upper boundary (UNIX seconds, defaults to `from + resolution * 200`)
|
|
239
|
+
* @property {number|string} [resolution] - Resolution in seconds or alias (`5m`,`15m`,`30m`,`1h`,`2h`,`4h`,`12h`,`1d`,`3d`,`1w`,`2w`, default `auto`)
|
|
240
|
+
* @property {'asc'|'desc'} [order] - Sort order (default `desc`)
|
|
241
|
+
*/
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* OHLCVT candle row: `[timestamp, open, high, low, close, baseVolume, quoteVolume, tradeCount]`
|
|
245
|
+
* @typedef {[number, string, string, string, string, string, string, number]} Candle
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* @typedef {{}} Ticker24hResult
|
|
250
|
+
* @property {number} ledger - Ledger sequence
|
|
251
|
+
* @property {number} timestamp - UNIX timestamp (seconds)
|
|
252
|
+
* @property {TickerEntry[]} ticker - Per-market 24h stats, sorted by trade count descending
|
|
253
|
+
*/
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* @typedef {{}} TickerEntry
|
|
257
|
+
* @property {string} symbol - Market symbol `BASE/QUOTE`
|
|
258
|
+
* @property {string} openPrice - Opening price 24h ago
|
|
259
|
+
* @property {string} highPrice - Highest price in the 24h window
|
|
260
|
+
* @property {string} lowPrice - Lowest price in the 24h window
|
|
261
|
+
* @property {string} lastPrice - Most recent trade price
|
|
262
|
+
* @property {string} volume - 24h base asset volume
|
|
263
|
+
* @property {string} quoteVolume - 24h quote asset volume
|
|
264
|
+
* @property {number} change - 24h price change (percent)
|
|
265
|
+
* @property {string} avgPrice - Volume-weighted average price
|
|
266
|
+
* @property {number} trades - 24h trade count
|
|
267
|
+
*/
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* @typedef {{}} MarketsParams
|
|
271
|
+
* @property {string} [cursor] - Pagination cursor (`baseAsset-quoteAsset`)
|
|
272
|
+
* @property {number|string} [limit] - Max markets to return
|
|
273
|
+
*/
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* @typedef {{}} MarketInfo
|
|
277
|
+
* @property {string} baseAsset - Base asset contract id
|
|
278
|
+
* @property {string} quoteAsset - Quote asset contract id
|
|
279
|
+
* @property {string} cursor - Pagination cursor for this market
|
|
280
|
+
* @property {string[]} orderTypes - Supported order types
|
|
281
|
+
*/
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* @typedef {{}} OrdersParams
|
|
285
|
+
* @property {string} [owner] - Filter by order owner address
|
|
286
|
+
* @property {string|string[]} [asset] - Filter by asset(s) - matches orders selling or buying any of them
|
|
287
|
+
* @property {string|bigint} [cursor] - Pagination cursor (order id)
|
|
288
|
+
* @property {number|string} [limit] - Max orders to return
|
|
289
|
+
*/
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* @typedef {{}} OrderHistoryParams
|
|
293
|
+
* @property {string} [owner] - Filter by order owner address
|
|
294
|
+
* @property {string[]} [pair] - Asset pair `[base, quote]` (contract ids)
|
|
295
|
+
* @property {string|bigint} [cursor] - Pagination cursor (order id)
|
|
296
|
+
* @property {number|string} [limit] - Max orders to return
|
|
297
|
+
*/
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* @typedef {{}} TradesParams
|
|
301
|
+
* @property {string} [trader] - Filter by trader address
|
|
302
|
+
* @property {string[]} [pair] - Asset pair `[base, quote]` (contract ids)
|
|
303
|
+
* @property {string|bigint} [cursor] - Pagination cursor (trade id)
|
|
304
|
+
* @property {number|string} [limit] - Max trades to return
|
|
305
|
+
*/
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* @typedef {{}} ApiOrder - Serialized order returned by the API
|
|
309
|
+
* @property {string} id - Order ID
|
|
310
|
+
* @property {string} status - Order status (`ACTIVE`|`FILLED`|`CANCELED`)
|
|
311
|
+
* @property {string} kind - Order kind (`LIMIT`)
|
|
312
|
+
* @property {string} buying - Buying asset contract id
|
|
313
|
+
* @property {string} selling - Selling asset contract id
|
|
314
|
+
* @property {string} price - Order price
|
|
315
|
+
* @property {string} rprice - Rational price representation
|
|
316
|
+
* @property {string} quote - Total quote amount
|
|
317
|
+
* @property {string} amount - Amount left to sell/buy
|
|
318
|
+
* @property {string} owner - Maker address
|
|
319
|
+
* @property {string} [expires] - Expiration timestamp (UTC)
|
|
320
|
+
* @property {string} [iceberg] - Iceberg amount
|
|
321
|
+
* @property {string} [stop] - Stop price
|
|
322
|
+
* @property {string} [created] - Creation timestamp (UTC)
|
|
323
|
+
* @property {string} [updated] - Last update timestamp (UTC)
|
|
324
|
+
* @property {string} [cursor] - Pagination cursor
|
|
325
|
+
*/
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* @typedef {{}} ApiTrade - Serialized trade returned by the API
|
|
329
|
+
* @property {string} id - Trade ID
|
|
330
|
+
* @property {string} order - Matched order ID
|
|
331
|
+
* @property {string} taker - Taker account address
|
|
332
|
+
* @property {string} maker - Maker account address
|
|
333
|
+
* @property {string} soldAsset - Sold asset contract id
|
|
334
|
+
* @property {string} boughtAsset - Bought asset contract id
|
|
335
|
+
* @property {string} sold - Sold tokens amount
|
|
336
|
+
* @property {string} bought - Bought tokens amount
|
|
337
|
+
* @property {string} price - Approximate trade price
|
|
338
|
+
* @property {string} [cursor] - Pagination cursor
|
|
339
|
+
* @property {string} timestamp - Trade timestamp (UTC)
|
|
340
|
+
*/
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {contract} from '@stellar/stellar-sdk'
|
|
2
|
+
|
|
3
|
+
export default class ContractClient extends contract.Client {
|
|
4
|
+
options
|
|
5
|
+
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super(new contract.Spec([
|
|
8
|
+
"AAAAAAAAADJHZXQgbGF0IG9yZGVyIGlkCgojIFJldHVybnMKCkxhc3QgY3JlYXRlZCBvcmRlciBpZAAAAAAABGxhc3QAAAAAAAAAAQAAAAY=",
|
|
9
|
+
"AAAAAAAAA4ZTd2Fw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gAAAAAAEQAAAAEAAAAVU2VsbGluZyBhc3NldCBhZGRyZXNzAAAAAAAAB3NlbGxpbmcAAAAAEwAAAAEAAAAUQnV5aW5nIGFzc2V0IGFkZHJlc3MAAAAGYnV5aW5nAAAAAAATAAAAAQAAAA1PcmRlciBkZXRhaWxzAAAAAAAABW9yZGVyAAAAAAAH0AAAAAVPcmRlcgAAAAAAAAAAAAAA",
|
|
23
|
+
"AAAABQAAAAAAAAAAAAAAClRyYWRlRXZlbnQAAAAAAAIAAAAEQVhJUwAAAAV0cmFkZQAAAAAAAAMAAAASU29sZCBhc3NldCBhZGRyZXNzAAAAAAAHc2VsbGluZwAAAAATAAAAAQAAABRCb3VnaHQgYXNzZXQgYWRkcmVzcwAAAAZidXlpbmcAAAAAABMAAAABAAAADVRyYWRlIGRldGFpbHMAAAAAAAAFdHJhZGUAAAAAAAfQAAAABVRyYWRlAAAAAAAAAAAAAAA="
|
|
24
|
+
]), options)
|
|
25
|
+
this.options = options
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
fromJSON = {
|
|
29
|
+
last: this.txFromJSON,
|
|
30
|
+
order: this.txFromJSON,
|
|
31
|
+
cancel: this.txFromJSON,
|
|
32
|
+
trade: this.txFromJSON,
|
|
33
|
+
swap: this.txFromJSON,
|
|
34
|
+
fill_order: this.txFromJSON
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/errors.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard contract errors
|
|
3
|
+
*/
|
|
4
|
+
export const ContractErrors = {
|
|
5
|
+
701: {message: "NotAuthorized"},
|
|
6
|
+
702: {message: "InsufficientBalance"},
|
|
7
|
+
703: {message: "OrderNotFound"},
|
|
8
|
+
704: {message: "Overflow"},
|
|
9
|
+
705: {message: "InvalidMatch"},
|
|
10
|
+
706: {message: "InvalidPrice"}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Handle simulation errors if any
|
|
14
|
+
* @param {AssembledTransaction} tx
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export function processSimulationErrors(tx) {
|
|
18
|
+
if (tx.simulation.error) {
|
|
19
|
+
const contractErrorMatch = /HostError: Error\(Contract, #(\d+)\)/.exec(tx.simulation.error)
|
|
20
|
+
if (contractErrorMatch) {
|
|
21
|
+
const code = contractErrorMatch[1]
|
|
22
|
+
const err = ContractErrors[code]
|
|
23
|
+
if (err) {
|
|
24
|
+
throw new Error(`Contract execution error: #${code} ${err.message} `)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
throw tx.simulation.error
|
|
28
|
+
}
|
|
29
|
+
}
|