-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat: added status basic endpoint #347
Merged
chrisleekr
merged 1 commit into
chrisleekr:master
from
ilbuonmarcio:feat/status-endpoints
Oct 6, 2021
Merged
feat: added status basic endpoint #347
chrisleekr
merged 1 commit into
chrisleekr:master
from
ilbuonmarcio:feat/status-endpoints
Oct 6, 2021
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hi @chrisleekr, sorry to bother you everytime but I just checked the repo and it's missing a test for this new feature so it's marking it as failing. Here's the code snippet I'm currently at: /* eslint-disable global-require */
describe('webserver/handlers/status', () => {
const appMock = {};
let resSendMock;
let loggerMock;
beforeEach(async () => {
resSendMock = jest.fn().mockResolvedValue(true);
appMock.route = jest.fn(() => ({
get: jest.fn().mockImplementation((_path, func) => {
func(null, { send: resSendMock });
})
}));
const logger = require('../../../../helpers');
loggerMock = logger;
const { handleStatus } = require('../status');
await handleStatus(loggerMock, appMock);
});
it('triggers res.send', () => {
expect(resSendMock).toHaveBeenCalledWith({
success: true,
status: 200,
message: 'OK'
});
});
}); The following error occurs after running PS C:\Users\Alessandro Marchioro\Desktop\Clients\AleMarioDario\binance-trading-bot> npm run test
> binance-trading-bot@0.0.79 test C:\Users\Alessandro Marchioro\Desktop\Clients\AleMarioDario\binance-trading-bot
> cross-env NODE_ENV=test jest --coverage --detectOpenHandles
FAIL app/cronjob/trailingTrade/step/__tests__/ensure-grid-trade-order-executed.test.js (7.483 s)
● ensure-grid-trade-order-executed.js › execute › when found last buy order › last buy order is NEW and still NEW after checking the order › triggers saveGridTradeOrder for last buy order as not filled
expect(jest.fn()).toHaveBeenCalledWith(...expected)
- Expected
+ Received
{"child": [Function anonymous], "debug": [Function mockConstructor], "error": [Function mockConstructor], "info": [Function mockConstructor], "warn": [Function mockConstructor]},
"BNBUSDT-grid-trade-last-buy-order",
@@ -1,8 +1,8 @@
Object {
"currentGridTradeIndex": 0,
- "nextCheck": "2020-01-02T00:00:10+00:00",
+ "nextCheck": "2020-01-02T01:00:10+01:00",
"orderId": 2705449295,
"origQty": "0.03320000",
"price": "302.09000000",
"side": "BUY",
"status": "NEW",,
Number of calls: 1
852 | // do else thing
853 | it('triggers saveGridTradeOrder for last buy order as not filled', () => {
> 854 | expect(mockSaveGridTradeOrder).toHaveBeenCalledWith(
| ^
855 | loggerMock,
856 | `${t.symbol}-grid-trade-last-buy-order`,
857 | {
at Object.<anonymous> (app/cronjob/trailingTrade/step/__tests__/ensure-grid-trade-order-executed.test.js:854:50)
● ensure-grid-trade-order-executed.js › execute › when found last buy order › last buy order is NEW but error › triggers saveGridTradeOrder for last buy order as order throws error
expect(jest.fn()).toHaveBeenCalledWith(...expected)
- Expected
+ Received
{"child": [Function anonymous], "debug": [Function mockConstructor], "error": [Function mockConstructor], "info": [Function mockConstructor], "warn": [Function mockConstructor]},
"BNBUSDT-grid-trade-last-buy-order",
@@ -1,8 +1,8 @@
Object {
"currentGridTradeIndex": 0,
- "nextCheck": "2020-01-02T00:00:10+00:00",
+ "nextCheck": "2020-01-02T01:00:10+01:00",
"orderId": 2705449295,
"origQty": "0.03320000",
"price": "302.09000000",
"side": "BUY",
"status": "NEW",,
Number of calls: 1
740 | // order throws an error
741 | it('triggers saveGridTradeOrder for last buy order as order throws error', () => {
> 742 | expect(mockSaveGridTradeOrder).toHaveBeenCalledWith(
| ^
743 | loggerMock,
744 | `${t.symbol}-grid-trade-last-buy-order`,
745 | {
at Object.<anonymous> (app/cronjob/trailingTrade/step/__tests__/ensure-grid-trade-order-executed.test.js:742:48)
● ensure-grid-trade-order-executed.js › execute › when found last sell order › last sell order is NEW and still NEW after checking the order › triggers saveGridTradeOrder for last sell order as not filled
expect(jest.fn()).toHaveBeenCalledWith(...expected)
- Expected
+ Received
{"child": [Function anonymous], "debug": [Function mockConstructor], "error": [Function mockConstructor], "info": [Function mockConstructor], "warn": [Function mockConstructor]},
"BNBUSDT-grid-trade-last-sell-order",
@@ -1,8 +1,8 @@
Object {
"currentGridTradeIndex": 0,
- "nextCheck": "2020-01-02T00:00:10+00:00",
+ "nextCheck": "2020-01-02T01:00:10+01:00",
"orderId": 2705449295,
"origQty": "0.03320000",
"price": "302.09000000",
"side": "SELL",
"status": "NEW",,
Number of calls: 1
1580 | // do else thing
1581 | it('triggers saveGridTradeOrder for last sell order as not filled', () => {
> 1582 | expect(mockSaveGridTradeOrder).toHaveBeenCalledWith(
| ^
1583 | loggerMock,
1584 | `${t.symbol}-grid-trade-last-sell-order`,
1585 | {
at Object.<anonymous> (app/cronjob/trailingTrade/step/__tests__/ensure-grid-trade-order-executed.test.js:1582:50)
● ensure-grid-trade-order-executed.js › execute › when found last sell order › last sell order is NEW but error › triggers saveGridTradeOrder for last sell order as order throws error
expect(jest.fn()).toHaveBeenCalledWith(...expected)
- Expected
+ Received
{"child": [Function anonymous], "debug": [Function mockConstructor], "error": [Function mockConstructor], "info": [Function mockConstructor], "warn": [Function mockConstructor]},
"BNBUSDT-grid-trade-last-sell-order",
@@ -1,8 +1,8 @@
Object {
"currentGridTradeIndex": 0,
- "nextCheck": "2020-01-02T00:00:10+00:00",
+ "nextCheck": "2020-01-02T01:00:10+01:00",
"orderId": 2705449295,
"origQty": "0.03320000",
"price": "302.09000000",
"side": "SELL",
"status": "NEW",,
Number of calls: 1
1476 | // order throws an error
1477 | it('triggers saveGridTradeOrder for last sell order as order throws error', () => {
> 1478 | expect(mockSaveGridTradeOrder).toHaveBeenCalledWith(
| ^
1479 | loggerMock,
1480 | `${t.symbol}-grid-trade-last-sell-order`,
1481 | {
at Object.<anonymous> (app/cronjob/trailingTrade/step/__tests__/ensure-grid-trade-order-executed.test.js:1478:48)
FAIL app/frontend/webserver/handlers/__tests__/index.test.js
● index › triggers handleAuth
TypeError: funcLogger.child is not a function
2 |
3 | const handleStatus = async (funcLogger, app) => {
> 4 | const logger = funcLogger.child({ endpoint: '/status' });
| ^
5 |
6 | app.route('/status').get(async (req, res) => {
7 | const clientIp = requestIp.getClientIp(req);
at handleStatus (app/frontend/webserver/handlers/status.js:4:29)
at Object.setHandlers (app/frontend/webserver/handlers/index.js:13:9)
at Object.<anonymous> (app/frontend/webserver/handlers/__tests__/index.test.js:45:5)
● index › triggers handleGridTradeArchiveGet
TypeError: funcLogger.child is not a function
2 |
3 | const handleStatus = async (funcLogger, app) => {
> 4 | const logger = funcLogger.child({ endpoint: '/status' });
| ^
5 |
6 | app.route('/status').get(async (req, res) => {
7 | const clientIp = requestIp.getClientIp(req);
at handleStatus (app/frontend/webserver/handlers/status.js:4:29)
at Object.setHandlers (app/frontend/webserver/handlers/index.js:13:9)
at Object.<anonymous> (app/frontend/webserver/handlers/__tests__/index.test.js:45:5)
● index › triggers handleGridTradeArchiveDelete
TypeError: funcLogger.child is not a function
2 |
3 | const handleStatus = async (funcLogger, app) => {
> 4 | const logger = funcLogger.child({ endpoint: '/status' });
| ^
5 |
6 | app.route('/status').get(async (req, res) => {
7 | const clientIp = requestIp.getClientIp(req);
at handleStatus (app/frontend/webserver/handlers/status.js:4:29)
at Object.setHandlers (app/frontend/webserver/handlers/index.js:13:9)
at Object.<anonymous> (app/frontend/webserver/handlers/__tests__/index.test.js:45:5)
● index › triggers handleClosedTradesSetPeriod
TypeError: funcLogger.child is not a function
2 |
3 | const handleStatus = async (funcLogger, app) => {
> 4 | const logger = funcLogger.child({ endpoint: '/status' });
| ^
5 |
6 | app.route('/status').get(async (req, res) => {
7 | const clientIp = requestIp.getClientIp(req);
at handleStatus (app/frontend/webserver/handlers/status.js:4:29)
at Object.setHandlers (app/frontend/webserver/handlers/index.js:13:9)
at Object.<anonymous> (app/frontend/webserver/handlers/__tests__/index.test.js:45:5)
● index › triggers handle404
TypeError: funcLogger.child is not a function
2 |
3 | const handleStatus = async (funcLogger, app) => {
> 4 | const logger = funcLogger.child({ endpoint: '/status' });
| ^
5 |
6 | app.route('/status').get(async (req, res) => {
7 | const clientIp = requestIp.getClientIp(req);
at handleStatus (app/frontend/webserver/handlers/status.js:4:29)
at Object.setHandlers (app/frontend/webserver/handlers/index.js:13:9)
at Object.<anonymous> (app/frontend/webserver/handlers/__tests__/index.test.js:45:5)
PASS app/cronjob/trailingTrade/step/__tests__/place-buy-order.test.js (5.834 s)
RUNS app/cronjob/trailingTradeHelper/__tests__/common.test.js
Terminate batch job (Y/N)?
^C
PS C:\Users\Alessandro Marchioro\Desktop\Clients\AleMarioDario\binance-trading-bot> ^C```
|
This was referenced Oct 10, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Added
/status
basic endpoint for monitoring using Grafana/Prometheus/UptimeKuma.I just added a
/status
endpoint, which replies (fast) with an HTTP 200 and a basic json object if the body.This implementation right now doesn't check for
mongodb
orredis
availability, yet it's still pretty useful in itself to make sure the bot is at least up.Related Issue
#341
Motivation and Context
Monitoring the bot is a good thing, and this is an easy way to help with that!
How Has This Been Tested?
Tested on TEST environment, should be ok even in production environment aswell.