Skip to content

Commit

Permalink
Merge pull request #4 from FinBook/live
Browse files Browse the repository at this point in the history
Live
  • Loading branch information
yizhoucao committed Feb 26, 2019
2 parents 1a1e663 + 2235e86 commit 3300219
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 63 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@finbook/duo-market-data",
"version": "1.0.2",
"version": "1.0.3",
"description": "DUO Market Data",
"author": "FinBook Pte Ltd",
"main": "dist/index.js",
Expand Down
77 changes: 49 additions & 28 deletions src/DynamoUtil.ts
Expand Up @@ -112,7 +112,9 @@ export class DynamoUtil {
const data = this.convertTradeToDynamo(trade, systemTimestamp);

const params = {
TableName: `${CST.DB_DUO}.${CST.DB_TRADES}.${this.live ? CST.DB_LIVE : CST.DB_DEV}`,
TableName: this.live
? `${CST.DB_DUO}.${CST.DB_LIVE}.${CST.DB_TRADES}`
: `${CST.DB_DUO}.${CST.DB_TRADES}.${CST.DB_DEV}`,
Item: {
[CST.DB_TX_SRC_DHM]: {
S: trade.source + '|' + moment.utc(trade.timestamp).format('YYYY-MM-DD-HH-mm')
Expand All @@ -127,7 +129,9 @@ export class DynamoUtil {

public async insertEventsData(events: IEvent[]) {
const systime = DynamoUtil.getUTCNowTimestamp();
const TableName = `${CST.DB_DUO}.${CST.DB_EVENTS}.${this.live ? CST.DB_LIVE : CST.DB_DEV}`;
const TableName = this.live
? `${CST.DB_DUO}.${CST.DB_LIVE}.${CST.DB_EVENTS}`
: `${CST.DB_DUO}.${CST.DB_EVENTS}.${CST.DB_DEV}`;
// const putItem: any;

events.forEach(async event => {
Expand All @@ -152,7 +156,9 @@ export class DynamoUtil {

public insertHeartbeat(data: object = {}): Promise<void> {
return this.insertData({
TableName: `${CST.DB_DUO}.${CST.DB_STATUS}.${this.live ? CST.DB_LIVE : CST.DB_DEV}`,
TableName: this.live
? `${CST.DB_DUO}.${CST.DB_LIVE}.${CST.DB_STATUS}`
: `${CST.DB_DUO}.${CST.DB_STATUS}.${CST.DB_DEV}`,
Item: {
[CST.DB_ST_PROCESS]: {
S: this.process
Expand All @@ -165,7 +171,9 @@ export class DynamoUtil {

public insertStatusData(data: object): Promise<void> {
return this.insertData({
TableName: `${CST.DB_DUO}.${CST.DB_STATUS}.${this.live ? CST.DB_LIVE : CST.DB_DEV}`,
TableName: this.live
? `${CST.DB_DUO}.${CST.DB_LIVE}.${CST.DB_STATUS}`
: `${CST.DB_DUO}.${CST.DB_STATUS}.${CST.DB_DEV}`,
Item: {
[CST.DB_ST_PROCESS]: {
S: this.process
Expand All @@ -177,7 +185,10 @@ export class DynamoUtil {

public async readLastBlock(): Promise<number> {
const params = {
TableName: `${CST.DB_DUO}.${CST.DB_STATUS}.${this.live ? CST.DB_LIVE : CST.DB_DEV}`,
TableName: this.live
? `${CST.DB_DUO}.${CST.DB_LIVE}.${CST.DB_STATUS}`
: `${CST.DB_DUO}.${CST.DB_STATUS}.${CST.DB_DEV}`,

KeyConditionExpression: CST.DB_ST_PROCESS + ' = :' + CST.DB_ST_PROCESS,
ExpressionAttributeValues: {
[':' + CST.DB_ST_PROCESS]: { S: CST.DB_STATUS_EVENT_PUBLIC_OTHERS }
Expand All @@ -198,7 +209,9 @@ export class DynamoUtil {
let params: QueryInput;
if (period === 0) {
params = {
TableName: `${CST.DB_DUO}.${CST.DB_TRADES}.${this.live ? CST.DB_LIVE : CST.DB_DEV}`,
TableName: this.live
? `${CST.DB_DUO}.${CST.DB_LIVE}.${CST.DB_TRADES}`
: `${CST.DB_DUO}.${CST.DB_TRADES}.${CST.DB_DEV}`,
KeyConditionExpression: `${CST.DB_SRC_DHM} = :${CST.DB_SRC_DHM}`,
ExpressionAttributeValues: {
[':' + CST.DB_SRC_DHM]: {
Expand Down Expand Up @@ -231,9 +244,9 @@ export class DynamoUtil {
else throw new Error('invalid period');

params = {
TableName: `${CST.DB_DUO}.${CST.DB_PRICES}.${period}.${
this.live ? CST.DB_LIVE : CST.DB_DEV
}`,
TableName: this.live
? `${CST.DB_DUO}.${CST.DB_LIVE}.${CST.DB_PRICES}.${period}`
: `${CST.DB_DUO}.${CST.DB_PRICES}.${period}.${CST.DB_DEV}`,
KeyConditionExpression: keyConditionExpression,
ExpressionAttributeValues: {
[':primaryValue']: primaryValue
Expand Down Expand Up @@ -333,9 +346,9 @@ export class DynamoUtil {
else throw new Error('invalid period');

return this.insertData({
TableName: `${CST.DB_DUO}.${CST.DB_PRICES}.${price.period}.${
this.live ? CST.DB_LIVE : CST.DB_DEV
}`,
TableName: this.live
? `${CST.DB_DUO}.${CST.DB_LIVE}.${CST.DB_PRICES}.${price.period}`
: `${CST.DB_DUO}.${CST.DB_PRICES}.${price.period}.${CST.DB_DEV}`,
Item: data
});
}
Expand Down Expand Up @@ -379,7 +392,9 @@ export class DynamoUtil {
public async getTrades(src: string, dateHourMinute: string, pair: string = '') {
let params: QueryInput;
params = {
TableName: `${CST.DB_DUO}.${CST.DB_TRADES}.${this.live ? CST.DB_LIVE : CST.DB_DEV}`,
TableName: this.live
? `${CST.DB_DUO}.${CST.DB_LIVE}.${CST.DB_TRADES}`
: `${CST.DB_DUO}.${CST.DB_TRADES}.${CST.DB_DEV}`,
KeyConditionExpression: `${CST.DB_SRC_DHM} = :${CST.DB_SRC_DHM}`,
ExpressionAttributeValues: {
[':' + CST.DB_SRC_DHM]: {
Expand Down Expand Up @@ -409,9 +424,9 @@ export class DynamoUtil {
allData.push(
...this.parseAcceptedPrice(
await this.queryData({
TableName: `${CST.DB_DUO}.${CST.DB_EVENTS}.${
this.live ? CST.DB_LIVE : CST.DB_DEV
}`,
TableName: this.live
? `${CST.DB_DUO}.${CST.DB_LIVE}.${CST.DB_EVENTS}`
: `${CST.DB_DUO}.${CST.DB_EVENTS}.${CST.DB_DEV}`,
KeyConditionExpression: CST.DB_EV_KEY + ' = :' + CST.DB_EV_KEY,
ExpressionAttributeValues: {
[':' + CST.DB_EV_KEY]: {
Expand Down Expand Up @@ -448,9 +463,9 @@ export class DynamoUtil {
allData.push(
...this.parseTotalSupply(
await this.queryData({
TableName: `${CST.DB_DUO}.${CST.DB_EVENTS}.${
this.live ? CST.DB_LIVE : CST.DB_DEV
}`,
TableName: this.live
? `${CST.DB_DUO}.${CST.DB_LIVE}.${CST.DB_EVENTS}`
: `${CST.DB_DUO}.${CST.DB_EVENTS}.${CST.DB_DEV}`,
KeyConditionExpression: CST.DB_EV_KEY + ' = :' + CST.DB_EV_KEY,
ExpressionAttributeValues: {
[':' + CST.DB_EV_KEY]: {
Expand Down Expand Up @@ -495,9 +510,9 @@ export class DynamoUtil {
allData.push(
...this.parseConversion(
await this.queryData({
TableName: `${CST.DB_DUO}.${CST.DB_EVENTS}.${
this.live ? CST.DB_LIVE : CST.DB_DEV
}`,
TableName: this.live
? `${CST.DB_DUO}.${CST.DB_LIVE}.${CST.DB_EVENTS}`
: `${CST.DB_DUO}.${CST.DB_EVENTS}.${CST.DB_DEV}`,
KeyConditionExpression: CST.DB_EV_KEY + ' = :' + CST.DB_EV_KEY,
ExpressionAttributeValues: {
[':' + CST.DB_EV_KEY]: { S: ek }
Expand Down Expand Up @@ -529,7 +544,9 @@ export class DynamoUtil {
public async scanStatus() {
return this.parseStatus(
await this.scanData({
TableName: `${CST.DB_DUO}.${CST.DB_STATUS}.${this.live ? CST.DB_LIVE : CST.DB_DEV}`
TableName: this.live
? `${CST.DB_DUO}.${CST.DB_LIVE}.${CST.DB_STATUS}`
: `${CST.DB_DUO}.${CST.DB_STATUS}.${CST.DB_DEV}`
})
);
}
Expand Down Expand Up @@ -576,7 +593,9 @@ export class DynamoUtil {
fee: number
) {
const params = {
TableName: `${CST.DB_DUO}.${CST.DB_UI_EVENTS}.${this.live ? CST.DB_LIVE : CST.DB_DEV}`,
TableName: this.live
? `${CST.DB_DUO}.${CST.DB_LIVE}.${CST.DB_UI_EVENTS}`
: `${CST.DB_DUO}.${CST.DB_UI_EVENTS}.${CST.DB_DEV}`,
Item: {
[CST.DB_EV_KEY]: {
S:
Expand Down Expand Up @@ -608,9 +627,9 @@ export class DynamoUtil {
allData.push(
...this.parseUIConversion(
await this.queryData({
TableName: `${CST.DB_DUO}.${CST.DB_UI_EVENTS}.${
this.live ? CST.DB_LIVE : CST.DB_DEV
}`,
TableName: this.live
? `${CST.DB_DUO}.${CST.DB_LIVE}.${CST.DB_UI_EVENTS}`
: `${CST.DB_DUO}.${CST.DB_UI_EVENTS}.${CST.DB_DEV}`,
KeyConditionExpression: CST.DB_EV_KEY + ' = :' + CST.DB_EV_KEY,
ExpressionAttributeValues: {
[':' + CST.DB_EV_KEY]: { S: ek }
Expand Down Expand Up @@ -643,7 +662,9 @@ export class DynamoUtil {

public deleteUIConversionEvent(account: string, conversion: IConversion): Promise<void> {
return this.deleteData({
TableName: `${CST.DB_DUO}.${CST.DB_UI_EVENTS}.${this.live ? CST.DB_LIVE : CST.DB_DEV}`,
TableName: this.live
? `${CST.DB_DUO}.${CST.DB_LIVE}.${CST.DB_UI_EVENTS}`
: `${CST.DB_DUO}.${CST.DB_UI_EVENTS}.${CST.DB_DEV}`,
Key: {
[CST.DB_EV_KEY]: {
S: conversion.contractAddress + '|' + conversion.type + '|' + account
Expand Down

0 comments on commit 3300219

Please sign in to comment.