Skip to content

Commit

Permalink
Merge pull request #900 from bitholla/testnet
Browse files Browse the repository at this point in the history
Testnet
  • Loading branch information
abeikverdi authored Jul 30, 2021
2 parents 4e959d9 + 1d19eee commit 4484dd3
Show file tree
Hide file tree
Showing 43 changed files with 6,285 additions and 5,911 deletions.
108 changes: 99 additions & 9 deletions server/api/controllers/trade.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,62 @@ const getUserTrades = (req, res) => {
);

const user_id = req.auth.sub.id;
const { limit, page, order_by, order, start_date, end_date, format } = req.swagger.params;
const {
limit,
page,
order_by,
order,
start_date,
end_date,
format
} = req.swagger.params;
const symbol = req.swagger.params.symbol.value;

loggerTrades.info(
req.uuid,
'controllers/trade/getUserTrades params',
'user_id',
user_id,
'symbol',
symbol,
'limit',
limit.value,
'page',
page.value,
'order_by',
order_by.value,
'order',
order.value,
'start_date',
start_date.value,
'end_date',
end_date.value,
'format',
format.value
);

if (symbol && !toolsLib.subscribedToPair(symbol)) {
loggerTrades.error(req.uuid, 'controllers/trade/getUserTrades', 'Invalid symbol');
return res.status(400).json({ message: 'Invalid symbol' });
}

