Market Data
MarketData ⇐ PerpetualDataHandler
PerpetualDataHandler
Functions to access market data (e.g., information on open orders, information on products that can be traded). This class requires no private key and is blockchain read-only. No gas required for the queries here.
Kind: global class
Extends: PerpetualDataHandler
MarketData ⇐
PerpetualDataHandler
new MarketData(config)
.createProxyInstance(providerOrMarketData)
.getProxyAddress() ⇒
string
.getTriangulations() ⇒
.smartContractOrderToOrder(smOrder) ⇒
Order
.getReadOnlyProxyInstance() ⇒
Contract
.exchangeInfo() ⇒
ExchangeInfo
.openOrders(traderAddr, symbol) ⇒
.positionRisk(traderAddr, symbol) ⇒
Array.<MarginAccount>
.positionRiskOnTrade(traderAddr, order, account, indexPriceInfo) ⇒
.positionRiskOnCollateralAction(deltaCollateral, account) ⇒
MarginAccount
.getWalletBalance(address, symbol) ⇒
.getPoolShareTokenBalance(address, symbolOrId) ⇒
number
.getShareTokenPrice(symbolOrId) ⇒
number
.getParticipationValue(address, symbolOrId) ⇒
.maxOrderSizeForTrader(traderAddr, symbol) ⇒
.maxSignedPosition(side, symbol) ⇒
number
.getOraclePrice(base, quote) ⇒
number
.getOrderStatus(symbol, orderId, overrides) ⇒
.getOrdersStatus(symbol, orderId) ⇒
.getMarkPrice(symbol) ⇒
number
.getPerpetualPrice(symbol, quantity) ⇒
number
.getPerpetualState(symbol) ⇒
PerpetualState
.getPoolState(poolSymbol) ⇒
PoolState
.getPerpetualStaticInfo(symbol) ⇒
PerpetualStaticInfo
.getPerpetualMidPrice(symbol) ⇒
number
.getAvailableMargin(traderAddr, symbol, indexPrices) ⇒
.getTraderLoyalityScore(traderAddr) ⇒
number
.isMarketClosed(symbol) ⇒
boolean
.getPriceInUSD(symbol) ⇒
Map.<string, number>
.fetchPricesForPerpetual(symbol) ⇒
new MarketData(config)
Constructor
Example
marketData.createProxyInstance(providerOrMarketData)
Initialize the marketData-Class with this function to create instance of D8X perpetual contract and gather information about perpetual currencies
Kind: instance method of MarketData
marketData.getProxyAddress() ⇒ string
string
Get the proxy address
Kind: instance method of MarketData
Returns: string
-
Address of the perpetual proxy contract
marketData.getTriangulations() ⇒
Get the pre-computed triangulations
Kind: instance method of MarketData
Returns:
Triangulations
marketData.smartContractOrderToOrder(smOrder) ⇒ Order
Order
Convert the smart contract output of an order into a convenient format of type "Order"
Kind: instance method of MarketData
Returns: Order
-
more convenient format of order, type "Order"
marketData.getReadOnlyProxyInstance() ⇒ Contract
Contract
Get contract instance. Useful for event listening.
Kind: instance method of MarketData
Returns: Contract
-
read-only proxy instance
Example
marketData.exchangeInfo() ⇒ ExchangeInfo
ExchangeInfo
Information about the products traded in the exchange.
Kind: instance method of MarketData
Returns: ExchangeInfo
-
Array of static data for all the pools and perpetuals in the system.
Example
marketData.openOrders(traderAddr, symbol) ⇒
All open orders for a trader-address and a symbol.
Kind: instance method of MarketData
Returns:
For each perpetual an array of open orders and corresponding order-ids.
Example
marketData.positionRisk(traderAddr, symbol) ⇒ Array.<MarginAccount>
Array.<MarginAccount>
Information about the position open by a given trader in a given perpetual contract, or for all perpetuals in a pool
Kind: instance method of MarketData
Returns: Array.<MarginAccount>
-
Array of position risks of trader.
Example
marketData.positionRiskOnTrade(traderAddr, order, account, indexPriceInfo) ⇒
Estimates what the position risk will be if a given order is executed.
Kind: instance method of MarketData
Returns:
Position risk after trade, including order cost and maximal trade sizes for position
Example
marketData.positionRiskOnCollateralAction(deltaCollateral, account) ⇒ MarginAccount
MarginAccount
Estimates what the position risk will be if given amount of collateral is added/removed from the account.
Kind: instance method of MarketData
Returns: MarginAccount
-
Position risk after collateral has been added/removed
Example
marketData.getWalletBalance(address, symbol) ⇒
Gets the wallet balance in the collateral currency corresponding to a given perpetual symbol.
Kind: instance method of MarketData
Returns:
Perpetual's collateral token balance of the given address.
Example
marketData.getPoolShareTokenBalance(address, symbolOrId) ⇒ number
number
Get the address' balance of the pool share token
Kind: instance method of MarketData
Returns: number
-
Pool share token balance of the given address (e.g. dMATIC balance)
Example
marketData.getShareTokenPrice(symbolOrId) ⇒ number
number
Value of pool token in collateral currency
Kind: instance method of MarketData
Returns: number
-
current pool share token price in collateral currency
Example
marketData.getParticipationValue(address, symbolOrId) ⇒
Value of the pool share tokens for this liquidity provider in poolSymbol-currency (e.g. MATIC, USDC).
Kind: instance method of MarketData
Returns:
the value (in collateral tokens) of the pool share, #share tokens, shareTokenAddress
Example
marketData.maxOrderSizeForTrader(traderAddr, symbol) ⇒
Gets the maximal order sizes to open positions (increase size), both long and short, considering the existing position, state of the perpetual Accounts for user's wallet balance.
Kind: instance method of MarketData
Returns:
Maximal trade sizes
Example
marketData.maxSignedPosition(side, symbol) ⇒ number
number
Perpetual-wide maximal signed position size in perpetual.
Kind: instance method of MarketData
Returns: number
-
signed maximal position size in base currency
Example
marketData.getOraclePrice(base, quote) ⇒ number
number
Uses the Oracle(s) in the exchange to get the latest price of a given index in a given currency, if a route exists.
Kind: instance method of MarketData
Returns: number
-
Price of index in given currency.
Example
marketData.getOrderStatus(symbol, orderId, overrides) ⇒
Get the status of an order given a symbol and order Id
Kind: instance method of MarketData
Returns:
Order status (cancelled = 0, executed = 1, open = 2, unkown = 3)
Example
marketData.getOrdersStatus(symbol, orderId) ⇒
Get the status of an array of orders given a symbol and their Ids
Kind: instance method of MarketData
Returns:
Array of order status
Example
marketData.getMarkPrice(symbol) ⇒ number
number
Get the current mark price
Kind: instance method of MarketData
Returns: number
-
mark price
Example
marketData.getPerpetualPrice(symbol, quantity) ⇒ number
number
get the current price for a given quantity
Kind: instance method of MarketData
Returns: number
-
price
Example
marketData.getPerpetualState(symbol) ⇒ PerpetualState
PerpetualState
Query recent perpetual state from blockchain
Kind: instance method of MarketData
Returns: PerpetualState
-
PerpetualState copy
marketData.getPoolState(poolSymbol) ⇒ PoolState
PoolState
Query recent pool state from blockchain, not including perpetual states
Kind: instance method of MarketData
Returns: PoolState
-
PoolState copy
marketData.getPerpetualStaticInfo(symbol) ⇒ PerpetualStaticInfo
PerpetualStaticInfo
Query perpetual static info. This information is queried once at createProxyInstance-time, and remains static after that.
Kind: instance method of MarketData
Returns: PerpetualStaticInfo
-
Perpetual static info copy.
marketData.getPerpetualMidPrice(symbol) ⇒ number
number
get the current mid-price for a perpetual
Kind: instance method of MarketData
Returns: number
-
price
Example
marketData.getAvailableMargin(traderAddr, symbol, indexPrices) ⇒
Query the available margin conditional on the given (or current) index prices Result is in collateral currency
Kind: instance method of MarketData
Returns:
available margin in collateral currency
Example
marketData.getTraderLoyalityScore(traderAddr) ⇒ number
number
Calculate a type of exchange loyality score based on trader volume
Kind: instance method of MarketData
Returns: number
-
a loyality score (4 worst, 1 best)
Example
marketData.isMarketClosed(symbol) ⇒ boolean
boolean
Get market open/closed status
Kind: instance method of MarketData
Returns: boolean
-
True if the market is closed
Example
marketData.getPriceInUSD(symbol) ⇒ Map.<string, number>
Map.<string, number>
Get the latest on-chain price of a perpetual base index in USD.
Kind: instance method of MarketData
Returns: Map.<string, number>
-
Price of the base index in USD, e.g. for ETH-USDC-MATIC, it returns the value of ETH-USD.
Example
marketData.fetchPricesForPerpetual(symbol) ⇒
Fetch latest off-chain index and collateral prices
Kind: instance method of MarketData
Returns:
Prices and market-closed information