Allow for client to set an open orders account when placing orders (#20)
This commit is contained in:
parent
e06b5e74e4
commit
19fcd6a064
|
@ -275,6 +275,7 @@ export class Market {
|
||||||
size,
|
size,
|
||||||
orderType = 'limit',
|
orderType = 'limit',
|
||||||
clientId,
|
clientId,
|
||||||
|
openOrdersAddressKey,
|
||||||
}: OrderParams,
|
}: OrderParams,
|
||||||
) {
|
) {
|
||||||
const { transaction, signers } = await this.makePlaceOrderTransaction(
|
const { transaction, signers } = await this.makePlaceOrderTransaction(
|
||||||
|
@ -287,6 +288,7 @@ export class Market {
|
||||||
size,
|
size,
|
||||||
orderType,
|
orderType,
|
||||||
clientId,
|
clientId,
|
||||||
|
openOrdersAddressKey,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return await this._sendTransaction(connection, transaction, signers);
|
return await this._sendTransaction(connection, transaction, signers);
|
||||||
|
@ -302,6 +304,7 @@ export class Market {
|
||||||
size,
|
size,
|
||||||
orderType = 'limit',
|
orderType = 'limit',
|
||||||
clientId,
|
clientId,
|
||||||
|
openOrdersAddressKey,
|
||||||
}: OrderParams<T>,
|
}: OrderParams<T>,
|
||||||
cacheDurationMs = 0,
|
cacheDurationMs = 0,
|
||||||
) {
|
) {
|
||||||
|
@ -331,6 +334,8 @@ export class Market {
|
||||||
signers.push(newOpenOrdersAccount);
|
signers.push(newOpenOrdersAccount);
|
||||||
// refresh the cache of open order accounts on next fetch
|
// refresh the cache of open order accounts on next fetch
|
||||||
this._openOrdersAccountsCache[ownerAddress.toBase58()].ts = 0;
|
this._openOrdersAccountsCache[ownerAddress.toBase58()].ts = 0;
|
||||||
|
} else if (openOrdersAddressKey) {
|
||||||
|
openOrdersAddress = openOrdersAddressKey;
|
||||||
} else {
|
} else {
|
||||||
openOrdersAddress = openOrdersAccounts[0].address;
|
openOrdersAddress = openOrdersAccounts[0].address;
|
||||||
}
|
}
|
||||||
|
@ -377,19 +382,16 @@ export class Market {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const placeOrderInstruction = this.makePlaceOrderInstruction(
|
const placeOrderInstruction = this.makePlaceOrderInstruction(connection, {
|
||||||
connection,
|
owner,
|
||||||
{
|
payer: wrappedSolAccount?.publicKey ?? payer,
|
||||||
owner,
|
side,
|
||||||
payer: wrappedSolAccount?.publicKey ?? payer,
|
price,
|
||||||
side,
|
size,
|
||||||
price,
|
orderType,
|
||||||
size,
|
clientId,
|
||||||
orderType,
|
openOrdersAddressKey: openOrdersAddress,
|
||||||
clientId,
|
});
|
||||||
},
|
|
||||||
openOrdersAddress,
|
|
||||||
);
|
|
||||||
transaction.add(placeOrderInstruction);
|
transaction.add(placeOrderInstruction);
|
||||||
|
|
||||||
if (wrappedSolAccount) {
|
if (wrappedSolAccount) {
|
||||||
|
@ -415,8 +417,8 @@ export class Market {
|
||||||
size,
|
size,
|
||||||
orderType = 'limit',
|
orderType = 'limit',
|
||||||
clientId,
|
clientId,
|
||||||
|
openOrdersAddressKey,
|
||||||
}: OrderParams<T>,
|
}: OrderParams<T>,
|
||||||
openOrdersAddress,
|
|
||||||
): TransactionInstruction {
|
): TransactionInstruction {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const ownerAddress: PublicKey = owner.publicKey ?? owner;
|
const ownerAddress: PublicKey = owner.publicKey ?? owner;
|
||||||
|
@ -431,7 +433,7 @@ export class Market {
|
||||||
requestQueue: this._decoded.requestQueue,
|
requestQueue: this._decoded.requestQueue,
|
||||||
baseVault: this._decoded.baseVault,
|
baseVault: this._decoded.baseVault,
|
||||||
quoteVault: this._decoded.quoteVault,
|
quoteVault: this._decoded.quoteVault,
|
||||||
openOrders: openOrdersAddress,
|
openOrders: openOrdersAddressKey,
|
||||||
owner: ownerAddress,
|
owner: ownerAddress,
|
||||||
payer,
|
payer,
|
||||||
side,
|
side,
|
||||||
|
@ -810,6 +812,7 @@ export interface OrderParams<T = Account> {
|
||||||
size: number;
|
size: number;
|
||||||
orderType?: 'limit' | 'ioc' | 'postOnly';
|
orderType?: 'limit' | 'ioc' | 'postOnly';
|
||||||
clientId?: BN;
|
clientId?: BN;
|
||||||
|
openOrdersAddressKey?: PublicKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const OPEN_ORDERS_LAYOUT = struct([
|
export const OPEN_ORDERS_LAYOUT = struct([
|
||||||
|
|
Loading…
Reference in New Issue