Skip to content

Commit c98566f

Browse files
authored
Merge pull request #3062 from DFXswiss/develop
Release: develop -> main
2 parents b44cf76 + c1790bf commit c98566f

4 files changed

Lines changed: 41 additions & 15 deletions

File tree

src/integration/exchange/dto/mexc.dto.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,14 @@ export interface MexcMyTrade {
126126
isMaker: boolean;
127127
isBestMatch: boolean;
128128
}
129+
130+
export interface MexcOrderResponse {
131+
symbol: string;
132+
orderId: string;
133+
orderListId: number;
134+
price: string;
135+
origQty: string;
136+
type: string;
137+
side: string;
138+
transactTime: number;
139+
}

src/integration/exchange/services/exchange.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ export abstract class ExchangeService extends PricingProvider implements OnModul
354354
return this.createOrder(pair, direction, amount, price).then((o) => o.id);
355355
}
356356

357-
private async createOrder(pair: string, direction: OrderSide, amount: number, price: number): Promise<Order> {
357+
protected async createOrder(pair: string, direction: OrderSide, amount: number, price: number): Promise<Order> {
358358
return this.callApi((e) => e.createOrder(pair, 'limit', direction, amount, price));
359359
}
360360

src/integration/exchange/services/mexc.service.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable } from '@nestjs/common';
22
import { Method } from 'axios';
3-
import { Market, mexc, OrderBook, Trade, Transaction } from 'ccxt';
3+
import { Market, mexc, Order, OrderBook, Trade, Transaction } from 'ccxt';
44
import { Config, GetConfig } from 'src/config/config';
55
import { Blockchain } from 'src/integration/blockchain/shared/enums/blockchain.enum';
66
import { DfxLogger } from 'src/shared/services/dfx-logger';
@@ -12,12 +12,13 @@ import {
1212
MexcExchangeInfo,
1313
MexcMyTrade,
1414
MexcOrderBook,
15+
MexcOrderResponse,
1516
MexcSymbol,
1617
MexcTrade,
1718
Withdrawal,
1819
WithdrawalStatus,
1920
} from '../dto/mexc.dto';
20-
import { ExchangeService } from './exchange.service';
21+
import { ExchangeService, OrderSide } from './exchange.service';
2122

2223
@Injectable()
2324
export class MexcService extends ExchangeService {
@@ -288,4 +289,18 @@ export class MexcService extends ExchangeService {
288289
fees: t.commission ? [{ cost: parseFloat(t.commission), currency: t.commissionAsset }] : [],
289290
}));
290291
}
292+
293+
protected async createOrder(pair: string, direction: OrderSide, amount: number, price: number): Promise<Order> {
294+
const symbol = pair.replace('/', '');
295+
296+
const response = await this.request<MexcOrderResponse>('POST', 'order', {
297+
symbol,
298+
side: direction.toUpperCase(),
299+
type: 'LIMIT',
300+
quantity: amount.toString(),
301+
price: price.toString(),
302+
});
303+
304+
return { id: response.orderId } as Order;
305+
}
291306
}

src/subdomains/core/liquidity-management/adapters/actions/base/ccxt-exchange.adapter.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ export abstract class CcxtExchangeAdapter extends LiquidityActionAdapter {
149149
const availableBalance = await this.getAvailableTradeBalance(tradeAsset, targetAssetEntity.name);
150150
let effectiveMax = Math.min(maxSellAmount, availableBalance);
151151

152+
if (availableBalance < minSellAmount) {
153+
throw new OrderNotProcessableException(
154+
`${this.exchangeService.name}: not enough balance for ${tradeAsset} (balance: ${availableBalance}, min. requested: ${minSellAmount}, max. requested: ${maxSellAmount})`,
155+
);
156+
}
157+
152158
if (liquidityLimited) {
153159
const { amount: liquidity, price: liquidityPrice } = await this.getBestPriceLiquidity(
154160
tradeAsset,
@@ -157,12 +163,6 @@ export abstract class CcxtExchangeAdapter extends LiquidityActionAdapter {
157163
effectiveMax = Math.min(effectiveMax, Util.floor(liquidity * liquidityPrice, 6));
158164
}
159165

160-
if (effectiveMax < minSellAmount) {
161-
throw new OrderNotProcessableException(
162-
`${this.exchangeService.name}: not enough balance/liquidity for ${tradeAsset} (balance: ${effectiveMax}, min. requested: ${minSellAmount}, max. requested: ${maxSellAmount})`,
163-
);
164-
}
165-
166166
const amount = effectiveMax;
167167

168168
order.inputAmount = amount;
@@ -197,17 +197,17 @@ export abstract class CcxtExchangeAdapter extends LiquidityActionAdapter {
197197
const availableBalance = await this.getAvailableTradeBalance(asset, tradeAsset);
198198
let effectiveMax = Math.min(order.maxAmount, availableBalance);
199199

200+
if (availableBalance < order.minAmount) {
201+
throw new OrderNotProcessableException(
202+
`${this.exchangeService.name}: not enough balance for ${asset} (balance: ${availableBalance}, min. requested: ${order.minAmount}, max. requested: ${order.maxAmount})`,
203+
);
204+
}
205+
200206
if (liquidityLimited) {
201207
const { amount: liquidity } = await this.getBestPriceLiquidity(asset, tradeAsset);
202208
effectiveMax = Math.min(effectiveMax, liquidity);
203209
}
204210

205-
if (effectiveMax < order.minAmount) {
206-
throw new OrderNotProcessableException(
207-
`${this.exchangeService.name}: not enough balance/liquidity for ${asset} (balance: ${effectiveMax}, min. requested: ${order.minAmount}, max. requested: ${order.maxAmount})`,
208-
);
209-
}
210-
211211
const amount = effectiveMax;
212212

213213
order.inputAmount = amount;

0 commit comments

Comments
 (0)