DEX Class


Instances of DEX cannot be constructed manually. They are only accessible as a return value of SDK.init(). Each instance of the DEX class represents a connection to a particular instance of the Portal DEX network for a particular user.

The DEX instance returned by SDK.init() contains no assets. Before any trades are executed on that instance, assets must be transferred into it using DEX.xfer().

Instance Properties

Array = dex.assets

Returns the assets and their quantities currently available. The elements of the Array are Objects with format: { asset: String, qty: Number }.

Instance Methods

Array = dex.xfer( source, assets )

Transfers one or more assets into the receiver from the specified source. Instances of DEX initially contain no assets and this method must be called before any trades are executed.

DEX.xfer() returns an Array whose elements are Objects with format:

   status: String,
   asset: String,
   qty: Number      // quantity actually in wallet

trade = order_id, order_type, goals,
                   sell_asset, sell_qty,
                   buy_asset,  buy_qty )

Performs a swap of the specified assets under the specified conditions. Returns an instance of the Trade class. Will throw an exception if there are any errors in the arguments - thus it is advisable to call this function in a try/catch block.

Boolean = dex.close()

Close the connection to receiver. Returns true if successful else false.

trade = dex.find( order_id )

Returns the instance of Trade with the specified order_id or undefined if no trade with that order_id was executed on the receiver.

Array = dex.history()

Last updated