Functions to create, submit and cancel orders on the exchange. This class requires a private key and executes smart-contract interactions that require gas-payments.
import { AccountTrade, PerpetualDataHandler } from'@d8x/perpetuals-sdk';asyncfunctionmain() {console.log(AccountTrade);// load configuration for Polygon zkEVM Tesnetconstconfig=PerpetualDataHandler.readSDKConfig("cardona");// AccountTrade (authentication required, PK is an environment variable with a private key)constpk:string= <string>process.env.PK; let accTrade = new AccountTrade(config, pk); // Create a proxy instance to access the blockchain await accTrade.createProxyInstance();}main();
Kind: instance method of AccountTradeReturns: ContractTransaction -
Contract Transaction (containing events).
Example
import { AccountTrade, PerpetualDataHandler, Order } from'@d8x/perpetuals-sdk';asyncfunctionmain() {console.log(AccountTrade);// setup (authentication required, PK is an environment variable with a private key)constconfig=PerpetualDataHandler.readSDKConfig("cardona");constpk:string= <string>process.env.PK; let accTrade = new AccountTrade(config, pk); await accTrade.createProxyInstance(); // cancel order let cancelTransaction = accTrade.cancelOrder("MATIC-USD-MATIC", "0x4639061a58dcf34f4c9c703f49f1cb00d6a4fba490d62c0eb4a4fb06e1c76c19") console.log(cancelTransaction); } main();
accountTrade.order(order) ⇒ ContractTransaction
Submits an order to the exchange.
Kind: instance method of AccountTradeReturns: ContractTransaction -
Contract Transaction (containing events).
Example
import { AccountTrade, PerpetualDataHandler, Order } from'@d8x/perpetuals-sdk';asyncfunctionmain() {console.log(AccountTrade);// setup (authentication required, PK is an environment variable with a private key)constconfig=PerpetualDataHandler.readSDKConfig("cardona");constpk:string= <string>process.env.PK; const accTrade = new AccountTrade(config, pk); await accTrade.createProxyInstance(); // set allowance await accTrade.setAllowance("MATIC"); // set an order const order: Order = { symbol: "MATIC-USD-MATIC", side: "BUY", type: "MARKET", quantity: 100, leverage: 2, executionTimestamp: Date.now()/1000, }; const orderTransaction = await accTrade.order(order); console.log(orderTransaction); } main();
Fee charged by the exchange for trading any perpetual on a given pool. It accounts for the current trader's fee tier (based on the trader's D8X balance and trading volume). If trading with a broker, it also accounts for the selected broker's fee tier. Note that this result only includes exchange fees, additional broker fees are not included.
Kind: instance method of AccountTradeReturns:
Exchange fee, in decimals (i.e. 0.1% is 0.001).
Example
import { AccountTrade, PerpetualDataHandler } from'@d8x/perpetuals-sdk';asyncfunctionmain() {console.log(AccountTrade);// setup (authentication required, PK is an environment variable with a private key)constconfig=PerpetualDataHandler.readSDKConfig("cardona");constpk:string= <string>process.env.PK; let accTrade = new AccountTrade(config, pk); await accTrade.createProxyInstance(); // query exchange fee let fees = await accTrade.queryExchangeFee("MATIC"); console.log(fees);}main();
accountTrade.getCurrentTraderVolume(poolSymbolName) ⇒ number
Exponentially weighted EMA of the total USD trading volume of all trades performed by this trader. The weights are chosen so that in average this coincides with the 30 day volume.
Kind: instance method of AccountTradeReturns: number -
Current trading volume for this trader, in USD.
Example
import { AccountTrade, PerpetualDataHandler } from'@d8x/perpetuals-sdk';asyncfunctionmain() {console.log(AccountTrade);// setup (authentication required, PK is an environment variable with a private key)constconfig=PerpetualDataHandler.readSDKConfig("cardona");constpk:string= <string>process.env.PK; let accTrade = new AccountTrade(config, pk); await accTrade.createProxyInstance(); // query 30 day volume let vol = await accTrade.getCurrentTraderVolume("MATIC"); console.log(vol);}main();
accountTrade.getOrderIds(symbol) ⇒ Array.<string>
Kind: instance method of AccountTradeReturns: Array.<string> -
Array of Ids for all the orders currently open by this trader.
Example
import { AccountTrade, PerpetualDataHandler } from'@d8x/perpetuals-sdk';asyncfunctionmain() {console.log(AccountTrade);// setup (authentication required, PK is an environment variable with a private key)constconfig=PerpetualDataHandler.readSDKConfig("cardona");constpk:string= <string>process.env.PK; let accTrade = new AccountTrade(config, pk); await accTrade.createProxyInstance(); // get order IDs let orderIds = await accTrade.getOrderIds("MATIC-USD-MATIC"); console.log(orderIds);}main();
accountTrade.addCollateral(symbol, amount)
Kind: instance method of AccountTrade
Example
import { AccountTrade, PerpetualDataHandler } from'@d8x/perpetuals-sdk';asyncfunctionmain() {// setup (authentication required, PK is an environment variable with a private key)constconfig=PerpetualDataHandler.readSDKConfig("cardona");constpk:string= <string>process.env.PK; let accTrade = new AccountTrade(config, pk); await accTrade.createProxyInstance(); // add collateral to margin account const tx = await accTrade.addCollateral("MATIC-USD-MATIC", 10.9); console.log(orderIds);}main();
accountTrade.removeCollateral(symbol, amount)
Kind: instance method of AccountTrade
Example
import { AccountTrade, PerpetualDataHandler } from'@d8x/perpetuals-sdk';asyncfunctionmain() {// setup (authentication required, PK is an environment variable with a private key)constconfig=PerpetualDataHandler.readSDKConfig("cardona");constpk:string= <string>process.env.PK; let accTrade = new AccountTrade(config, pk); await accTrade.createProxyInstance(); // remove collateral from margin account const tx = await accTrade.removeCollateral("MATIC-USD-MATIC", 3.14); console.log(orderIds);}main();
Param
Type
Description
Param
Type
Description
Param
Type
Description
Param
Type
Description
Param
Type
Description
Param
Description
Param
Type
Description
Param
Type
Description
config
NodeSDKConfig
Configuration object, see PerpetualDataHandler. readSDKConfig.
signer
string | Signer
Private key or ethers Signer of the account
symbol
string
Symbol of the form ETH-USD-MATIC.
orderId
string
ID of the order to be cancelled.
order
Order
Order structure. As a minimum the structure needs to specify symbol, side, type and quantity.
poolSymbolName
string
Pool symbol name (e.g. MATIC, USDC, etc).
[brokerAddr]
string
Optional address of a broker this trader may use to trade under.
poolSymbolName
string
Pool symbol name (e.g. MATIC, USDC, etc).
symbol
Symbol of the form ETH-USD-MATIC.
symbol
string
Symbol of the form ETH-USD-MATIC.
amount
number
How much collateral to add, in units of collateral currency, e.g. MATIC
symbol
string
Symbol of the form ETH-USD-MATIC.
amount
number
How much collateral to remove, in units of collateral currency, e.g. MATIC