@drift-labs/sdk
Advanced tools
Comparing version 2.11.0 to 2.12.0-beta.0
@@ -67,3 +67,18 @@ /// <reference types="bn.js" /> | ||
getLimitAsks(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): Generator<DLOBNode>; | ||
/** | ||
* Filters the limit asks that are post only or have been place for sufficiently long | ||
* Useful for displaying order book that doesn't have taker limit orders crossing spread | ||
* | ||
* @returns | ||
*/ | ||
getRestingLimitAsks(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, minPerpAuctionDuration: number): Generator<DLOBNode>; | ||
isRestingLimitOrder(order: Order, slot: number, minPerpAuctionDuration: number): boolean; | ||
getLimitBids(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): Generator<DLOBNode>; | ||
/** | ||
* Filters the limit bids that are post only or have been place for sufficiently long | ||
* Useful for displaying order book that doesn't have taker limit orders crossing spread | ||
* | ||
* @returns | ||
*/ | ||
getRestingLimitBids(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, minPerpAuctionDuration: number): Generator<DLOBNode>; | ||
getAsks(marketIndex: number, fallbackAsk: BN | undefined, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): Generator<DLOBNode>; | ||
@@ -70,0 +85,0 @@ getBids(marketIndex: number, fallbackBid: BN | undefined, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): Generator<DLOBNode>; |
@@ -538,2 +538,19 @@ "use strict"; | ||
} | ||
/** | ||
* Filters the limit asks that are post only or have been place for sufficiently long | ||
* Useful for displaying order book that doesn't have taker limit orders crossing spread | ||
* | ||
* @returns | ||
*/ | ||
*getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData, minPerpAuctionDuration) { | ||
for (const node of this.getLimitAsks(marketIndex, slot, marketType, oraclePriceData)) { | ||
if (this.isRestingLimitOrder(node.order, slot, minPerpAuctionDuration)) { | ||
yield node; | ||
} | ||
} | ||
} | ||
isRestingLimitOrder(order, slot, minPerpAuctionDuration) { | ||
return (order.postOnly || | ||
new __1.BN(slot).sub(order.slot).gte(new __1.BN(minPerpAuctionDuration * 1.5))); | ||
} | ||
*getLimitBids(marketIndex, slot, marketType, oraclePriceData) { | ||
@@ -556,2 +573,15 @@ if ((0, __1.isVariant)(marketType, 'spot') && !oraclePriceData) { | ||
} | ||
/** | ||
* Filters the limit bids that are post only or have been place for sufficiently long | ||
* Useful for displaying order book that doesn't have taker limit orders crossing spread | ||
* | ||
* @returns | ||
*/ | ||
*getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData, minPerpAuctionDuration) { | ||
for (const node of this.getLimitBids(marketIndex, slot, marketType, oraclePriceData)) { | ||
if (this.isRestingLimitOrder(node.order, slot, minPerpAuctionDuration)) { | ||
yield node; | ||
} | ||
} | ||
} | ||
*getAsks(marketIndex, fallbackAsk, slot, marketType, oraclePriceData) { | ||
@@ -558,0 +588,0 @@ if ((0, __1.isVariant)(marketType, 'spot') && !oraclePriceData) { |
@@ -39,4 +39,3 @@ "use strict"; | ||
programID: driftPublicKey, | ||
perpMarketIndexes: __2.PerpMarkets[cluster].map((market) => market.marketIndex), | ||
spotMarketIndexes: spotMarkets_1.SpotMarkets[cluster].map((spotMarket) => spotMarket.marketIndex), | ||
...(0, __2.getMarketsAndOraclesForSubscription)(cluster), | ||
accountSubscription: { | ||
@@ -73,3 +72,3 @@ type: 'polling', | ||
const longAmount = new anchor_1.BN(5000).mul(__2.QUOTE_PRECISION); | ||
const slippage = (0, __2.convertToNumber)((0, __2.calculateTradeSlippage)(__2.PositionDirection.LONG, longAmount, solMarketAccount, 'quote', undefined)[0], __2.PRICE_PRECISION); | ||
const slippage = (0, __2.convertToNumber)((0, __2.calculateTradeSlippage)(__2.PositionDirection.LONG, longAmount, solMarketAccount, 'quote', driftClient.getOracleDataForPerpMarket(solMarketInfo.marketIndex))[0], __2.PRICE_PRECISION); | ||
console.log(`Slippage for a $5000 LONG on the SOL market would be $${slippage}`); | ||
@@ -76,0 +75,0 @@ // Make a $5000 LONG trade |
@@ -24,3 +24,3 @@ /// <reference types="bn.js" /> | ||
*/ | ||
export declare function calculateTradeSlippage(direction: PositionDirection, amount: BN, market: PerpMarketAccount, inputAssetType?: AssetType, oraclePriceData?: OraclePriceData, useSpread?: boolean): [BN, BN, BN, BN]; | ||
export declare function calculateTradeSlippage(direction: PositionDirection, amount: BN, market: PerpMarketAccount, inputAssetType: AssetType, oraclePriceData: OraclePriceData, useSpread?: boolean): [BN, BN, BN, BN]; | ||
/** | ||
@@ -27,0 +27,0 @@ * Calculates acquired amounts for trade executed |
{ | ||
"name": "@drift-labs/sdk", | ||
"version": "2.11.0", | ||
"version": "2.12.0-beta.0", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "types": "lib/index.d.ts", |
@@ -918,2 +918,38 @@ import { getOrderSignature, getVammNodeGenerator, NodeList } from './NodeList'; | ||
/** | ||
* Filters the limit asks that are post only or have been place for sufficiently long | ||
* Useful for displaying order book that doesn't have taker limit orders crossing spread | ||
* | ||
* @returns | ||
*/ | ||
*getRestingLimitAsks( | ||
marketIndex: number, | ||
slot: number, | ||
marketType: MarketType, | ||
oraclePriceData: OraclePriceData, | ||
minPerpAuctionDuration: number | ||
): Generator<DLOBNode> { | ||
for (const node of this.getLimitAsks( | ||
marketIndex, | ||
slot, | ||
marketType, | ||
oraclePriceData | ||
)) { | ||
if (this.isRestingLimitOrder(node.order, slot, minPerpAuctionDuration)) { | ||
yield node; | ||
} | ||
} | ||
} | ||
isRestingLimitOrder( | ||
order: Order, | ||
slot: number, | ||
minPerpAuctionDuration: number | ||
): boolean { | ||
return ( | ||
order.postOnly || | ||
new BN(slot).sub(order.slot).gte(new BN(minPerpAuctionDuration * 1.5)) | ||
); | ||
} | ||
*getLimitBids( | ||
@@ -951,2 +987,27 @@ marketIndex: number, | ||
/** | ||
* Filters the limit bids that are post only or have been place for sufficiently long | ||
* Useful for displaying order book that doesn't have taker limit orders crossing spread | ||
* | ||
* @returns | ||
*/ | ||
*getRestingLimitBids( | ||
marketIndex: number, | ||
slot: number, | ||
marketType: MarketType, | ||
oraclePriceData: OraclePriceData, | ||
minPerpAuctionDuration: number | ||
): Generator<DLOBNode> { | ||
for (const node of this.getLimitBids( | ||
marketIndex, | ||
slot, | ||
marketType, | ||
oraclePriceData | ||
)) { | ||
if (this.isRestingLimitOrder(node.order, slot, minPerpAuctionDuration)) { | ||
yield node; | ||
} | ||
} | ||
} | ||
*getAsks( | ||
@@ -953,0 +1014,0 @@ marketIndex: number, |
@@ -14,3 +14,3 @@ import { AnchorProvider, BN } from '@project-serum/anchor'; | ||
BulkAccountLoader, | ||
PerpMarkets, | ||
getMarketsAndOraclesForSubscription, | ||
PRICE_PRECISION, | ||
@@ -78,6 +78,3 @@ QUOTE_PRECISION, | ||
programID: driftPublicKey, | ||
perpMarketIndexes: PerpMarkets[cluster].map((market) => market.marketIndex), | ||
spotMarketIndexes: SpotMarkets[cluster].map( | ||
(spotMarket) => spotMarket.marketIndex | ||
), | ||
...getMarketsAndOraclesForSubscription(cluster), | ||
accountSubscription: { | ||
@@ -144,3 +141,3 @@ type: 'polling', | ||
'quote', | ||
undefined | ||
driftClient.getOracleDataForPerpMarket(solMarketInfo.marketIndex) | ||
)[0], | ||
@@ -147,0 +144,0 @@ PRICE_PRECISION |
@@ -64,3 +64,3 @@ import { PerpMarketAccount, PositionDirection } from '../types'; | ||
inputAssetType: AssetType = 'quote', | ||
oraclePriceData?: OraclePriceData, | ||
oraclePriceData: OraclePriceData, | ||
useSpread = true | ||
@@ -67,0 +67,0 @@ ): [BN, BN, BN, BN] { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1788796
55847
1