@arken/node 1.5.1 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/db.ts +76 -1
- package/index.ts +351 -18
- package/package.json +3 -3
- package/tsconfig.json +33 -2
- package/util.ts +1 -0
- package/modules/area/area.models.ts +0 -15
- package/modules/area/area.router.ts +0 -74
- package/modules/area/area.schema.ts +0 -22
- package/modules/area/area.service.ts +0 -124
- package/modules/area/area.types.ts +0 -26
- package/modules/area/index.ts +0 -5
- package/modules/asset/asset.models.ts +0 -59
- package/modules/asset/asset.router.ts +0 -55
- package/modules/asset/asset.schema.ts +0 -27
- package/modules/asset/asset.service.ts +0 -85
- package/modules/asset/asset.types.ts +0 -22
- package/modules/asset/index.ts +0 -5
- package/modules/chain/chain.models.ts +0 -50
- package/modules/chain/chain.router.ts +0 -104
- package/modules/chain/chain.schema.ts +0 -52
- package/modules/chain/chain.service.ts +0 -167
- package/modules/chain/chain.types.ts +0 -24
- package/modules/chain/index.ts +0 -5
- package/modules/character/character.models.ts +0 -174
- package/modules/character/character.router.ts +0 -314
- package/modules/character/character.schema.ts +0 -147
- package/modules/character/character.service.ts +0 -876
- package/modules/character/character.types.ts +0 -64
- package/modules/character/index.ts +0 -5
- package/modules/chat/chat.models.ts +0 -43
- package/modules/chat/chat.router.ts +0 -67
- package/modules/chat/chat.schema.ts +0 -36
- package/modules/chat/chat.service.ts +0 -128
- package/modules/chat/chat.types.ts +0 -20
- package/modules/chat/index.ts +0 -5
- package/modules/collection/collection.models.ts +0 -76
- package/modules/collection/collection.router.ts +0 -91
- package/modules/collection/collection.schema.ts +0 -90
- package/modules/collection/collection.service.ts +0 -192
- package/modules/collection/collection.types.ts +0 -36
- package/modules/collection/index.ts +0 -5
- package/modules/core/core.models.ts +0 -1380
- package/modules/core/core.router.ts +0 -1781
- package/modules/core/core.schema.ts +0 -847
- package/modules/core/core.service.ts +0 -2824
- package/modules/core/core.types.ts +0 -340
- package/modules/core/index.ts +0 -5
- package/modules/core/mail/applyPatchesOrMail.ts +0 -568
- package/modules/core/mail/mailClaimablePatchesBatch.ts +0 -381
- package/modules/game/game.models.ts +0 -53
- package/modules/game/game.router.ts +0 -110
- package/modules/game/game.schema.ts +0 -23
- package/modules/game/game.service.ts +0 -143
- package/modules/game/game.types.ts +0 -28
- package/modules/game/index.ts +0 -5
- package/modules/interface/index.ts +0 -5
- package/modules/interface/interface.canonicalize.ts +0 -279
- package/modules/interface/interface.models.ts +0 -40
- package/modules/interface/interface.router.ts +0 -175
- package/modules/interface/interface.schema.ts +0 -59
- package/modules/interface/interface.service.ts +0 -356
- package/modules/interface/interface.types.ts +0 -25
- package/modules/item/index.ts +0 -5
- package/modules/item/item.models.ts +0 -124
- package/modules/item/item.router.ts +0 -103
- package/modules/item/item.schema.ts +0 -120
- package/modules/item/item.service.ts +0 -167
- package/modules/item/item.types.ts +0 -74
- package/modules/job/index.ts +0 -5
- package/modules/job/job.models.ts +0 -14
- package/modules/job/job.router.ts +0 -44
- package/modules/job/job.schema.ts +0 -9
- package/modules/job/job.service.ts +0 -243
- package/modules/job/job.types.ts +0 -23
- package/modules/market/index.ts +0 -5
- package/modules/market/market.models.ts +0 -113
- package/modules/market/market.router.ts +0 -73
- package/modules/market/market.schema.ts +0 -140
- package/modules/market/market.service.ts +0 -122
- package/modules/market/market.types.ts +0 -56
- package/modules/product/index.ts +0 -5
- package/modules/product/product.models.ts +0 -166
- package/modules/product/product.router.ts +0 -93
- package/modules/product/product.schema.ts +0 -149
- package/modules/product/product.service.ts +0 -160
- package/modules/product/product.types.ts +0 -33
- package/modules/profile/index.ts +0 -5
- package/modules/profile/profile.models.ts +0 -214
- package/modules/profile/profile.router.ts +0 -72
- package/modules/profile/profile.schema.ts +0 -156
- package/modules/profile/profile.service.ts +0 -149
- package/modules/profile/profile.types.ts +0 -22
- package/modules/raffle/index.ts +0 -5
- package/modules/raffle/raffle.models.ts +0 -44
- package/modules/raffle/raffle.router.ts +0 -90
- package/modules/raffle/raffle.schema.ts +0 -32
- package/modules/raffle/raffle.service.ts +0 -167
- package/modules/raffle/raffle.types.ts +0 -30
- package/modules/skill/index.ts +0 -5
- package/modules/skill/skill.models.ts +0 -16
- package/modules/skill/skill.router.ts +0 -201
- package/modules/skill/skill.schema.ts +0 -40
- package/modules/skill/skill.service.ts +0 -390
- package/modules/skill/skill.types.ts +0 -33
- package/modules/video/index.ts +0 -5
- package/modules/video/video.models.ts +0 -25
- package/modules/video/video.router.ts +0 -143
- package/modules/video/video.schema.ts +0 -46
- package/modules/video/video.service.ts +0 -274
- package/modules/video/video.types.ts +0 -33
- package/util/db/index.ts +0 -7
- package/util/db/isPostgresError.ts +0 -9
- package/util/db/isUniqueConstraintViolation.ts +0 -3
- package/util/db.ts +0 -62
- package/util/index.ts +0 -351
- /package/{util/api.ts → api.ts} +0 -0
- /package/{util/array.ts → array.ts} +0 -0
- /package/{util/browser.ts → browser.ts} +0 -0
- /package/{util/codebase.ts → codebase.ts} +0 -0
- /package/{util/config.ts → config.ts} +0 -0
- /package/{util/decoder.test.ts → decoder.test.ts} +0 -0
- /package/{util/decoder.ts → decoder.ts} +0 -0
- /package/{util/format.ts → format.ts} +0 -0
- /package/{util/guid.ts → guid.ts} +0 -0
- /package/{util/json.ts → json.ts} +0 -0
- /package/{util/log.ts → log.ts} +0 -0
- /package/{util/math.ts → math.ts} +0 -0
- /package/{util/merkle.ts → merkle.ts} +0 -0
- /package/{util/mongo.ts → mongo.ts} +0 -0
- /package/{util/number.ts → number.ts} +0 -0
- /package/{util/object.ts → object.ts} +0 -0
- /package/{util/otp.ts → otp.ts} +0 -0
- /package/{util/physics.ts → physics.ts} +0 -0
- /package/{util/process.ts → process.ts} +0 -0
- /package/{util/rpc.ts → rpc.ts} +0 -0
- /package/{util/seer.ts → seer.ts} +0 -0
- /package/{util/string.ts → string.ts} +0 -0
- /package/{util/text.ts → text.ts} +0 -0
- /package/{util/time → time}/date.ts +0 -0
- /package/{util/time → time}/fancyTimeFormat.ts +0 -0
- /package/{util/time → time}/index.ts +0 -0
- /package/{util/time → time}/now.ts +0 -0
- /package/{util/types → types}/mongo.d.ts +0 -0
- /package/{util/web3 → web3}/httpProvider.ts +0 -0
- /package/{util/web3.ts → web3.ts} +0 -0
- /package/{util/websocket.ts → websocket.ts} +0 -0
- /package/{util/zk.ts → zk.ts} +0 -0
- /package/{util/zod.ts → zod.ts} +0 -0
package/modules/job/job.types.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// module/job.types.ts
|
|
2
|
-
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
import * as schema from './job.schema';
|
|
5
|
-
import { Document, Model } from '../../util/mongo';
|
|
6
|
-
import type { RouterContext } from '../../types';
|
|
7
|
-
import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
|
|
8
|
-
import type { Router } from './job.router';
|
|
9
|
-
|
|
10
|
-
export type * from './job.router';
|
|
11
|
-
export type * from './job.service';
|
|
12
|
-
export type { RouterContext };
|
|
13
|
-
|
|
14
|
-
export type Job = z.infer<typeof schema.Job>;
|
|
15
|
-
|
|
16
|
-
export type JobDocument = Job & Document;
|
|
17
|
-
|
|
18
|
-
export type Mappings = {
|
|
19
|
-
Job: Model<JobDocument>;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export type RouterInput = inferRouterInputs<Router>;
|
|
23
|
-
export type RouterOutput = inferRouterOutputs<Router>;
|
package/modules/market/index.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import * as mongo from '../../util/mongo';
|
|
2
|
-
import type * as Types from './market.types';
|
|
3
|
-
|
|
4
|
-
export const Market = mongo.createModel<Types.MarketDocument>('Market', {
|
|
5
|
-
value: { type: String, required: true },
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
export const MarketPair = mongo.createModel<Types.MarketPairDocument>('MarketPair', {
|
|
9
|
-
value: { type: String, required: true },
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
export const MarketExchange = mongo.createModel<Types.MarketExchangeDocument>('MarketExchange', {
|
|
13
|
-
value: { type: String },
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export const MarketAnalysis = mongo.createModel<Types.MarketAnalysisDocument>('MarketAnalysis', {
|
|
17
|
-
action: { type: String, required: true },
|
|
18
|
-
asset: { type: String, required: true },
|
|
19
|
-
signalType: { type: String, required: true },
|
|
20
|
-
confidence: { type: Number, required: true },
|
|
21
|
-
riskLevel: { type: String, required: true },
|
|
22
|
-
timeFrame: { type: String, required: true },
|
|
23
|
-
source: { type: String, required: true },
|
|
24
|
-
summary: { type: String, required: true },
|
|
25
|
-
labels: {
|
|
26
|
-
sector: { type: String },
|
|
27
|
-
topic: { type: String },
|
|
28
|
-
sentiment: { type: String },
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
export const MarketInvestor = mongo.createModel<Types.MarketInvestorDocument>('MarketInvestor', {
|
|
33
|
-
portfolioIds: [{ type: mongo.Schema.Types.ObjectId, required: true }],
|
|
34
|
-
totalPnl: { type: Number },
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
export const MarketInvestmentPortfolio = mongo.createModel<Types.MarketInvestmentPortfolioDocument>(
|
|
38
|
-
'MarketInvestmentPortfolio',
|
|
39
|
-
{
|
|
40
|
-
categoryGoals: [
|
|
41
|
-
{
|
|
42
|
-
category: { type: String, required: true },
|
|
43
|
-
goalPercentage: { type: Number, required: true },
|
|
44
|
-
currentPnL: { type: Number },
|
|
45
|
-
historicalPnL: { type: Number },
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
investmentIds: [{ type: mongo.Schema.Types.ObjectId, required: true }],
|
|
49
|
-
totalPnl: { type: Number },
|
|
50
|
-
}
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
export const MarketInvestment = mongo.createModel<Types.MarketInvestmentDocument>('MarketInvestment', {
|
|
54
|
-
type: { type: String, required: true },
|
|
55
|
-
amount: { type: Number, required: true },
|
|
56
|
-
category: { type: String, required: true },
|
|
57
|
-
purchasePrice: { type: Number, required: true },
|
|
58
|
-
currentValue: { type: Number, required: true },
|
|
59
|
-
pnl: { type: Number, required: true },
|
|
60
|
-
transactions: [
|
|
61
|
-
{
|
|
62
|
-
date: { type: Date, required: true },
|
|
63
|
-
type: { type: String, required: true },
|
|
64
|
-
price: { type: Number, required: true },
|
|
65
|
-
quantity: { type: Number, required: true },
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
stockId: { type: mongo.Schema.Types.ObjectId },
|
|
69
|
-
chainTokenId: { type: mongo.Schema.Types.ObjectId },
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
export const MarketStock = mongo.createModel<Types.MarketStockDocument>('MarketStock', {
|
|
73
|
-
ticker: { type: String, required: true },
|
|
74
|
-
companyId: { type: mongo.Schema.Types.ObjectId, required: true, ref: 'StockCompany' },
|
|
75
|
-
currentPrice: { type: Number, required: true },
|
|
76
|
-
marketCap: { type: Number },
|
|
77
|
-
volume: { type: Number },
|
|
78
|
-
currency: { type: String, required: true },
|
|
79
|
-
aum: { type: Number },
|
|
80
|
-
quoteType: { type: String },
|
|
81
|
-
dailyChange: { type: Number },
|
|
82
|
-
dailyChangePercent: { type: Number },
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
export const MarketToken = mongo.createModel<Types.MarketTokenDocument>('MarketToken', {
|
|
86
|
-
symbol: { type: String, required: true },
|
|
87
|
-
currentPrice: { type: Number, required: true },
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
export const MarketCompany = mongo.createModel<Types.MarketCompanyDocument>('MarketCompany', {
|
|
91
|
-
ticker: { type: String, required: true },
|
|
92
|
-
country: { type: String, required: true },
|
|
93
|
-
industry: { type: String, required: true },
|
|
94
|
-
sector: { type: String, required: true },
|
|
95
|
-
type: { type: String, required: true },
|
|
96
|
-
issuedETFs: [{ type: mongo.Schema.Types.ObjectId, ref: 'MarketETF' }],
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
export const MarketETF = mongo.createModel<Types.MarketETFDocument>('ETF', {
|
|
100
|
-
ticker: { type: String, required: true },
|
|
101
|
-
issuerId: { type: mongo.Schema.Types.ObjectId, required: true },
|
|
102
|
-
leverage: { type: Number, required: false },
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
export const MarketStockSentiment = mongo.createModel<Types.MarketStockSentimentDocument>('MarketStockSentiment', {
|
|
106
|
-
ticker: { type: String, required: true },
|
|
107
|
-
companyId: { type: mongo.Schema.Types.ObjectId, required: true, ref: 'StockCompany' },
|
|
108
|
-
sentiment: {
|
|
109
|
-
label: { type: String, required: true },
|
|
110
|
-
score: { type: Number, required: true },
|
|
111
|
-
},
|
|
112
|
-
confidence: { type: Number, required: true },
|
|
113
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
// module/market.router.ts
|
|
2
|
-
|
|
3
|
-
import { z as zod } from 'zod';
|
|
4
|
-
import { initTRPC, inferRouterInputs, inferRouterOutputs } from '@trpc/server';
|
|
5
|
-
import { customErrorFormatter, hasRole } from '../../util/rpc';
|
|
6
|
-
import type { RouterContext } from '../../types';
|
|
7
|
-
import { Market, MarketPair, MarketExchange } from './market.schema';
|
|
8
|
-
|
|
9
|
-
export const z = zod;
|
|
10
|
-
export const t = initTRPC.context<RouterContext>().create();
|
|
11
|
-
export const router = t.router;
|
|
12
|
-
export const procedure = t.procedure;
|
|
13
|
-
|
|
14
|
-
export const createRouter = () =>
|
|
15
|
-
router({
|
|
16
|
-
getMarket: procedure
|
|
17
|
-
.use(hasRole('guest', t))
|
|
18
|
-
.use(customErrorFormatter(t))
|
|
19
|
-
.input(z.object({ marketId: z.string() }))
|
|
20
|
-
.query(({ input, ctx }) => (ctx.app.service.Market.getMarket as any)(input, ctx)),
|
|
21
|
-
|
|
22
|
-
createMarket: procedure
|
|
23
|
-
.use(hasRole('admin', t))
|
|
24
|
-
.use(customErrorFormatter(t))
|
|
25
|
-
.input(Market)
|
|
26
|
-
.mutation(({ input, ctx }) => (ctx.app.service.Market.createMarket as any)(input, ctx)),
|
|
27
|
-
|
|
28
|
-
updateMarket: procedure
|
|
29
|
-
.use(hasRole('admin', t))
|
|
30
|
-
.use(customErrorFormatter(t))
|
|
31
|
-
.input(z.object({ marketId: z.string(), data: Market.partial() }))
|
|
32
|
-
.mutation(({ input, ctx }) => (ctx.app.service.Market.updateMarket as any)(input, ctx)),
|
|
33
|
-
|
|
34
|
-
getMarketPair: procedure
|
|
35
|
-
.use(hasRole('guest', t))
|
|
36
|
-
.use(customErrorFormatter(t))
|
|
37
|
-
.input(z.object({ marketPairId: z.string() }))
|
|
38
|
-
.query(({ input, ctx }) => (ctx.app.service.Market.getMarketPair as any)(input, ctx)),
|
|
39
|
-
|
|
40
|
-
createMarketPair: procedure
|
|
41
|
-
.use(hasRole('admin', t))
|
|
42
|
-
.use(customErrorFormatter(t))
|
|
43
|
-
.input(MarketPair)
|
|
44
|
-
.mutation(({ input, ctx }) => (ctx.app.service.Market.createMarketPair as any)(input, ctx)),
|
|
45
|
-
|
|
46
|
-
updateMarketPair: procedure
|
|
47
|
-
.use(hasRole('admin', t))
|
|
48
|
-
.use(customErrorFormatter(t))
|
|
49
|
-
.input(z.object({ marketPairId: z.string(), data: MarketPair.partial() }))
|
|
50
|
-
.mutation(({ input, ctx }) => (ctx.app.service.Market.updateMarketPair as any)(input, ctx)),
|
|
51
|
-
|
|
52
|
-
getMarketExchange: procedure
|
|
53
|
-
.use(hasRole('guest', t))
|
|
54
|
-
.use(customErrorFormatter(t))
|
|
55
|
-
.input(z.object({ exchangeId: z.string() }))
|
|
56
|
-
.query(({ input, ctx }) => (ctx.app.service.Market.getMarketExchange as any)(input, ctx)),
|
|
57
|
-
|
|
58
|
-
createMarketExchange: procedure
|
|
59
|
-
.use(hasRole('admin', t))
|
|
60
|
-
.use(customErrorFormatter(t))
|
|
61
|
-
.input(MarketExchange)
|
|
62
|
-
.mutation(({ input, ctx }) => (ctx.app.service.Market.createMarketExchange as any)(input, ctx)),
|
|
63
|
-
|
|
64
|
-
updateMarketExchange: procedure
|
|
65
|
-
.use(hasRole('admin', t))
|
|
66
|
-
.use(customErrorFormatter(t))
|
|
67
|
-
.input(z.object({ exchangeId: z.string(), data: MarketExchange.partial() }))
|
|
68
|
-
.mutation(({ input, ctx }) => (ctx.app.service.Market.updateMarketExchange as any)(input, ctx)),
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
export type Router = ReturnType<typeof createRouter>;
|
|
72
|
-
export type RouterInput = inferRouterInputs<Router>;
|
|
73
|
-
export type RouterOutput = inferRouterOutputs<Router>;
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { z, Entity, ObjectId } from '../../schema';
|
|
2
|
-
|
|
3
|
-
export const Market = Entity.merge(
|
|
4
|
-
z.object({
|
|
5
|
-
value: z.string(),
|
|
6
|
-
})
|
|
7
|
-
);
|
|
8
|
-
|
|
9
|
-
export const MarketPair = Entity.merge(
|
|
10
|
-
z.object({
|
|
11
|
-
value: z.string(),
|
|
12
|
-
})
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
export const MarketExchange = Entity.merge(
|
|
16
|
-
z.object({
|
|
17
|
-
value: z.string(),
|
|
18
|
-
})
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
export const MarketAnalysis = Entity.merge(
|
|
22
|
-
z.object({
|
|
23
|
-
action: z.enum(['Buy', 'Sell']), // buy or sell action
|
|
24
|
-
asset: z.string().min(1), // the asset being traded (e.g., oil, Bitcoin)
|
|
25
|
-
signalType: z.string().min(1), // type of signal (e.g., news)
|
|
26
|
-
confidence: z.number().min(0).max(100), // confidence level from 0 to 100
|
|
27
|
-
riskLevel: z.enum(['Low', 'Medium', 'High']), // risk level
|
|
28
|
-
timeFrame: z.enum(['Short-Term', 'Long-Term']), // investment time frame
|
|
29
|
-
source: z.string().min(1), // source of information (e.g., FinancialJuice, Ground News)
|
|
30
|
-
summary: z.string().min(1), // summary of the analysis
|
|
31
|
-
labels: z.object({
|
|
32
|
-
sector: z.string().optional(), // sector related to the asset (e.g., energy, aviation)
|
|
33
|
-
topic: z.string().optional(), // topic of the news (e.g., oil demand, job cuts)
|
|
34
|
-
sentiment: z.enum(['Positive', 'Neutral', 'Negative']).optional(), // sentiment of the news
|
|
35
|
-
}),
|
|
36
|
-
})
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
export const MarketInvestor = Entity.merge(
|
|
40
|
-
z.object({
|
|
41
|
-
portfolioIds: z.array(ObjectId), // Array of ObjectId references to InvestmentPortfolio
|
|
42
|
-
totalPnl: z.number().optional(), // Total profit and loss
|
|
43
|
-
})
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
export const MarketInvestmentPortfolio = Entity.merge(
|
|
47
|
-
z.object({
|
|
48
|
-
categoryGoals: z.array(
|
|
49
|
-
z.object({
|
|
50
|
-
category: z.string(), // Category name
|
|
51
|
-
goalPercentage: z.number(), // Goal percentage for this category
|
|
52
|
-
currentPnl: z.number().optional(), // Current P&L for this category
|
|
53
|
-
historicalPnL: z.number().optional(), // Historical P&L for this category
|
|
54
|
-
})
|
|
55
|
-
), // Array of categories with goal percentages and P&L tracking
|
|
56
|
-
investmentIds: z.array(ObjectId), // Array of ObjectId references to Investment
|
|
57
|
-
totalPnl: z.number().optional(), // Total P&L for this portfolio
|
|
58
|
-
})
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
export const MarketInvestment = Entity.merge(
|
|
62
|
-
z.object({
|
|
63
|
-
type: z.enum(['Stock', 'ChainToken']),
|
|
64
|
-
category: z.enum(['Historically Safe', 'Economy Bull', 'Economy Bear', 'Custom']),
|
|
65
|
-
amount: z.number(), // Initial amount invested
|
|
66
|
-
purchasePrice: z.number(), // Price at which the investment was purchased
|
|
67
|
-
currentValue: z.number().optional(), // Current value of the investment
|
|
68
|
-
pnl: z.number().optional(), // Current P&L of the investment
|
|
69
|
-
transactions: z
|
|
70
|
-
.array(
|
|
71
|
-
z.object({
|
|
72
|
-
date: z.string(), // Date of transaction
|
|
73
|
-
type: z.enum(['Buy', 'Sell']),
|
|
74
|
-
price: z.number(), // Price at transaction
|
|
75
|
-
quantity: z.number(), // Quantity bought or sold
|
|
76
|
-
})
|
|
77
|
-
)
|
|
78
|
-
.optional(), // Optional array for detailed transaction history
|
|
79
|
-
stockId: ObjectId.optional(), // Reference to Stock if type is 'Stock'
|
|
80
|
-
chainTokenId: ObjectId.optional(), // Reference to ChainToken if type is 'ChainToken'
|
|
81
|
-
})
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
export const MarketStock = Entity.merge(
|
|
85
|
-
z.object({
|
|
86
|
-
ticker: z.string(),
|
|
87
|
-
companyId: ObjectId,
|
|
88
|
-
marketCap: z.number().optional(),
|
|
89
|
-
aum: z.number().optional(),
|
|
90
|
-
quoteType: z.string(),
|
|
91
|
-
currentPrice: z.number(),
|
|
92
|
-
dailyChange: z.number().optional(),
|
|
93
|
-
dailyChangePercent: z.number().optional(),
|
|
94
|
-
volume: z.number(),
|
|
95
|
-
currency: z.string(),
|
|
96
|
-
})
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
export const MarketToken = Entity.merge(
|
|
100
|
-
z.object({
|
|
101
|
-
symbol: z.string(),
|
|
102
|
-
currentPrice: z.number(),
|
|
103
|
-
})
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
export const MarketCompany = Entity.merge(
|
|
107
|
-
z.object({
|
|
108
|
-
ticker: z.string(), // Primary ticker, if applicable
|
|
109
|
-
type: z.enum(['Public Company', 'ETF Issuer', 'Both', 'Other']), // Categorize the company type
|
|
110
|
-
country: z.string().optional(), // Country where the company is based
|
|
111
|
-
industry: z.string().optional(), // Industry the company operates in
|
|
112
|
-
sector: z.string().optional(), // Sector the company belongs to
|
|
113
|
-
issuedETFs: z.array(ObjectId).optional(), // References to ETFs issued by this company
|
|
114
|
-
})
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
export const MarketETF = Entity.merge(
|
|
118
|
-
z.object({
|
|
119
|
-
ticker: z.string(),
|
|
120
|
-
issuerId: ObjectId, // Reference to the Company issuing the ETF
|
|
121
|
-
leverage: z.number().optional(), // Leverage factor if applicable (e.g., 3x)
|
|
122
|
-
country: z.string().optional(), // Country where the ETF is based
|
|
123
|
-
currency: z.string().optional(), // Currency the ETF is traded in
|
|
124
|
-
AUM: z.number().optional(), // Assets under management
|
|
125
|
-
industry: z.string().optional(), // Industry the ETF is focused on
|
|
126
|
-
sector: z.string().optional(), // Sector the ETF is focused on
|
|
127
|
-
})
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
export const MarketStockSentiment = Entity.merge(
|
|
131
|
-
z.object({
|
|
132
|
-
ticker: z.string(),
|
|
133
|
-
companyId: ObjectId,
|
|
134
|
-
sentiment: z.object({
|
|
135
|
-
label: z.enum(['Positive', 'Neutral', 'Negative']), // predefined sentiment labels
|
|
136
|
-
score: z.number().min(0).max(1), // sentiment score as a confidence percentage
|
|
137
|
-
}),
|
|
138
|
-
confidence: z.number().min(0).max(1), // overall confidence level for the analysis
|
|
139
|
-
})
|
|
140
|
-
);
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
// module/market.service.ts
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
Market,
|
|
5
|
-
MarketPair,
|
|
6
|
-
MarketExchange,
|
|
7
|
-
RouterContext,
|
|
8
|
-
Router,
|
|
9
|
-
RouterInput,
|
|
10
|
-
RouterOutput,
|
|
11
|
-
} from './market.types';
|
|
12
|
-
|
|
13
|
-
export class Service {
|
|
14
|
-
async getMarket(input: RouterInput['getMarket'], ctx: RouterContext): Promise<RouterOutput['getMarket']> {
|
|
15
|
-
if (!input) throw new Error('Input should not be void');
|
|
16
|
-
console.log('Market.Service.getMarket', input.marketId);
|
|
17
|
-
|
|
18
|
-
const market = await ctx.app.model.Market.findById(input.marketId).lean().exec();
|
|
19
|
-
if (!market) throw new Error('Market not found');
|
|
20
|
-
|
|
21
|
-
return market as Market;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async createMarket(input: RouterInput['createMarket'], ctx: RouterContext): Promise<RouterOutput['createMarket']> {
|
|
25
|
-
if (!input) throw new Error('Input should not be void');
|
|
26
|
-
console.log('Market.Service.createMarket', input);
|
|
27
|
-
|
|
28
|
-
const market = await ctx.app.model.Market.create(input);
|
|
29
|
-
return market as Market;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async updateMarket(input: RouterInput['updateMarket'], ctx: RouterContext): Promise<RouterOutput['updateMarket']> {
|
|
33
|
-
if (!input) throw new Error('Input should not be void');
|
|
34
|
-
console.log('Market.Service.updateMarket', input.marketId, input.data);
|
|
35
|
-
|
|
36
|
-
const updatedMarket = await ctx.app.model.Market.findByIdAndUpdate(input.marketId, input.data, { new: true })
|
|
37
|
-
.lean()
|
|
38
|
-
.exec();
|
|
39
|
-
if (!updatedMarket) throw new Error('Market update failed');
|
|
40
|
-
|
|
41
|
-
return updatedMarket as Market;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async getMarketPair(input: RouterInput['getMarketPair'], ctx: RouterContext): Promise<RouterOutput['getMarketPair']> {
|
|
45
|
-
if (!input) throw new Error('Input should not be void');
|
|
46
|
-
console.log('Market.Service.getMarketPair', input.marketPairId);
|
|
47
|
-
|
|
48
|
-
const marketPair = await ctx.app.model.MarketPair.findById(input.marketPairId).lean().exec();
|
|
49
|
-
if (!marketPair) throw new Error('MarketPair not found');
|
|
50
|
-
|
|
51
|
-
return marketPair as MarketPair;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async createMarketPair(
|
|
55
|
-
input: RouterInput['createMarketPair'],
|
|
56
|
-
ctx: RouterContext
|
|
57
|
-
): Promise<RouterOutput['createMarketPair']> {
|
|
58
|
-
if (!input) throw new Error('Input should not be void');
|
|
59
|
-
console.log('Market.Service.createMarketPair', input);
|
|
60
|
-
|
|
61
|
-
const marketPair = await ctx.app.model.MarketPair.create(input);
|
|
62
|
-
return marketPair as MarketPair;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async updateMarketPair(
|
|
66
|
-
input: RouterInput['updateMarketPair'],
|
|
67
|
-
ctx: RouterContext
|
|
68
|
-
): Promise<RouterOutput['updateMarketPair']> {
|
|
69
|
-
if (!input) throw new Error('Input should not be void');
|
|
70
|
-
console.log('Market.Service.updateMarketPair', input.marketPairId, input.data);
|
|
71
|
-
|
|
72
|
-
const updatedMarketPair = await ctx.app.model.MarketPair.findByIdAndUpdate(input.marketPairId, input.data, {
|
|
73
|
-
new: true,
|
|
74
|
-
})
|
|
75
|
-
.lean()
|
|
76
|
-
.exec();
|
|
77
|
-
if (!updatedMarketPair) throw new Error('MarketPair update failed');
|
|
78
|
-
|
|
79
|
-
return updatedMarketPair as MarketPair;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async getMarketExchange(
|
|
83
|
-
input: RouterInput['getMarketExchange'],
|
|
84
|
-
ctx: RouterContext
|
|
85
|
-
): Promise<RouterOutput['getMarketExchange']> {
|
|
86
|
-
if (!input) throw new Error('Input should not be void');
|
|
87
|
-
console.log('Market.Service.getMarketExchange', input.exchangeId);
|
|
88
|
-
|
|
89
|
-
const marketExchange = await ctx.app.model.MarketExchange.findById(input.exchangeId).lean().exec();
|
|
90
|
-
if (!marketExchange) throw new Error('MarketExchange not found');
|
|
91
|
-
|
|
92
|
-
return marketExchange as MarketExchange;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
async createMarketExchange(
|
|
96
|
-
input: RouterInput['createMarketExchange'],
|
|
97
|
-
ctx: RouterContext
|
|
98
|
-
): Promise<RouterOutput['createMarketExchange']> {
|
|
99
|
-
if (!input) throw new Error('Input should not be void');
|
|
100
|
-
console.log('Market.Service.createMarketExchange', input);
|
|
101
|
-
|
|
102
|
-
const marketExchange = await ctx.app.model.MarketExchange.create(input);
|
|
103
|
-
return marketExchange as MarketExchange;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async updateMarketExchange(
|
|
107
|
-
input: RouterInput['updateMarketExchange'],
|
|
108
|
-
ctx: RouterContext
|
|
109
|
-
): Promise<RouterOutput['updateMarketExchange']> {
|
|
110
|
-
if (!input) throw new Error('Input should not be void');
|
|
111
|
-
console.log('Market.Service.updateMarketExchange', input.exchangeId, input.data);
|
|
112
|
-
|
|
113
|
-
const updatedMarketExchange = await ctx.app.model.MarketExchange.findByIdAndUpdate(input.exchangeId, input.data, {
|
|
114
|
-
new: true,
|
|
115
|
-
})
|
|
116
|
-
.lean()
|
|
117
|
-
.exec();
|
|
118
|
-
if (!updatedMarketExchange) throw new Error('MarketExchange update failed');
|
|
119
|
-
|
|
120
|
-
return updatedMarketExchange as MarketExchange;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
// module/market.types.ts
|
|
2
|
-
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
import * as schema from './market.schema';
|
|
5
|
-
import { Document, Model } from '../../util/mongo';
|
|
6
|
-
import type { RouterContext } from '../../types';
|
|
7
|
-
import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
|
|
8
|
-
import type { Router } from './market.router';
|
|
9
|
-
|
|
10
|
-
export type * from './market.router';
|
|
11
|
-
export type * from './market.service';
|
|
12
|
-
export type { RouterContext };
|
|
13
|
-
|
|
14
|
-
export type Market = z.infer<typeof schema.Market>;
|
|
15
|
-
export type MarketPair = z.infer<typeof schema.MarketPair>;
|
|
16
|
-
export type MarketExchange = z.infer<typeof schema.MarketExchange>;
|
|
17
|
-
export type MarketAnalysis = z.infer<typeof schema.MarketAnalysis>;
|
|
18
|
-
export type MarketInvestor = z.infer<typeof schema.MarketInvestor>;
|
|
19
|
-
export type MarketInvestmentPortfolio = z.infer<typeof schema.MarketInvestmentPortfolio>;
|
|
20
|
-
export type MarketInvestment = z.infer<typeof schema.MarketInvestment>;
|
|
21
|
-
export type MarketStock = z.infer<typeof schema.MarketStock>;
|
|
22
|
-
export type MarketToken = z.infer<typeof schema.MarketToken>;
|
|
23
|
-
export type MarketCompany = z.infer<typeof schema.MarketCompany>;
|
|
24
|
-
export type MarketETF = z.infer<typeof schema.MarketETF>;
|
|
25
|
-
export type MarketStockSentiment = z.infer<typeof schema.MarketStockSentiment>;
|
|
26
|
-
|
|
27
|
-
export type MarketDocument = Market & Document;
|
|
28
|
-
export type MarketPairDocument = MarketPair & Document;
|
|
29
|
-
export type MarketExchangeDocument = MarketExchange & Document;
|
|
30
|
-
export type MarketAnalysisDocument = MarketAnalysis & Document;
|
|
31
|
-
export type MarketInvestorDocument = MarketInvestor & Document;
|
|
32
|
-
export type MarketInvestmentPortfolioDocument = MarketInvestmentPortfolio & Document;
|
|
33
|
-
export type MarketInvestmentDocument = MarketInvestment & Document;
|
|
34
|
-
export type MarketStockDocument = MarketStock & Document;
|
|
35
|
-
export type MarketTokenDocument = MarketToken & Document;
|
|
36
|
-
export type MarketCompanyDocument = MarketCompany & Document;
|
|
37
|
-
export type MarketETFDocument = MarketETF & Document;
|
|
38
|
-
export type MarketStockSentimentDocument = MarketStockSentiment & Document;
|
|
39
|
-
|
|
40
|
-
export type Mappings = {
|
|
41
|
-
Market: Model<MarketDocument>;
|
|
42
|
-
MarketPair: Model<MarketPairDocument>;
|
|
43
|
-
MarketExchange: Model<MarketExchangeDocument>;
|
|
44
|
-
MarketAnalysis: Model<MarketAnalysisDocument>;
|
|
45
|
-
MarketInvestor: Model<MarketInvestorDocument>;
|
|
46
|
-
MarketInvestmentPortfolio: Model<MarketInvestmentPortfolioDocument>;
|
|
47
|
-
MarketInvestment: Model<MarketInvestmentDocument>;
|
|
48
|
-
MarketStock: Model<MarketStockDocument>;
|
|
49
|
-
MarketToken: Model<MarketTokenDocument>;
|
|
50
|
-
MarketCompany: Model<MarketCompanyDocument>;
|
|
51
|
-
MarketETF: Model<MarketETFDocument>;
|
|
52
|
-
MarketStockSentiment: Model<MarketStockSentimentDocument>;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export type RouterInput = inferRouterInputs<Router>;
|
|
56
|
-
export type RouterOutput = inferRouterOutputs<Router>;
|