Skip to content

Commit

Permalink
Merge pull request #2182 from hollaex/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
abeikverdi authored Jun 9, 2023
2 parents 7d0127c + 00a28d9 commit 22df1ab
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 31 deletions.
2 changes: 1 addition & 1 deletion server/api/swagger/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const definition = {
swagger: '2.0',
info: {
title: 'HollaEx Kit',
version: '2.6.5'
version: '2.6.6'
},
host: 'api.hollaex.com',
basePath: '/v2',
Expand Down
4 changes: 4 additions & 0 deletions server/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ exports.QUICK_TRADE_QUOTE_INVALID = 'Invalid quote';
exports.QUICK_TRADE_QUOTE_CALCULATING_ERROR = 'Error calculating the quote';
exports.QUICK_TRADE_ORDER_CAN_NOT_BE_FILLED =
'The order with the current size can not be filled';
exports.QUICK_TRADE_VALUE_IS_TOO_SMALL =
'The order with the current size is too small to be filled';
exports.QUICK_TRADE_ORDER_CURRENT_PRICE_ERROR =
'The order with the current price can not be filled';
exports.QUICK_TRADE_INSUFFICIENT_BALANCE =
'Insufficient balance to perform the order';
exports.QUICK_TRADE_DISABLED = 'Broker service is currently disabled';
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.6.5",
"version": "2.6.6",
"private": false,
"description": "HollaEx Kit",
"keywords": [
Expand Down
22 changes: 17 additions & 5 deletions server/utils/hollaex-tools-lib/tools/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { SERVER_PATH } = require('../constants');
const { getModel } = require('./database/model');
const { fetchBrokerQuote, generateRandomToken, executeBrokerDeal } = require('./broker');
const { getNodeLib } = require(`${SERVER_PATH}/init`);
const { INVALID_SYMBOL, NO_DATA_FOR_CSV, USER_NOT_FOUND, USER_NOT_REGISTERED_ON_NETWORK, TOKEN_EXPIRED, BROKER_NOT_FOUND, BROKER_PAUSED, BROKER_SIZE_EXCEED } = require(`${SERVER_PATH}/messages`);
const { INVALID_SYMBOL, NO_DATA_FOR_CSV, USER_NOT_FOUND, USER_NOT_REGISTERED_ON_NETWORK, TOKEN_EXPIRED, BROKER_NOT_FOUND, BROKER_PAUSED, BROKER_SIZE_EXCEED, QUICK_TRADE_ORDER_CAN_NOT_BE_FILLED, QUICK_TRADE_ORDER_CURRENT_PRICE_ERROR, QUICK_TRADE_VALUE_IS_TOO_SMALL } = require(`${SERVER_PATH}/messages`);
const { parse } = require('json2csv');
const { subscribedToPair, getKitTier, getDefaultFees, getAssetsPrices, getPublicTrades, validatePair } = require('./common');
const { reject } = require('bluebird');
Expand Down Expand Up @@ -147,6 +147,11 @@ const getUserQuickTrade = async (spending_currency, spending_amount, receiving_a
);
responseObj.spending_amount = sourceAmount;
}

const baseCoinSize = side === 'buy' ? responseObj.receiving_amount : responseObj.spending_amount;
if (baseCoinSize < broker.min_size || baseCoinSize > broker.max_size) {
throw new Error(BROKER_SIZE_EXCEED)
}

return responseObj;
})
Expand Down Expand Up @@ -182,17 +187,24 @@ const getUserQuickTrade = async (spending_currency, spending_amount, receiving_a
isSourceChanged: spending_amount != null ? true : false,
}, opts);

if (spending_amount != null) responseObj.receiving_amount = priceValues.estimatedPrice == 0 ? null : priceValues.targetAmount;
else if (receiving_amount != null) responseObj.spending_amount = priceValues.estimatedPrice == 0 ? null : priceValues.sourceAmount;
if (priceValues.estimatedPrice === 0) {
throw new Error(QUICK_TRADE_ORDER_CAN_NOT_BE_FILLED);
}

