npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@stellar-broker/client

v0.6.14

Published

Client library for StellarBroker service

Downloads

155

Readme

@stellar-broker/client

Installation

npm i @stellar-broker/client

Usage

Interactive Sessions

Using an interactive session is the preferred way for the majority of integrations. A client connects to the router server and maintains the connection open, receiving price quote updates and other notifications from the server without delays. Trading, retries, and results confirmations get processed in the background.

import {StellarBrokerClient} from '@stellar-broker/client'

//create client instance
const client = new StellarBrokerClient({partnerKey: '<your_partner_key>'})

//subscribe to the quote notifications
client.on('quote', e => {
    console.log('Received route quote from the server', e.quote)
    /*{
      "status": "success",
      "sellingAsset": "USDC-GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
      "buyingAsset": "XLM",
      "slippageTolerance": 0.5,
      "directTrade": {
          "selling": "10",
          "buying": "100.23505",
          "path": []
      },
      "sellingAmount": "10",
      "estimatedBuyingAmount": "100.688121",
      "ts": "2024-08-13T23:13:21.275Z"
    }*/
})

client.on('paused', e => {
    console.log('Quotation paused due to inactivity. Call `quote` method to resume.')
})

client.on('finished', e => {
    console.log('Trade finished', e.result)
    /*{
      "status": "success",
      "sold": "10",
      "bought": "100.6704597"
    }*/
})

client.on('progress', e => {
    console.log('Progress', e.status)
    /*{
      "sold": "10",
      "bought": "100.6704597"
    }*/
})

client.on('error', e => {
    console.warn('StellarBroker error', e.error)
})

//connect
client.connect() //only once
    .then(() => console.log('StellarBroker connected'))
    .catch(e => console.error(e))

//request a price quote
client.quote({
    sellingAsset: 'xlm',
    buyingAsset: 'USDC-GDK2GNB4Q6FKNW2GNJIQFARI4RMSHV5DN5G4BBXX2F24RT5I4QT7TWZ7',
    sellingAmount: '1000', //1000.0000000 XLM
    slippageTolerance: 0.02 //2%
})

//once the quote received from the server, we can confirm the quote
async function signTx(payload) { //async signing callback - implement custom logic here
    const kp = Keypair.fromSecret('<account_secret>')
    if (payload.sign) { //sign transaction
        payload.sign(kp)
        return payload
    } 
    //it's authorization payload
    return kp.sign(payload)
}
client.confirmQuote('<account_address>', signTx) //provide trader account address

//trade can be interrupted from the client by calling
client.stop()

//cleanup resources and close connection once the trading has been finished
client.close()
//do not forget to call .off() for every attached event listener to avoid memory leaks

Swap Estimate

Swap estimates may be handy in scenarios when a client has no intention to trade or receive price quote updates, and just wants to get a single price quote instead.

import {estimateSwap} from '@stellar-broker/client'

estimateSwap({
    sellingAsset: 'xlm',
    buyingAsset: 'USDC-GDK2GNB4Q6FKNW2GNJIQFARI4RMSHV5DN5G4BBXX2F24RT5I4QT7TWZ7',
    sellingAmount: '1000', 
    slippageTolerance: 0.02 //2%
})

Delegated Signing and Multisig

StellarBroker trading sessions rely on fast transactions signing in order to immediately react on market changes. In scenarios when a client app cannot sign transactions directly or requires multisig aggregation, it's still possible to utilize StellarBroker using a mediator account.

Mediator flow implies creation of a temporary auxiliary account that will hold tokens until the swap process is executed in full, then transfers all funds back to the source account and gets merged into it, releasing temporary blocked XLM funds.

This package contains a reference implementation of such mediator account, but it's up to developers whether to use it directly or create alternative logic based on it.

import {Mediator} from '@stellar-broker/client'

const source = 'GDNDS76YATRWMRQ7SGCI7FG3Y4A2MREDSKWDGLEB75IX5W2T25HA4DS3'
const sellingAsset = 'XLM'
const buyingAsset = 'AQUA-GBNZILSTVQZ4R7IKQDGHYGY2QXL5QOFJYQMXPKWRRM5PAV7Y4M67AQUA'
const sellingAmount = '10'

//once the quote received from the server, we can confirm the quote
async function signTx(tx) { //async signing callback - implement custom logic here
    const kp = Keypair.fromSecret('<account_secret>')
    tx.sign(kp)
    return tx
}

//fabric for meditor account creation
const mediator = new Mediator(source, sellingAsset, buyingAsset, sellingAmount, signTx)

//create new mediator account
const mediatorSecret = await mediator.init()
console.log('Created mediator account ' + Keypair.fromSecret(mediatorSecret).publicKey())

//use it for trading, and dispose once finished -- all funds and XLM reserves will be returned to the source account
await mediator.dispose()
console.log('Mediator account disposed')

//if the user left the session in the process or there were connection problems,
//funds from previously created mediator accounts can be recovered like this
if (mediator.hasObsoleteMediators) {
    await mediator.disposeObsoleteMediators()
}
//or using static methods
if (Mediator.hasObsoleteMediators(source)) {
    await Mediator.disposeObsoleteMediators(source, signTx)
}