Skip to content

Commit

Permalink
Initial DB setup
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbenincasa committed Jan 29, 2022
1 parent 71cd803 commit 49158b2
Show file tree
Hide file tree
Showing 13 changed files with 3,643 additions and 191 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ yarn-error.log*
# typescript
*.tsbuildinfo
.idea/
.vscode/
.vscode/

dev-db
5 changes: 5 additions & 0 deletions app/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Connection, createConnection } from 'typeorm';

export default async function initDb(): Promise<Connection> {
return await createConnection();
}
27 changes: 27 additions & 0 deletions model/db/entity/Execution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { ExecutionType } from '../..';
import { Trade } from './Trade';

@Entity()
export class Execution {
@PrimaryGeneratedColumn('uuid') id: string;
@Column() symbol: string;
@Column() executionTimestamp: Date;
@Column({
type: 'enum',
enum: ExecutionType,
})
executionType: ExecutionType;

@Column() quantity: number;

@Column('money') pricePerShare: number;
@Column('int') pricePerShareScale: number;

@Column('money') totalOutflow: number;
@Column('int') totalOutflowScale: number;

@Column() currency: string;

@ManyToOne(() => Trade, (trade) => trade.executions) trade: Trade;
}
25 changes: 25 additions & 0 deletions model/db/entity/Trade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { Execution } from './Execution';

@Entity()
export class Trade {
@PrimaryGeneratedColumn('uuid') id: string;
@Column() symbol: string;

@OneToMany(() => Execution, (execution) => execution.trade)
executions: Execution[];

@Column() quantity: number;

@Column('bool') isOpen: boolean;

@Column('bool') isShort: boolean;

@Column('money') closedPl: number;
@Column('int') closedPlScale: number;

@Column('money') outflow: number;
@Column('int') outflowScale: number;

@Column() currency: string;
}
23 changes: 23 additions & 0 deletions ormconfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require('dotenv/config');

const database = {
development: 'traderperf_dev',
production: 'prod-db',
test: 'test-db',
};

module.exports = {
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'postgres',
password: 'password',
database: database[process.env.NODE_ENV],
entities: ['./model/db/entity/*{.ts,.js}'],
synchronize: process.env.NODE_ENV !== 'production',
migrationsTableName: 'migration',
migrations: ['migration/*.js'],
cli: {
migrationsDir: 'migration',
},
};
Loading

0 comments on commit 49158b2

Please sign in to comment.