-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
alexeykosinski
committed
Jul 15, 2021
1 parent
11978f4
commit d9d1618
Showing
23 changed files
with
490 additions
and
431 deletions.
There are no files selected for viewing
Binary file not shown.
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
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
This file was deleted.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class AsyncQueue { | ||
constructor(options = {}) { | ||
const { log, error } = options; | ||
this.log = log || console.log; | ||
this.error = error || console.error; | ||
this.queue = []; | ||
this.isRunning = false; | ||
} | ||
|
||
addToQueue(func, data) { | ||
this.queue.push({ func, data }); | ||
} | ||
|
||
emitInQueue = (func, data) => { | ||
this.addToQueue(func, data); | ||
this.runQueue(); | ||
}; | ||
|
||
runQueue() { | ||
if (this.isRunning) { | ||
return; | ||
} | ||
this.isRunning = true; | ||
this.runNext().catch((e) => this.error('runQueue error', e)); | ||
} | ||
|
||
async runNext() { | ||
if (this.queue.length === 0) { | ||
this.isRunning = false; | ||
return; | ||
} | ||
const { func, data } = this.queue.splice(0, 1)[0]; | ||
if (typeof func === 'function') { | ||
await func(data); | ||
} else { | ||
this.log('function in queue not found', { func, data }); | ||
} | ||
await this.runNext(); | ||
} | ||
} | ||
|
||
module.exports = AsyncQueue; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const path = require('path') | ||
const initConfig = require('./config') | ||
const initDB = require('./db') | ||
|
||
const ROOT_PATH = process.cwd(); | ||
|
||
(async function () { | ||
const config = await initConfig(path.resolve(ROOT_PATH, 'config')) | ||
|
||
const db = await initDB() | ||
application.services = { db, config } | ||
|
||
|
||
await application.start(true) | ||
|
||
logger.info('Application started') | ||
})() |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: async (queryInterface, Sequelize) => { | ||
await queryInterface.createTable('strategy', { | ||
id: { | ||
autoIncrement: true, | ||
type: Sequelize.BIGINT, | ||
allowNull: false, | ||
primaryKey: true | ||
}, | ||
status: { | ||
type: Sequelize.STRING, | ||
allowNull: false | ||
}, | ||
profit: { | ||
type: Sequelize.REAL, | ||
allowNull: true | ||
}, | ||
position_side: { | ||
type: Sequelize.STRING, | ||
allowNull: true | ||
}, | ||
symbol: { | ||
type: Sequelize.STRING, | ||
allowNull: true | ||
}, | ||
type: { | ||
type: Sequelize.STRING, | ||
allowNull: true | ||
}, | ||
options:{ | ||
type: Sequelize.JSONB, | ||
allowNull: true, | ||
}, | ||
user_id: { | ||
type: Sequelize.BIGINT, | ||
allowNull: false, | ||
references: { | ||
model: { | ||
tableName: 'user' | ||
}, | ||
key: 'id' | ||
}, | ||
onUpdate: 'cascade', | ||
onDelete: 'cascade' | ||
}, | ||
createdAt: { | ||
type: Sequelize.DATE, | ||
allowNull: false, | ||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'), | ||
}, | ||
updatedAt: { | ||
type: Sequelize.DATE, | ||
allowNull: false, | ||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'), | ||
}, | ||
deletedAt: { | ||
type: Sequelize.DATE, | ||
allowNull: true, | ||
}, | ||
}) | ||
}, | ||
|
||
down: (queryInterface) => { | ||
return queryInterface.dropTable('strategy'); | ||
} | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const { Model, DataTypes } = require('sequelize') | ||
|
||
class Strategy extends Model { | ||
static associate(models) { | ||
Strategy.hasMany(models.Order, { | ||
foreignKey: 'strategyId', | ||
sourceKey: 'id', | ||
as: 'orders' | ||
}); | ||
} | ||
} | ||
module.exports = function (sequelize) { | ||
return Strategy.init( | ||
{ | ||
id: { | ||
autoIncrement: true, | ||
type: DataTypes.BIGINT, | ||
allowNull: false, | ||
primaryKey: true | ||
}, | ||
status: { | ||
type: DataTypes.STRING, | ||
allowNull: false | ||
}, | ||
profit: { | ||
type: DataTypes.REAL, | ||
allowNull: true | ||
}, | ||
positionSide: { | ||
type: DataTypes.STRING, | ||
allowNull: true | ||
}, | ||
symbol: { | ||
type: DataTypes.STRING, | ||
allowNull: true | ||
}, | ||
type: { | ||
type: DataTypes.STRING, | ||
allowNull: true | ||
}, | ||
options:{ | ||
type: DataTypes.JSONB, | ||
allowNull: true, | ||
}, | ||
userId: { | ||
type: DataTypes.BIGINT, | ||
allowNull: false, | ||
references: { | ||
model: { | ||
tableName: 'user' | ||
}, | ||
key: 'id' | ||
}, | ||
onUpdate: 'cascade', | ||
onDelete: 'cascade' | ||
}, | ||
}, | ||
{ | ||
sequelize, | ||
tableName: 'strategy', | ||
timestamps: true, | ||
}, | ||
) | ||
} | ||
|
||
module.exports.Strategy = Strategy |
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
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
Oops, something went wrong.