update sdk to use mm oracle
This commit is contained in:
@@ -13,7 +13,7 @@ import {
|
|||||||
PerpOperation,
|
PerpOperation,
|
||||||
PositionDirection,
|
PositionDirection,
|
||||||
ZERO,
|
ZERO,
|
||||||
calculateAMMBidAskPrice,
|
calculateBidAskPrice,
|
||||||
getLimitPrice,
|
getLimitPrice,
|
||||||
isOperationPaused,
|
isOperationPaused,
|
||||||
isVariant,
|
isVariant,
|
||||||
@@ -151,7 +151,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
try {
|
try {
|
||||||
if (this.indicativeQuotesRedisClient) {
|
if (this.indicativeQuotesRedisClient) {
|
||||||
const oraclePriceData = isVariant(marketArgs.marketType, 'perp')
|
const oraclePriceData = isVariant(marketArgs.marketType, 'perp')
|
||||||
? this.driftClient.getOracleDataForPerpMarket(
|
? this.driftClient.getMMOracleDataForPerpMarket(
|
||||||
marketArgs.marketIndex
|
marketArgs.marketIndex
|
||||||
)
|
)
|
||||||
: this.driftClient.getOracleDataForSpotMarket(
|
: this.driftClient.getOracleDataForSpotMarket(
|
||||||
@@ -160,13 +160,17 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
const bestDlobBid = dlob.getBestBid(
|
const bestDlobBid = dlob.getBestBid(
|
||||||
marketArgs.marketIndex,
|
marketArgs.marketIndex,
|
||||||
this.slotSource.getSlot(),
|
this.slotSource.getSlot(),
|
||||||
marketArgs.marketType,
|
isVariant(marketArgs.marketType, 'perp')
|
||||||
|
? MarketType.PERP
|
||||||
|
: MarketType.SPOT,
|
||||||
oraclePriceData
|
oraclePriceData
|
||||||
);
|
);
|
||||||
const bestDlobAsk = dlob.getBestAsk(
|
const bestDlobAsk = dlob.getBestAsk(
|
||||||
marketArgs.marketIndex,
|
marketArgs.marketIndex,
|
||||||
this.slotSource.getSlot(),
|
this.slotSource.getSlot(),
|
||||||
marketArgs.marketType,
|
isVariant(marketArgs.marketType, 'perp')
|
||||||
|
? MarketType.PERP
|
||||||
|
: MarketType.SPOT,
|
||||||
oraclePriceData
|
oraclePriceData
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -177,7 +181,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
let bestBid = bestDlobBid;
|
let bestBid = bestDlobBid;
|
||||||
let bestAsk = bestDlobAsk;
|
let bestAsk = bestDlobAsk;
|
||||||
if (marketType === 'perp') {
|
if (marketType === 'perp') {
|
||||||
const [bestVammBid, bestVammAsk] = calculateAMMBidAskPrice(
|
const [bestVammBid, bestVammAsk] = calculateBidAskPrice(
|
||||||
this.driftClient.getPerpMarketAccount(marketArgs.marketIndex).amm,
|
this.driftClient.getPerpMarketAccount(marketArgs.marketIndex).amm,
|
||||||
this.driftClient.getMMOracleDataForPerpMarket(
|
this.driftClient.getMMOracleDataForPerpMarket(
|
||||||
marketArgs.marketIndex
|
marketArgs.marketIndex
|
||||||
@@ -269,7 +273,8 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
indicativeBid,
|
indicativeBid,
|
||||||
INDICATIVE_QUOTES_PUBKEY,
|
INDICATIVE_QUOTES_PUBKEY,
|
||||||
this.slotSource.getSlot(),
|
this.slotSource.getSlot(),
|
||||||
false
|
false,
|
||||||
|
indicativeBid.baseAssetAmount
|
||||||
);
|
);
|
||||||
indicativeOrderId += 1;
|
indicativeOrderId += 1;
|
||||||
}
|
}
|
||||||
@@ -304,7 +309,8 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
indicativeAsk,
|
indicativeAsk,
|
||||||
INDICATIVE_QUOTES_PUBKEY,
|
INDICATIVE_QUOTES_PUBKEY,
|
||||||
this.slotSource.getSlot(),
|
this.slotSource.getSlot(),
|
||||||
false
|
false,
|
||||||
|
indicativeAsk.baseAssetAmount
|
||||||
);
|
);
|
||||||
indicativeOrderId += 1;
|
indicativeOrderId += 1;
|
||||||
}
|
}
|
||||||
@@ -471,7 +477,9 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
const bids = this.dlob
|
const bids = this.dlob
|
||||||
.getBestMakers({
|
.getBestMakers({
|
||||||
marketIndex: marketArgs.marketIndex,
|
marketIndex: marketArgs.marketIndex,
|
||||||
marketType: marketArgs.marketType,
|
marketType: isVariant(marketArgs.marketType, 'perp')
|
||||||
|
? MarketType.PERP
|
||||||
|
: MarketType.SPOT,
|
||||||
direction: PositionDirection.LONG,
|
direction: PositionDirection.LONG,
|
||||||
slot: slot,
|
slot: slot,
|
||||||
oraclePriceData: oracleData,
|
oraclePriceData: oracleData,
|
||||||
@@ -481,7 +489,9 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
const asks = this.dlob
|
const asks = this.dlob
|
||||||
.getBestMakers({
|
.getBestMakers({
|
||||||
marketIndex: marketArgs.marketIndex,
|
marketIndex: marketArgs.marketIndex,
|
||||||
marketType: marketArgs.marketType,
|
marketType: isVariant(marketArgs.marketType, 'perp')
|
||||||
|
? MarketType.PERP
|
||||||
|
: MarketType.SPOT,
|
||||||
direction: PositionDirection.SHORT,
|
direction: PositionDirection.SHORT,
|
||||||
slot,
|
slot,
|
||||||
oraclePriceData: oracleData,
|
oraclePriceData: oracleData,
|
||||||
|
|||||||
12
src/index.ts
12
src/index.ts
@@ -22,6 +22,7 @@ import {
|
|||||||
PRICE_PRECISION_EXP,
|
PRICE_PRECISION_EXP,
|
||||||
MarketTypeStr,
|
MarketTypeStr,
|
||||||
AssetType,
|
AssetType,
|
||||||
|
MarketType,
|
||||||
} from '@drift-labs/sdk';
|
} from '@drift-labs/sdk';
|
||||||
import { RedisClient, RedisClientPrefix } from '@drift/common/clients';
|
import { RedisClient, RedisClientPrefix } from '@drift/common/clients';
|
||||||
|
|
||||||
@@ -384,7 +385,8 @@ const main = async (): Promise<void> => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const normedSide = (side as string).toLowerCase();
|
const normedSide = (side as string).toLowerCase();
|
||||||
const oracle = driftClient.getOracleDataForPerpMarket(normedMarketIndex);
|
const oracle =
|
||||||
|
driftClient.getMMOracleDataForPerpMarket(normedMarketIndex);
|
||||||
|
|
||||||
let normedLimit = undefined;
|
let normedLimit = undefined;
|
||||||
if (limit) {
|
if (limit) {
|
||||||
@@ -469,7 +471,9 @@ const main = async (): Promise<void> => {
|
|||||||
.getRestingLimitBids(
|
.getRestingLimitBids(
|
||||||
normedMarketIndex,
|
normedMarketIndex,
|
||||||
dlobProvider.getSlot(),
|
dlobProvider.getSlot(),
|
||||||
normedMarketType,
|
isVariant(normedMarketType, 'perp')
|
||||||
|
? MarketType.PERP
|
||||||
|
: MarketType.SPOT,
|
||||||
oracle
|
oracle
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -480,7 +484,9 @@ const main = async (): Promise<void> => {
|
|||||||
.getRestingLimitAsks(
|
.getRestingLimitAsks(
|
||||||
normedMarketIndex,
|
normedMarketIndex,
|
||||||
dlobProvider.getSlot(),
|
dlobProvider.getSlot(),
|
||||||
normedMarketType,
|
isVariant(normedMarketType, 'perp')
|
||||||
|
? MarketType.PERP
|
||||||
|
: MarketType.SPOT,
|
||||||
oracle
|
oracle
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import { program } from 'commander';
|
|
||||||
|
|
||||||
import { Connection, Commitment, PublicKey, Keypair } from '@solana/web3.js';
|
import { Connection, Commitment, PublicKey, Keypair } from '@solana/web3.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -101,7 +99,6 @@ metricsV2.finalizeObservables();
|
|||||||
const sdkConfig = initialize({ env: process.env.ENV });
|
const sdkConfig = initialize({ env: process.env.ENV });
|
||||||
let driftClient: DriftClient;
|
let driftClient: DriftClient;
|
||||||
|
|
||||||
const opts = program.opts();
|
|
||||||
setLogLevel('debug');
|
setLogLevel('debug');
|
||||||
|
|
||||||
const useGrpc = process.env.USE_GRPC?.toLowerCase() === 'true';
|
const useGrpc = process.env.USE_GRPC?.toLowerCase() === 'true';
|
||||||
@@ -709,7 +706,8 @@ const main = async () => {
|
|||||||
const dlob = await dlobProvider.getDLOB(slot);
|
const dlob = await dlobProvider.getDLOB(slot);
|
||||||
|
|
||||||
// Get oracle data for the market
|
// Get oracle data for the market
|
||||||
const oracleData = driftClient.getOracleDataForPerpMarket(marketIndex);
|
const oracleData =
|
||||||
|
driftClient.getMMOracleDataForPerpMarket(marketIndex);
|
||||||
|
|
||||||
// Get L3 orderbook to check TOB
|
// Get L3 orderbook to check TOB
|
||||||
const l3OrderBook = dlob.getL3({
|
const l3OrderBook = dlob.getL3({
|
||||||
|
|||||||
Reference in New Issue
Block a user