Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telegram, initial language setup (for future changes in frontend), don't remove last buy when under amount, reworked notifications. #204

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ BINANCE_SLACK_WEBHOOK_URL=
BINANCE_SLACK_CHANNEL=
BINANCE_SLACK_USERNAME=

## Telegram
BINANCE_TELEGRAM_ENABLED=
BINANCE_TELEGRAM_CHATID=
BINANCE_TELEGRAM_TOKEN=

## Language
DEFINED_LANGUAGE=en-us

## Local Tunnel
BINANCE_LOCAL_TUNNEL_ENABLED=true
BINANCE_LOCAL_TUNNEL_SUBDOMAIN=default
Expand Down
16 changes: 16 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"ExpandedNodes": [
"",
"\\app",
"\\app\\cronjob",
"\\app\\cronjob\\trailingTrade",
"\\app\\cronjob\\trailingTrade\\step",
"\\app\\helpers",
"\\app\\scripts",
"\\config",
"\\public",
"\\public\\js"
],
"SelectedNode": "\\app\\cronjob\\trailingTrade\\step\\remove-last-buy-price.js",
"PreviewInSolutionExplorer": false
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
6 changes: 3 additions & 3 deletions app/cronjob/alive.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const moment = require('moment-timezone');
const config = require('config');
const aliveHelper = require('./alive/helper');
const { slack } = require('../helpers');
const { messenger } = require('../helpers');

const execute = async logger => {
logger.info('Alive: Notify balance');
Expand All @@ -22,10 +22,10 @@ const execute = async logger => {
.tz(config.get('tz'))
.format('YYYY-MM-DD HH:mm:ss')} (${config.get('tz')})_`;

slack.sendMessage(message);
messenger.sendMessage(message, null, 'BALANCE_INFO');
} catch (e) {
logger.error(e, 'Execution failed.');
slack.sendMessage(`Execution failed\n\`\`\`${e.message}\`\`\``);
messenger.sendMessage(`Execution failed\n\`\`\`${e.message}\`\`\``);
}
};

Expand Down
16 changes: 11 additions & 5 deletions app/cronjob/trailingTrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const {
removeLastBuyPrice,
saveDataToCache
} = require('./trailingTrade/steps');
const { slack } = require('../helpers');
const { messenger } = require('../helpers');

