#
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
#
isInitialized :boolean
✔ isInitialized
Flag for having a valid configuration
Methods
#
closeOrder(order) → {Promise.<function(*): *>}
Parameters:
Name |
Type |
Description |
order |
Order
|
|
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 |
#
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)
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>
|
|
|
#
setAsset(asset, optionsopt)
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
Examples
// Assign during construction
const api = new AlgodexAPI({config, asset: {id: 123456}})
// Dynamically configure Asset
api.setAsset({
id: 123456
})
#
setConfig(config, optionsopt)
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 |
Fires:
- AlgodexApi#event:InitEvent
Example
let algodex = new Algodex({wallet, asset, config})
algodex.setConfig(newConfig)
#
setWallet(_wallet, optionsopt)
Configure the current wallet.
Parameters:
Name |
Type |
Attributes |
Description |
_wallet |
Wallet
|
|
|
options |
SetterOptions
|
<optional>
|
Options for setting |
Events
#
OrderEvent
Fires during order operations
Properties
Name |
Type |
Description |
type |
string
|
Type of Event |
asset |
Order
|
Order Data |
#
WalletEvent
Fires during wallet operations
Properties
Name |
Type |
Description |
type |
string
|
Type of Event |
wallet |
Wallet
|
Wallet Data |