if (priceValues.targetAmount === 0 || priceValues.sourceAmount === 0) {
throw new Error(QUICK_TRADE_VALUE_IS_TOO_SMALL);
}

if (spending_amount != null) responseObj.receiving_amount = priceValues.targetAmount;
else if (receiving_amount != null) responseObj.spending_amount = priceValues.sourceAmount;

//Check if the estimated price is 50% greater than the last trade
const lastTrades = await getPublicTrades(symbol);
if (Array.isArray(lastTrades[symbol]) && lastTrades[symbol].length > 0) {
const lastPrice = math.number(lastTrades[symbol][0].price) * 1.50

if (priceValues.estimatedPrice > lastPrice) {
responseObj.receiving_amount = null;
responseObj.spending_amount = null;
throw new Error(QUICK_TRADE_ORDER_CURRENT_PRICE_ERROR);
}
}

Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.5
2.6.6
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hollaex-kit",
"version": "2.6.5",
"version": "2.6.6",
"private": true,
"dependencies": {
"@ant-design/compatible": "1.0.5",
Expand Down
42 changes: 20 additions & 22 deletions web/src/components/QuickTrade/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,39 +228,38 @@ const QuickTrade = ({
spending,
}) => {
if (spending) {
const spending_amount =
spending === SPENDING.SOURCE ? sourceAmount : targetAmount;
const [spending_currency, receiving_currency] =
spending === SPENDING.SOURCE
? [selectedSource, selectedTarget]
: [selectedTarget, selectedSource];
const [setSpendingAmount, setReceivingAmount] =
spending === SPENDING.SOURCE
? [setSourceAmount, setTargetAmount]
: [setTargetAmount, setSourceAmount];

if (spending_amount && spending_currency && receiving_currency) {
const spending_amount = sourceAmount;
const receiving_amount = targetAmount;

const [spending_currency, receiving_currency] = [selectedSource, selectedTarget];
const amount = spending === SPENDING.SOURCE ? spending_amount : receiving_amount;
const amountPayload = spending === SPENDING.SOURCE ? { spending_amount } : { receiving_amount };

if (amount && spending_currency && receiving_currency) {
setLoading(true);
setReceivingAmount();
setTargetAmount();
setSourceAmount();
setToken();
setError();

getQuickTrade({
spending_amount,
...amountPayload,
spending_currency,
receiving_currency,
})
.then(({ data: { token, spending_amount, receiving_amount } }) => {
setSpending();
setToken(token);
setReceivingAmount(receiving_amount);
setSpendingAmount(spending_amount);
setTargetAmount(receiving_amount);
setSourceAmount(spending_amount);
})
.catch((err) => handleError(err, true))
.finally(() => {
setLoading(false);
});
} else {
setReceivingAmount();
setTargetAmount();
setSourceAmount();
setSpending();
setToken();
}
Expand Down Expand Up @@ -305,7 +304,6 @@ const QuickTrade = ({
}, [selectedSource, selectedTarget, pairs, brokerPairs]);

useEffect(() => {
setError();
debouncedQuote.current({
sourceAmount,
targetAmount,
Expand Down Expand Up @@ -478,11 +476,11 @@ const QuickTrade = ({
<ReviewOrder
onCloseDialog={onCloseDialog}
onExecuteTrade={() => onExecuteTrade(token)}
selectedSource={spendingCurrency}
selectedSource={selectedSource}
decimalPoint={decimalPoint}
sourceAmount={spendingAmount}
targetAmount={receivingAmount}
selectedTarget={receivingCurrency}
sourceAmount={sourceAmount}
targetAmount={targetAmount}
selectedTarget={selectedTarget}
disabled={submitting}
/>
) : (
Expand Down

0 comments on commit 22df1ab

Please sign in to comment.