toolsLib.order.getAllUserTradesByKitId(user_id, symbol, limit.value, page.value, order_by.value, order.value, start_date.value, end_date.value, format.value)
toolsLib.order.getAllUserTradesByKitId(
user_id,
symbol,
limit.value,
page.value,
order_by.value,
order.value,
start_date.value,
end_date.value,
format.value
)
.then((data) => {
if (format.value) {
if (format.value == 'csv') {
res.setHeader('Content-disposition', `attachment; filename=${toolsLib.getKitConfig().api_name}-trades.csv`);
res.set('Content-Type', 'text/csv');
return res.status(202).send(data);
res.status(202);
return res.send(data);
} else {
return res.json(data);
}
Expand All @@ -41,20 +83,68 @@ const getAdminTrades = (req, res) => {

const { user_id, symbol, limit, page, order_by, order, start_date, end_date, format } = req.swagger.params;

loggerTrades.info(
req.uuid,
'controllers/trade/getAdminTrades params',
'user_id',
user_id.value,
'symbol',
symbol.value,
'limit',
limit.value,
'page',
page.value,
'order_by',
order_by.value,
'order',
order.value,
'start_date',
start_date.value,
'end_date',
end_date.value,
'format',
format.value
);

if (symbol.value && !toolsLib.subscribedToPair(symbol.value)) {
loggerTrades.error(req.uuid, 'controllers/trade/getUserTrades', 'Invalid symbol');
return res.status(400).json({ message: 'Invalid symbol' });
}

let promiseQuery;

if (user_id.value) {
promiseQuery = toolsLib.order.getAllUserTradesByKitId(user_id.value, symbol.value, limit.value, page.value, order_by.value, order.value, start_date.value, end_date.value, format.value);
promiseQuery = toolsLib.order.getAllUserTradesByKitId(
user_id.value,
symbol.value,
limit.value,
page.value,
order_by.value,
order.value,
start_date.value,
end_date.value,
format.value
);
} else {
promiseQuery = toolsLib.order.getAllTradesNetwork(symbol.value, limit.value, page.value, order_by.value, order.value, start_date.value, end_date.value, format.value);
promiseQuery = toolsLib.order.getAllTradesNetwork(
symbol.value,
limit.value,
page.value,
order_by.value,
order.value,
start_date.value,
end_date.value,
format.value
);
}

promiseQuery
.then((data) => {
if (format.value) {
res.setHeader('Content-disposition', `attachment; filename=${toolsLib.getKitConfig().api_name}-users-trades.csv`);
if (format.value === 'csv') {
res.setHeader('Content-disposition', `attachment; filename=${user_id.value ? `user-${user_id.value}-` : ''}trades.csv`);
res.set('Content-Type', 'text/csv');
return res.status(202).send(data);
res.status(202);
return res.send(data);
} else {
return res.json(data);
}
Expand Down
9 changes: 4 additions & 5 deletions server/api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
swagger: "2.0"
info:
version: "2.1.15"
version: "2.1.16"
title: HollaEx Kit
host: api.hollaex.com
basePath: /v2
Expand All @@ -12,6 +12,7 @@ consumes:
produces:
- application/json
- text/csv
- text/plain

securityDefinitions:
Bearer:
Expand Down Expand Up @@ -1572,14 +1573,12 @@ paths:
required: false
type: number
format: int32
default: 50
- in: query
name: page
description: Page of data to retrieve
required: false
type: number
format: int32
default: 1
- in: query
name: order_by
description: Field to order data
Expand Down Expand Up @@ -1607,7 +1606,7 @@ paths:
name: format
description: Specify data format
required: false
enum: ['csv']
enum: ['csv', 'all']
type: string
responses:
200:
Expand Down Expand Up @@ -2988,7 +2987,7 @@ paths:
name: format
description: Specify data format
required: false
enum: ['csv']
enum: ['csv', 'all']
type: string
tags:
- Admin
Expand Down
124 changes: 71 additions & 53 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,76 +8,94 @@ var YAML = require('yamljs');
var swaggerDoc = YAML.load('./api/swagger/swagger.yaml');
const { logEntryRequest, stream, logger } = require('./config/logger');
const { domainMiddleware, helmetMiddleware } = require('./config/middleware');
var app = require('express')();
const toolsLib = require('hollaex-tools-lib');
const { checkStatus } = require('./init');
const { API_HOST, CUSTOM_CSS } = require('./constants');

checkStatus();
// listen through pubsub for configuration/init
checkStatus()
.then(() => {
logger.info(
'app.js Initializing API Server'
);

//init runs, populates configuration/secrets
var app = require('express')();

const PORT = process.env.PORT || 10010;
// listen through pubsub for configuration/init

const server = createServer(app);
//init runs, populates configuration/secrets

module.exports = app; // for testing
const PORT = process.env.PORT || 10010;

app.use(logEntryRequest);
const server = createServer(app);

app.use(domainMiddleware);
helmetMiddleware(app);
module.exports = app; // for testing

const morganType = process.env.NODE_ENV === 'development' ? 'dev' : 'combined';
app.use(morgan(morganType, { stream }));
app.use(logEntryRequest);

var config = {
appRoot: './', // required config
swaggerSecurityHandlers: {
Bearer: toolsLib.security.verifyBearerTokenMiddleware,
HmacKey: toolsLib.security.verifyHmacTokenMiddleware
}
};
app.use(domainMiddleware);
helmetMiddleware(app);

swaggerDoc.host = API_HOST;
if (process.env.NODE_ENV === 'production') {
swaggerDoc.schemes = ['https'];
Object.entries(swaggerDoc.paths).forEach(([path, pathContent], index) => {
Object.keys(pathContent).forEach((method) => {
if (method.indexOf('swagger') === -1) {
if (pathContent[method].hasOwnProperty('tags')) {
const tags = pathContent[method].tags;
const index = tags.findIndex((value) => value === 'Admin' || value === 'Notification');
if (index > -1) {
delete pathContent[method];
}
}
const morganType = process.env.NODE_ENV === 'development' ? 'dev' : 'combined';
app.use(morgan(morganType, { stream }));

var config = {
appRoot: './', // required config
swaggerSecurityHandlers: {
Bearer: toolsLib.security.verifyBearerTokenMiddleware,
HmacKey: toolsLib.security.verifyHmacTokenMiddleware
}
};

swaggerDoc.host = API_HOST;
if (process.env.NODE_ENV === 'production') {
swaggerDoc.schemes = ['https'];
Object.entries(swaggerDoc.paths).forEach(([path, pathContent], index) => {
Object.keys(pathContent).forEach((method) => {
if (method.indexOf('swagger') === -1) {
if (pathContent[method].hasOwnProperty('tags')) {
const tags = pathContent[method].tags;
const index = tags.findIndex((value) => value === 'Admin' || value === 'Notification');
if (index > -1) {
delete pathContent[method];
}
}
}
});
});
}

var options = {
customCss: CUSTOM_CSS,
customSiteTitle: 'HollaEx Kit API Explorer',
customfavIcon:
'https://rm-content.s3.amazonaws.com/5aead825bb456c005e2322dd/upload-c116da40-ebd2-11e8-9c84-e32cc39c32d1_57.png'
};

app.get('/', (req, res) => {
res.redirect('/v2/health');
});
});
}

var options = {
customCss: CUSTOM_CSS,
customSiteTitle: 'HollaEx Kit API Explorer',
customfavIcon:
'https://rm-content.s3.amazonaws.com/5aead825bb456c005e2322dd/upload-c116da40-ebd2-11e8-9c84-e32cc39c32d1_57.png'
};
app.use('/explorer', swaggerUi.serve, swaggerUi.setup(swaggerDoc, options));

app.get('/', (req, res) => {
res.redirect('/v2/health');
});
SwaggerExpress.create(config, function(err, swaggerExpress) {
if (err) { throw err; }

app.use('/explorer', swaggerUi.serve, swaggerUi.setup(swaggerDoc, options));
// install middleware
swaggerExpress.register(app);

SwaggerExpress.create(config, function(err, swaggerExpress) {
if (err) { throw err; }

// install middleware
swaggerExpress.register(app);

server.listen(PORT, () => {
logger.info(`Server running on port: ${PORT}`);
server.listen(PORT, () => {
logger.info(`Server running on port: ${PORT}`);
});
});
})
.catch((err) => {
let message = 'API Initialization failed';
if (err.message) {
message = err.message;
}
if (err.statusCode && err.statusCode === 402) {
message = err.error.message;
}
logger.error('app/checkStatus Error ', message);
setTimeout(() => { process.exit(1); }, 60 * 1000 * 5);
});
});
15 changes: 4 additions & 11 deletions server/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ const checkStatus = () => {
activation_code: exchange.activation_code
});

if (!networkNodeLib) {
throw new Error('Node library failed to initialize');
}

nodeLib = networkNodeLib;

return all([
Expand Down Expand Up @@ -209,17 +213,6 @@ const checkStatus = () => {
);
loggerInit.info('init/checkStatus/activation complete');
return networkNodeLib;
})
.catch((err) => {
let message = 'Initialization failed';
if (err.message) {
message = err.message;
}
if (err.statusCode && err.statusCode === 402) {
message = err.error.message;
}
loggerInit.error('init/checkStatus Error ', message);
setTimeout(() => { process.exit(1); }, 60 * 1000 * 5);
});
};

Expand Down
Loading

0 comments on commit 4484dd3

Please sign in to comment.