Skip to content

Instantly share code, notes, and snippets.

@wphan
Created March 20, 2024 06:52
Show Gist options
  • Save wphan/61b261cb6ca15be4d317048136d9759b to your computer and use it in GitHub Desktop.
Save wphan/61b261cb6ca15be4d317048136d9759b to your computer and use it in GitHub Desktop.
Minimal AuctionSubscriber Example
import {
DriftClient,
AuctionSubscriber,
Wallet,
DRIFT_PROGRAM_ID,
} from '@drift-labs/sdk'
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
const main = async () => {
const connection = new Connection("ur own working rpc");
const driftClient = new DriftClient({
connection,
wallet: new Wallet(new Keypair()),
programID: new PublicKey(DRIFT_PROGRAM_ID),
accountSubscription: {
type: 'websocket'
},
env: 'mainnet-beta',
});
await driftClient.subscribe();
const auctionSubscriber = new AuctionSubscriber({driftClient});
await auctionSubscriber.subscribe();
auctionSubscriber.eventEmitter.on('onAccountUpdate', (auction) => {
console.log(auction);
});
while (true) {
await new Promise(resolve => setTimeout(resolve, 1000));
}
}
main().then(() => {
process.exit(0)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment