return tx signature while placing and cancelling orders

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2021-12-13 13:31:14 +01:00
parent ff896bafaf
commit dd3d9647cf
2 changed files with 26 additions and 10 deletions

View File

@ -383,7 +383,7 @@ class MangoSimpleClient {
price?: number, price?: number,
orderType: "ioc" | "postOnly" | "market" | "limit" = "limit", orderType: "ioc" | "postOnly" | "market" | "limit" = "limit",
clientOrderId?: number clientOrderId?: number
): Promise<void> { ): Promise<TransactionSignature> {
if (market.includes("PERP")) { if (market.includes("PERP")) {
const perpMarketConfig = getMarketByBaseSymbolAndKind( const perpMarketConfig = getMarketByBaseSymbolAndKind(
this.mangoGroupConfig, this.mangoGroupConfig,
@ -399,7 +399,7 @@ class MangoSimpleClient {
// TODO: this is a workaround, mango-v3 has a assertion for price>0 for all order types // TODO: this is a workaround, mango-v3 has a assertion for price>0 for all order types
// this will be removed soon hopefully // this will be removed soon hopefully
price = orderType !== "market" ? price : 1; price = orderType !== "market" ? price : 1;
await this.client.placePerpOrder( return await this.client.placePerpOrder(
this.mangoGroup, this.mangoGroup,
this.mangoAccount, this.mangoAccount,
this.mangoGroup.mangoCache, this.mangoGroup.mangoCache,
@ -429,7 +429,7 @@ class MangoSimpleClient {
undefined, undefined,
this.mangoGroupConfig.serumProgramId this.mangoGroupConfig.serumProgramId
); );
await this.client.placeSpotOrder( return await this.client.placeSpotOrder(
this.mangoGroup, this.mangoGroup,
this.mangoAccount, this.mangoAccount,
this.mangoGroup.mangoCache, this.mangoGroup.mangoCache,
@ -520,7 +520,10 @@ class MangoSimpleClient {
} }
} }
public async cancelOrder(orderInfo: OrderInfo, market?: Market | PerpMarket) { public async cancelOrder(
orderInfo: OrderInfo,
market?: Market | PerpMarket
): Promise<TransactionSignature> {
if (orderInfo.market.config.kind === "perp") { if (orderInfo.market.config.kind === "perp") {
const perpMarketConfig = getMarketByBaseSymbolAndKind( const perpMarketConfig = getMarketByBaseSymbolAndKind(
this.mangoGroupConfig, this.mangoGroupConfig,
@ -535,7 +538,7 @@ class MangoSimpleClient {
perpMarketConfig.quoteDecimals perpMarketConfig.quoteDecimals
); );
} }
await this.client.cancelPerpOrder( return await this.client.cancelPerpOrder(
this.mangoGroup, this.mangoGroup,
this.mangoAccount, this.mangoAccount,
this.owner, this.owner,
@ -556,7 +559,7 @@ class MangoSimpleClient {
this.mangoGroupConfig.serumProgramId this.mangoGroupConfig.serumProgramId
); );
} }
await this.client.cancelSpotOrder( return await this.client.cancelSpotOrder(
this.mangoGroup, this.mangoGroup,
this.mangoAccount, this.mangoAccount,
this.owner, this.owner,

View File

@ -126,8 +126,11 @@ class OrdersController implements Controller {
: "limit", : "limit",
placeOrderDto.clientId placeOrderDto.clientId
) )
.then(() => { .then((transactionSignature) => {
return response.status(200).send(); return response.send({
success: true,
result: { tx: transactionSignature },
});
}) })
.catch((error) => { .catch((error) => {
logger.error(`message - ${error.message}, ${error.stack}`); logger.error(`message - ${error.message}, ${error.stack}`);
@ -173,7 +176,12 @@ class OrdersController implements Controller {
} }
this.mangoSimpleClient this.mangoSimpleClient
.cancelOrder(orderInfos[0]) .cancelOrder(orderInfos[0])
.then(() => response.send()) .then((transactionSignature) =>
response.send({
success: true,
result: { tx: transactionSignature },
})
)
.catch((error) => { .catch((error) => {
logger.error(`message - ${error.message}, ${error.stack}`); logger.error(`message - ${error.message}, ${error.stack}`);
return response return response
@ -204,7 +212,12 @@ class OrdersController implements Controller {
} }
this.mangoSimpleClient this.mangoSimpleClient
.cancelOrder(orderInfos[0]) .cancelOrder(orderInfos[0])
.then(() => response.send()) .then((transactionSignature) =>
response.send({
success: true,
result: { tx: transactionSignature },
})
)
.catch((error) => { .catch((error) => {
logger.error(`message - ${error.message}, ${error.stack}`); logger.error(`message - ${error.message}, ${error.stack}`);
return response return response