Skip to content

Commit

Permalink
Merge pull request #24 from Adamant-im/dev
Browse files Browse the repository at this point in the history
v1.5.0
  • Loading branch information
dev-adamant-im authored Aug 28, 2023
2 parents 2e27e27 + 777992d commit 4c01ad7
Show file tree
Hide file tree
Showing 13 changed files with 4,080 additions and 1,431 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ See trades history example with a 3% price step:

# Supported exchanges

* [Binance](https://binance.com)
* [Binance](https://accounts.binance.com/register?ref=36699789)
* [P2PB2B](https://p2pb2b.com)
* [Azbit](https://azbit.com?referralCode=9YVWYAF)
* [StakeCube](https://stakecube.net/?team=adm)
* [Bitfinex](https://bitfinex.com)
* [Bitfinex](https://www.bitfinex.com/sign-up?refcode=4k5uFSBLZ)
* [Bittrex](https://global.bittrex.com/discover/join?referralCode=TGD-P0Z-F5W)
* [Coinstore](https://h5.coinstore.com/h5/signup?invitCode=o951vZ)

# Usage and Installation

Expand Down
4 changes: 3 additions & 1 deletion config.default.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
"Azbit",
"Binance",
"StakeCube",
"Bitfinex"
"Bitfinex",
"Bittrex",
"Coinstore"
],

/** Exchange to work with. Case insensitive. **/
Expand Down
2 changes: 1 addition & 1 deletion helpers/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ module.exports = (messageText, type, silent_mode = false, isPriority = false) =>
],
};
discordKeys.forEach((discordKey) => {
if (typeof discordKey === 'string') {
if (typeof discordKey === 'string' && discordKey.length > 36) {
axios.post(discordKey, params)
.catch((error) => {
log.log(`Request to Discord with message ${message} failed. ${error}.`);
Expand Down
67 changes: 54 additions & 13 deletions helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1300,34 +1300,75 @@ module.exports = {
return Math.round(-Math.log10(+precision));
},

/**
* Returns decimals for arbitrary number
* 0.00001 -> 5
* 1000.00001 -> 5
* 1 -> 0
* 0 -> 0
* @param {Number|String} number
* @returns {Number|undefined}
*/
getDecimalsFromNumber(number) {
number = number?.toString();

if (!isFinite(number)) return undefined;

const split = number.split('.');

if (split.length === 1) {
return 0;
}

return split[1]?.length;
},

/**
* Checks if order price is out of order book custom percent (as mm_liquiditySpreadPercent) spread
* @param order Object of ordersDb
* @param orderBookInfo Object of utils.getOrderBookInfo()
* @param obInfo Object of utils.getOrderBookInfo()
* @returns {Boolean}
*/
isOrderOutOfSpread(order, orderBookInfo) {
isOrderOutOfSpread(order, obInfo) {
try {
const liqInfo = order.subPurpose === 'ss' ? orderBookInfo.liquidity.percentSpreadSupport : orderBookInfo.liquidity.percentCustom;
const outOfSpreadInfo = {
isOrderOutOfSpread: false,
isOrderOutOfMinMaxSpread: false,
isOrderOutOfInnerSpread: false,
isSsOrder: order.subPurpose === 'ss',
orderPrice: order.price,
minPrice: undefined,
maxPrice: undefined,
innerLowPrice: undefined,
innerHighPrice: undefined,
spreadPercent: tradeParams.mm_liquiditySpreadPercent,
spreadPercentMin: tradeParams.mm_liquiditySpreadPercentMin,
};

const liqInfo = outOfSpreadInfo.isSsOrder ? obInfo.liquidity.percentSpreadSupport : obInfo.liquidity.percentCustom;
const roughness = liqInfo.spread * AVERAGE_SPREAD_DEVIATION;

// First, check mm_liquiditySpreadPercent
const minPrice = liqInfo.lowPrice - roughness;
const maxPrice = liqInfo.highPrice + roughness;
if (order.price < minPrice || order.price > maxPrice) {
return true;
outOfSpreadInfo.minPrice = liqInfo.lowPrice - roughness;
outOfSpreadInfo.maxPrice = liqInfo.highPrice + roughness;
if (order.price < outOfSpreadInfo.minPrice || order.price > outOfSpreadInfo.maxPrice) {
outOfSpreadInfo.isOrderOutOfSpread = true;
outOfSpreadInfo.isOrderOutOfMinMaxSpread = true;
return outOfSpreadInfo;
}

// Second, check mm_liquiditySpreadPercentMin: 'depth' orders should be not close to mid of spread
if (order.subPurpose !== 'ss' && tradeParams.mm_liquiditySpreadPercentMin) {
const innerLowPrice = orderBookInfo.averagePrice * (1 - tradeParams.mm_liquiditySpreadPercentMin/100) + roughness;
const innerHighPrice = orderBookInfo.averagePrice * (1 + tradeParams.mm_liquiditySpreadPercentMin/100) - roughness;
if (order.price > innerLowPrice && order.price < innerHighPrice) {
return true;
if (!outOfSpreadInfo.isSsOrder && tradeParams.mm_liquiditySpreadPercentMin) {
outOfSpreadInfo.innerLowPrice = obInfo.averagePrice * (1 - tradeParams.mm_liquiditySpreadPercentMin/100) + roughness;
outOfSpreadInfo.innerHighPrice = obInfo.averagePrice * (1 + tradeParams.mm_liquiditySpreadPercentMin/100) - roughness;
if (order.price > outOfSpreadInfo.innerLowPrice && order.price < outOfSpreadInfo.innerHighPrice) {
outOfSpreadInfo.isOrderOutOfSpread = true;
outOfSpreadInfo.isOrderOutOfInnerSpread = true;
return outOfSpreadInfo;
}
}

return false;
return outOfSpreadInfo;
} catch (e) {
log.error(`Error in isOrderOutOfSpread() of ${this.getModuleName(module.id)} module: ${e}.`);
return false;
Expand Down
Loading

0 comments on commit 4c01ad7

Please sign in to comment.