Skip to content

Commit

Permalink
lint & format
Browse files Browse the repository at this point in the history
  • Loading branch information
mschneider committed Mar 13, 2024
1 parent 7a640f2 commit 999e071
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 35 deletions.
23 changes: 18 additions & 5 deletions ts/client/src/accounts/openOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ export class OpenOrders {
});
}

public async cancelOrder(order: Order | { clientOrderId: number }): Promise<string> {

public async cancelOrder(
order: Order | { clientOrderId: number },
): Promise<string> {
const ixs: TransactionInstruction[] = [];
if ("clientOrderId" in order) {
if ('clientOrderId' in order) {
const id = new BN(order.clientOrderId);
const [ix] = await this.cancelOrderByClientIdIx(id);
ixs.push(ix);
Expand Down Expand Up @@ -348,11 +349,23 @@ export class OpenOrders {
}

public async cancelOrderByIdIx(id: BN) {
return this.market.client.cancelOrderByIdIx(this.pubkey, this.account, this.market.account, id, this.delegate);
return this.market.client.cancelOrderByIdIx(
this.pubkey,
this.account,
this.market.account,
id,
this.delegate,
);
}

public async cancelOrderByClientIdIx(id: BN) {
return this.market.client.cancelOrderByClientIdIx(this.pubkey, this.account, this.market.account, id, this.delegate);
return this.market.client.cancelOrderByClientIdIx(
this.pubkey,
this.account,
this.market.account,
id,
this.delegate,
);
}

public async settleFundsIx(
Expand Down
4 changes: 2 additions & 2 deletions ts/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ export class OpenBookV2Client {
orderType: PlaceOrderType,
bids: PlaceMultipleOrdersArgs[],
asks: PlaceMultipleOrdersArgs[],
limit: number = 12,
limit = 12,
openOrdersDelegate?: Keypair,
): Promise<[TransactionInstruction, Signer[]]> {
const ix = await this.program.methods
Expand Down Expand Up @@ -777,7 +777,7 @@ export class OpenBookV2Client {
orderType: PlaceOrderType,
bids: PlaceMultipleOrdersArgs[],
asks: PlaceMultipleOrdersArgs[],
limit: number = 12,
limit = 12,
openOrdersDelegate?: Keypair,
): Promise<[TransactionInstruction, Signer[]]> {
const ix = await this.program.methods
Expand Down
6 changes: 5 additions & 1 deletion ts/client/src/structs/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export class Order {
}

public toPrettyString(): string {
return `side:${this.side === SideUtils.Bid ? 'bid' : 'ask'} price:${this.price} size:${this.size} seqNum:${this.seqNum.toString()} expired:${this.isExpired}`;
return `side:${this.side === SideUtils.Bid ? 'bid' : 'ask'} price:${
this.price
} size:${this.size} seqNum:${this.seqNum.toString()} expired:${
this.isExpired
}`;
}
}
4 changes: 2 additions & 2 deletions ts/client/src/test/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
findAllMarkets,
initReadOnlyOpenbookClient,
Watcher,
sleep
sleep,
} from '..';

async function testFindAccountsByMints(): Promise<void> {
Expand Down Expand Up @@ -62,4 +62,4 @@ async function testWatchMarket(): Promise<void> {
// void testFindAccountsByMints();
// void testFindAllMarkets();
// void testDecodeMarket();
void testWatchMarket();
void testWatchMarket();
3 changes: 1 addition & 2 deletions ts/client/src/test/openOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ async function testPlaceAndCancelOrder(): Promise<void> {
console.log('cancelled order', sigCancel);
}


async function testPlaceAndCancelOrderByClientId(): Promise<void> {
const client = initOpenbookClient();
const marketPk = new PublicKey(
Expand All @@ -85,7 +84,7 @@ async function testPlaceAndCancelOrderByClientId(): Promise<void> {

console.log('placed order', sigPlace);

const sigCancel = await oo?.cancelOrder({clientOrderId: 9999});
const sigCancel = await oo?.cancelOrder({ clientOrderId: 9999 });

console.log('cancelled order', sigCancel);
}
Expand Down
10 changes: 4 additions & 6 deletions ts/client/src/utils/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export async function sendTransaction(
opts: any = {},
): Promise<string> {
const connection = provider.connection;
const additionalSigners = opts?.additionalSigners || [];

if ((connection as any).banksClient !== undefined) {
const tx = new Transaction();
Expand All @@ -28,7 +29,7 @@ export async function sendTransaction(
connection as any
).banksClient.getLatestBlockhash();

for (const signer of opts?.additionalSigners) {
for (const signer of additionalSigners) {
tx.partialSign(signer);
}

Expand Down Expand Up @@ -58,11 +59,8 @@ export async function sendTransaction(
});
let vtx = new VersionedTransaction(message);

if (
opts?.additionalSigners !== undefined &&
opts?.additionalSigners.length !== 0
) {
vtx.sign([...opts?.additionalSigners]);
if (additionalSigners !== undefined && additionalSigners.length !== 0) {
vtx.sign([...additionalSigners]);
}

if (
Expand Down
5 changes: 2 additions & 3 deletions ts/client/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export function initOpenbookClient(): OpenBookV2Client {
});
}


export function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
return new Promise((resolve) => setTimeout(resolve, ms));
}
45 changes: 31 additions & 14 deletions ts/client/src/utils/watcher.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { Connection } from "@solana/web3.js";
import { BookSide, Market, OpenOrders } from "..";
import { Connection } from '@solana/web3.js';
import { BookSide, Market, OpenOrders } from '..';

export class Watcher {
accountSubs: { [pk: string]: number } = {};

accountSubs: {[pk: string]: number} = {};

constructor(public connection: Connection) {};
constructor(public connection: Connection) {}

addMarket(market: Market, includeBook = true): this {
const { client, asks, bids, pubkey } = market;

this.accountSubs[pubkey.toBase58()] = this.connection.onAccountChange(pubkey, (ai) => {
market.account = client.program.coder.accounts.decode('market', ai.data);
});
this.accountSubs[pubkey.toBase58()] = this.connection.onAccountChange(
pubkey,
(ai) => {
market.account = client.program.coder.accounts.decode(
'market',
ai.data,
);
},
);

if (includeBook && asks) {
this.addBookSide(asks);
Expand All @@ -25,17 +30,29 @@ export class Watcher {

addBookSide(bookSide: BookSide): this {
const { market, pubkey } = bookSide;
this.accountSubs[pubkey.toBase58()] = this.connection.onAccountChange(pubkey, (ai) => {
bookSide.account = market.client.program.coder.accounts.decode('bookSide', ai.data);
});
this.accountSubs[pubkey.toBase58()] = this.connection.onAccountChange(
pubkey,
(ai) => {
bookSide.account = market.client.program.coder.accounts.decode(
'bookSide',
ai.data,
);
},
);
return this;
}

addOpenOrders(openOrders: OpenOrders): this {
const { market, pubkey } = openOrders;
this.accountSubs[pubkey.toBase58()] = this.connection.onAccountChange(pubkey, (ai) => {
openOrders.account = market.client.program.coder.accounts.decode('OpenOrders', ai.data);
});
this.accountSubs[pubkey.toBase58()] = this.connection.onAccountChange(
pubkey,
(ai) => {
openOrders.account = market.client.program.coder.accounts.decode(
'OpenOrders',
ai.data,
);
},
);
return this;
}

Expand Down

0 comments on commit 999e071

Please sign in to comment.