const execute = async logger => {
try {
Expand Down Expand Up @@ -178,12 +178,18 @@ const execute = async logger => {
) {
// Let's silent for internal server error or assumed temporary errors
} else {
slack.sendMessage(
messenger.errorMessage(
`Execution failed (${moment().format('HH:mm:ss.SSS')})\n` +
`Job: Trailing Trade\n` +
`Job: Trailing Trade Indicator\n` +
`Code: ${err.code}\n` +
`Message:\`\`\`${err.message}\`\`\`\n` +
`Stack:\`\`\`${err.stack}\`\`\`\n` +
`Error message: ${err.message}\n` +
`There's something *wrong*.\n`+
`You may want to reset me. You can try this *after disabling me in docker*:\n`+
`wsl --shutdown\n` +
`Now *restart wsl through windows notification* (if you're a windows user).\n` +
`Or you can *try this* to *sync docker clock with your machine*:\n` +
`docker run -it --rm --privileged --pid=host debian nsenter -t 1 -m -u -n -i date -u $(date -u +%m%d%H%M%Y)\n` +
`Then you just need to *restart* me.\n` +
`- Current API Usage: ${getAPILimit(logger)}`
);
}
Expand Down
84 changes: 21 additions & 63 deletions app/cronjob/trailingTrade/step/ensure-order-placed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const config = require('config');
const moment = require('moment');
const _ = require('lodash');

const { cache, slack } = require('../../../helpers');
const { cache, messenger } = require('../../../helpers');
const {
getAndCacheOpenOrdersForSymbol,
getAccountInfoFromAPI,
Expand Down Expand Up @@ -119,6 +119,8 @@ const isOrderExistingInOpenOrders = (_logger, order, openOrders) =>
* @param {*} logger
* @param {*} rawData
*/
var canCheckBuy = true;
var canCheckSell = true;
const execute = async (logger, rawData) => {
const data = rawData;

Expand Down Expand Up @@ -153,22 +155,9 @@ const execute = async (logger, rawData) => {
data.accountInfo = await getAccountInfoFromAPI(logger);

if (_.get(featureToggle, 'notifyOrderConfirm', false) === true) {
slack.sendMessage(
`${symbol} Action (${moment().format(
'HH:mm:ss.SSS'
)}): Confirmed buy order\n` +
`- Message: The buy order found in the open orders.\n` +
`\`\`\`${JSON.stringify(
{
lastBuyOrder,
openOrders
// accountInfo: data.accountInfo
},
undefined,
2
)}\`\`\`\n` +
`- Current API Usage: ${getAPILimit(logger)}`
);
messenger.sendMessage(
symbol, lastBuyOrder, 'BUY_CONFIRMED');
canCheckBuy = true;
}

// Lock symbol action 20 seconds to avoid API limit
Expand All @@ -192,21 +181,12 @@ const execute = async (logger, rawData) => {
);

if (_.get(featureToggle, 'notifyOrderConfirm', false) === true) {
slack.sendMessage(
`${symbol} Action (${moment().format(
'HH:mm:ss.SSS'
)}): Checking for buy order\n` +
`- Message: The buy order cannot be found in the open orders.\n` +
`\`\`\`${JSON.stringify(
{
lastBuyOrder,
openOrders
},
undefined,
2
)}\`\`\`\n` +
`- Current API Usage: ${getAPILimit(logger)}`
);

if (canCheckBuy) {
messenger.sendMessage(
symbol, lastBuyOrder, 'BUY_NOT_FOUND');
canCheckBuy = false;
}
}

return setBuyActionAndMessage(
Expand Down Expand Up @@ -247,22 +227,9 @@ const execute = async (logger, rawData) => {
data.accountInfo = await getAccountInfoFromAPI(logger);

if (_.get(featureToggle, 'notifyOrderConfirm', false) === true) {
slack.sendMessage(
`${symbol} Action (${moment().format(
'HH:mm:ss.SSS'
)}): Confirmed sell order\n` +
`- Message: The sell order found in the open orders.\n` +
`\`\`\`${JSON.stringify(
{
lastSellOrder,
openOrders
// accountInfo: data.accountInfo
},
undefined,
2
)}\`\`\`\n` +
`- Current API Usage: ${getAPILimit(logger)}`
);
messenger.sendMessage(
symbol, lastSellOrder, 'SELL_CONFIRMED');
canCheckSell = true;
}

// Lock symbol action 20 seconds to avoid API limit
Expand All @@ -286,21 +253,12 @@ const execute = async (logger, rawData) => {
);

if (_.get(featureToggle, 'notifyOrderConfirm', false) === true) {
slack.sendMessage(
`${symbol} Action (${moment().format(
'HH:mm:ss.SSS'
)}): Checking for sell order\n` +
`- Message: The sell order cannot be found in the open orders.\n` +
`\`\`\`${JSON.stringify(
{
lastSellOrder,
openOrders
},
undefined,
2
)}\`\`\`\n` +
`- Current API Usage: ${getAPILimit(logger)}`
);

if (canCheckSell) {
messenger.sendMessage(
symbol, lastSellOrder, 'SELL_NOT_FOUND');
canCheckSell = false;
}
}

return setSellActionAndMessage(
Expand Down
41 changes: 6 additions & 35 deletions app/cronjob/trailingTrade/step/handle-open-orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const moment = require('moment');
const _ = require('lodash');

const { slack, binance } = require('../../../helpers');
const { messenger, binance } = require('../../../helpers');
const {
getAndCacheOpenOrdersForSymbol,
getAccountInfoFromAPI,
Expand Down Expand Up @@ -113,23 +113,8 @@ const execute = async (logger, rawData) => {
data.action = 'buy-order-checking';

if (_.get(featureToggle, 'notifyDebug', false) === true) {
slack.sendMessage(
`${symbol} Action (${moment().format(
'HH:mm:ss.SSS'
)}): Failed cancelling buy order\n` +
`- Message: Binance API returned an error when cancelling the buy order.` +
` Refreshed open orders and wait for next tick.\n` +
`\`\`\`${JSON.stringify(
{
order,
openOrders: data.openOrders,
accountInfo: data.accountInfo
},
undefined,
2
)}\`\`\`\n` +
`- Current API Usage: ${getAPILimit(logger)}`
);
messenger.sendMessage(
symbol, order, 'CANCEL_BUY_FAILED');
}
} else {
// Reset buy open orders
Expand Down Expand Up @@ -181,24 +166,10 @@ const execute = async (logger, rawData) => {
data.action = 'sell-order-checking';

if (_.get(featureToggle, 'notifyDebug', false) === true) {
slack.sendMessage(
`${symbol} Action (${moment().format(
'HH:mm:ss.SSS'
)}): Failed cancelling sell order\n` +
`- Message: Binance API returned an error when cancelling the buy order.` +
` Refreshed open orders and wait for next tick.\n` +
`\`\`\`${JSON.stringify(
{
order,
openOrders: data.openOrders,
accountInfo: data.accountInfo
},
undefined,
2
)}\`\`\`\n` +
`- Current API Usage: ${getAPILimit(logger)}`
);
messenger.sendMessage(
symbol, order, 'CANCEL_SELL_FAILED');
}

} else {
// Reset sell open orders
data.sell.openOrders = [];
Expand Down
26 changes: 5 additions & 21 deletions app/cronjob/trailingTrade/step/place-buy-order.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const _ = require('lodash');
const moment = require('moment');
const { binance, slack, mongo, cache } = require('../../../helpers');
const { binance, messenger, mongo, cache } = require('../../../helpers');
const { roundDown } = require('../../trailingTradeHelper/util');
const {
getAndCacheOpenOrdersForSymbol,
Expand Down Expand Up @@ -146,16 +146,8 @@ const execute = async (logger, rawData) => {
timeInForce: 'GTC'
};

slack.sendMessage(
`${symbol} Buy Action (${moment().format(
'HH:mm:ss.SSS'
)}): *STOP_LOSS_LIMIT*\n` +
`- Order Params: \`\`\`${JSON.stringify(
orderParams,
undefined,
2
)}\`\`\`\n` +
`- Current API Usage: ${getAPILimit(logger)}`
messenger.sendMessage(
symbol, orderParams, 'PLACE_BUY'
);

logger.info(
Expand Down Expand Up @@ -190,16 +182,8 @@ const execute = async (logger, rawData) => {
// Refresh account info
data.accountInfo = await getAccountInfoFromAPI(logger);

slack.sendMessage(
`${symbol} Buy Action Result (${moment().format(
'HH:mm:ss.SSS'
)}): *STOP_LOSS_LIMIT*\n` +
`- Order Result: \`\`\`${JSON.stringify(
orderResult,
undefined,
2
)}\`\`\`\n` +
`- Current API Usage: ${getAPILimit(logger)}`
messenger.sendMessage(
symbol, orderResult, 'PLACE_BUY_DONE'
);
data.buy.processMessage = `Placed new stop loss limit order for buying.`;
data.buy.updatedAt = moment().utc();
Expand Down
23 changes: 5 additions & 18 deletions app/cronjob/trailingTrade/step/place-sell-order.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const _ = require('lodash');
const moment = require('moment');
const { binance, cache, slack } = require('../../../helpers');
const { binance, cache, messenger } = require('../../../helpers');
const { roundDown } = require('../../trailingTradeHelper/util');
const {
getAndCacheOpenOrdersForSymbol,
Expand Down Expand Up @@ -111,13 +111,8 @@ const execute = async (logger, rawData) => {
timeInForce: 'GTC'
};

slack.sendMessage(
`${symbol} Sell Action (${moment().format(
'HH:mm:ss.SSS'
)}): *STOP_LOSS_LIMIT*\n` +
`- Order Params: \`\`\`${JSON.stringify(orderParams, undefined, 2)}\`\`\`
\n` +
`- Current API Usage: ${getAPILimit(logger)}`
messenger.sendMessage(
symbol, orderParams, 'PLACE_SELL'
);

logger.info(
Expand All @@ -139,16 +134,8 @@ const execute = async (logger, rawData) => {
// Refresh account info
data.accountInfo = await getAccountInfoFromAPI(logger);

slack.sendMessage(
`${symbol} Sell Action Result (${moment().format(
'HH:mm:ss.SSS'
)}): *STOP_LOSS_LIMIT*\n` +
`- Order Result: \`\`\`${JSON.stringify(
orderResult,
undefined,
2
)}\`\`\`\n` +
`- Current API Usage: ${getAPILimit(logger)}`
messenger.sendMessage(
symbol, orderResult, 'PLACE_SELL_DONE'
);
data.sell.processMessage = `Placed new stop loss limit order for selling.`;
data.sell.updatedAt = moment().utc();
Expand Down
Loading