DEX Class

Constructor

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.

ArgumentType and Semantics

source

Object. Specifies the source of the assets and the parameters necessary for transferring them. Format depends on the source.

assets

Array. Specifies quantities of assets to transfer. The elements of the Array are Objects with format: { asset: String, qty: Number }

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

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

trade = dex.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.

ArgumentType and semantics

order_id

String (case sensitive). A user-defined identifier of this trade. Stored in the instance and returned on every method call to that instance.

order_type

String (case insensitive). One of: "limit" or "market".

goals

Object.

sell_asset, buy_asset

String (case insensitive). One of: "BTC" or "ETH".

sell_qty, buy_qty

Number

sell_ctx, buy_ctx

Object. Format is dependent on the values of order_type, sell_asset, and buy_asset.

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