@d8x/perpetuals-sdk
Version:
Node TypeScript SDK for D8X Perpetual Futures
28 lines (27 loc) • 1.55 kB
TypeScript
export default class Triangulator {
/**
* Find all possible triangulation paths
* @param ccyBase array of base currencies ['BTC', 'ETH', 'MATIC', ...]
* @param ccyQuote array of quote currencies corresponding to base ['USD', 'USD', ...]
* @param pair pair we want to calculate, e.g. BTC-USDC
* @returns array of different paths for which multiplication leads to
* desired pair, e.g. [['MATIC-USD'], ['MATIC-ETH', 'ETH-USD']]
*/
static findPath(ccyBase: string[], ccyQuote: string[], pair: string): Array<Array<string>>;
/**
* Calculate the triangulated price from underlying prices
* @param triangulation triangulation of with symbol and is-inverted flag
* @param feedIdxPrices map of symbol to price
* @returns triangulated price (scalar), true if market closed or price unavailable
*/
static calculateTriangulatedPrice(triangulation: [string[], boolean[]], feedIdxPrices: Map<string, [number, boolean]>): [number, boolean];
/**
* Finds shortest path and returns indices required and whether to divide or not
* @example triangulate BTC-USDC: [ [ 'BTC-USD', 'USDC-USD' ], [ false, true ] ]
* @param ccyArr array of available indices (e.g. from websocket)
* @param symbol symbol we are looking for (e.g. MATIC-USDC)
* @returns shortest path with given indices, array whether we have to divide (true) or multiply
* to arrive at the desired price
*/
static triangulate(ccyArr: string[], symbol: string): [string[], boolean[]];
}