AlgodexApi

AlgodexApi

# new AlgodexApi(props)

📦 AlgodexAPI

The API requires several services to operate. These include but are not limited to ExplorerClient, Algodv2, Indexer, and AlgodexClient. This constructor allows for easy use of the underlying smart contract teal.

See setWallet and placeOrder for more details

Parameters:
Name Type Description
props APIProperties

API Constructor Properties

Throws:
Errors.ValidationError
Example
// Create the API
const config = require('./config.js')
const api = new AlgodexAPI({config})

// Configure Wallet
await api.setWallet({
  address: "TESTWALLET",
  type: "my-algo-wallet",
  connector: MyAlgoWallet
})

// Placing an Order
await api.placeOrder({
  type: "buy",
  amount: 100,
  asset: {id: 123456}
})

Members

# algod :Algodv2

Type:
  • Algodv2

# asset :Asset

âš™ asset

Current asset. Use AlgodexApi#setAsset to update

Type:

# isInitialized :boolean

✔ isInitialized

Flag for having a valid configuration

Type:
  • boolean

# wallet :Wallet

👛 wallet

Current wallet. Use AlgodexApi#setWallet to update

Type:

Methods

# closeOrder(order, callbackFn) → {Promise.<function(*): *>}

Close An Existing Order

Parameters:
Name Type Description
order Order
callbackFn function
Returns:
Type
Promise.<function(*): *>

# getAppId(order) → {number}

getAppId

Fetches the application ID for the current order

Parameters:
Name Type Description
order Order

The User Order

Returns:
Type
number

# getIsExistingEscrow(order, orderbookopt) → {Promise.<boolean>}

Parameters:
Name Type Attributes Description
order Order

Order to check

orderbook Array.<Order> <optional>

The Orderbook

Returns:
Type
Promise.<boolean>

# placeOrder(_order, optionsopt, callbackFn)

💱 Place Order

Execute an Order in Algodex. See Order for details of what order types are supported

Parameters:
Name Type Attributes Description
_order Order
options Object <optional>
Properties
Name Type Attributes Description
wallet Wallet <optional>
orderbook Array <optional>
callbackFn function
To Do:
  • Add Order Logic
Throws:

Errors.ValidationError

# setAsset(asset, optionsopt)

âš™ Set Asset

Changes the current asset. This method is also run when an Asset is passed to the constructor of AlgodexApi.

Parameters:
Name Type Attributes Description
asset Asset

Algorand Asset

options SetterOptions <optional>

Options for setting

Fires:
  • AlgodexApi#event:AssetEvent
Throws:

ValidationError

Examples
// Assign during construction
const api = new AlgodexAPI({config, asset: {id: 123456}})
// Dynamically configure Asset
api.setAsset({
  id: 123456
})

# setConfig(config, optionsopt)

âš™ Set Config

Override the current configuration. This is a manditory operation for the use of AlgodexApi. It is run when a Config is passed to the constructor of AlgodexApi or when a consumer updates an instance of the AlgodexApi

Parameters:
Name Type Attributes Description
config Config

Configuration Object

options SetterOptions <optional>

Options for setting

To Do:
  • Add Application IDs
Fires:
  • AlgodexApi#event:InitEvent
Throws:

ValidationError

Example
let algodex = new Algodex({wallet, asset, config})
algodex.setConfig(newConfig)

# setWallet(_wallet, optionsopt)

âš™ Set Wallet

Configure the current wallet.

Parameters:
Name Type Attributes Description
_wallet Wallet
options SetterOptions <optional>

Options for setting

Throws:

ValidationError

Events

# OrderEvent

âš¡ Order Event

Fires during order operations

Type:
  • Object
Properties
Name Type Description
type string

Type of Event

asset Order

Order Data

# WalletEvent

âš¡ Wallet Event

Fires during wallet operations

Type:
  • Object
Properties
Name Type Description
type string

Type of Event

wallet Wallet

Wallet Data