@silvana-one/orderbook 1.1.9 → 1.1.11

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.
@@ -0,0 +1,245 @@
1
+ import type { GenFile, GenMessage, GenService } from "@bufbuild/protobuf/codegenv2";
2
+ import type { Timestamp } from "@bufbuild/protobuf/wkt";
3
+ import type { Message } from "@bufbuild/protobuf";
4
+ /**
5
+ * Describes the file proto/silvana/news/v1/news.proto.
6
+ */
7
+ export declare const file_proto_silvana_news_v1_news: GenFile;
8
+ /**
9
+ * News article source information
10
+ *
11
+ * @generated from message silvana.news.v1.Source
12
+ */
13
+ export type Source = Message<"silvana.news.v1.Source"> & {
14
+ /**
15
+ * @generated from field: optional string id = 1;
16
+ */
17
+ id?: string;
18
+ /**
19
+ * @generated from field: string name = 2;
20
+ */
21
+ name: string;
22
+ };
23
+ /**
24
+ * Describes the message silvana.news.v1.Source.
25
+ * Use `create(SourceSchema)` to create a new message.
26
+ */
27
+ export declare const SourceSchema: GenMessage<Source>;
28
+ /**
29
+ * News article
30
+ *
31
+ * @generated from message silvana.news.v1.NewsArticle
32
+ */
33
+ export type NewsArticle = Message<"silvana.news.v1.NewsArticle"> & {
34
+ /**
35
+ * @generated from field: silvana.news.v1.Source source = 1;
36
+ */
37
+ source?: Source;
38
+ /**
39
+ * @generated from field: optional string author = 2;
40
+ */
41
+ author?: string;
42
+ /**
43
+ * @generated from field: string title = 3;
44
+ */
45
+ title: string;
46
+ /**
47
+ * @generated from field: optional string description = 4;
48
+ */
49
+ description?: string;
50
+ /**
51
+ * @generated from field: string url = 5;
52
+ */
53
+ url: string;
54
+ /**
55
+ * @generated from field: optional string url_to_image = 6;
56
+ */
57
+ urlToImage?: string;
58
+ /**
59
+ * @generated from field: google.protobuf.Timestamp published_at = 7;
60
+ */
61
+ publishedAt?: Timestamp;
62
+ /**
63
+ * @generated from field: optional string content = 8;
64
+ */
65
+ content?: string;
66
+ /**
67
+ * Total text size (title + description + content)
68
+ *
69
+ * @generated from field: int32 text_size = 9;
70
+ */
71
+ textSize: number;
72
+ };
73
+ /**
74
+ * Describes the message silvana.news.v1.NewsArticle.
75
+ * Use `create(NewsArticleSchema)` to create a new message.
76
+ */
77
+ export declare const NewsArticleSchema: GenMessage<NewsArticle>;
78
+ /**
79
+ * Request for news articles
80
+ *
81
+ * @generated from message silvana.news.v1.GetNewsRequest
82
+ */
83
+ export type GetNewsRequest = Message<"silvana.news.v1.GetNewsRequest"> & {
84
+ /**
85
+ * Cryptocurrency tokens to fetch news for (e.g., "btc", "eth", "mina")
86
+ * If empty, fetches news for default tokens (btc, eth, mina)
87
+ *
88
+ * @generated from field: repeated string tokens = 1;
89
+ */
90
+ tokens: string[];
91
+ /**
92
+ * Maximum number of articles per token
93
+ *
94
+ * Default: 5
95
+ *
96
+ * @generated from field: optional int32 limit = 2;
97
+ */
98
+ limit?: number;
99
+ /**
100
+ * Filter by language (e.g., "en")
101
+ *
102
+ * Default: "en"
103
+ *
104
+ * @generated from field: optional string language = 3;
105
+ */
106
+ language?: string;
107
+ /**
108
+ * Time window in hours (e.g., 48 for last 48 hours)
109
+ *
110
+ * Default: 48
111
+ *
112
+ * @generated from field: optional int32 hours = 4;
113
+ */
114
+ hours?: number;
115
+ };
116
+ /**
117
+ * Describes the message silvana.news.v1.GetNewsRequest.
118
+ * Use `create(GetNewsRequestSchema)` to create a new message.
119
+ */
120
+ export declare const GetNewsRequestSchema: GenMessage<GetNewsRequest>;
121
+ /**
122
+ * Response containing news articles
123
+ *
124
+ * @generated from message silvana.news.v1.GetNewsResponse
125
+ */
126
+ export type GetNewsResponse = Message<"silvana.news.v1.GetNewsResponse"> & {
127
+ /**
128
+ * @generated from field: bool success = 1;
129
+ */
130
+ success: boolean;
131
+ /**
132
+ * @generated from field: string message = 2;
133
+ */
134
+ message: string;
135
+ /**
136
+ * News results grouped by token
137
+ *
138
+ * @generated from field: repeated silvana.news.v1.TokenNews token_news = 3;
139
+ */
140
+ tokenNews: TokenNews[];
141
+ /**
142
+ * Indicates if results were served from cache
143
+ *
144
+ * @generated from field: bool from_cache = 4;
145
+ */
146
+ fromCache: boolean;
147
+ /**
148
+ * Cache expiration time (if from_cache = true)
149
+ *
150
+ * @generated from field: optional google.protobuf.Timestamp cache_expires_at = 5;
151
+ */
152
+ cacheExpiresAt?: Timestamp;
153
+ };
154
+ /**
155
+ * Describes the message silvana.news.v1.GetNewsResponse.
156
+ * Use `create(GetNewsResponseSchema)` to create a new message.
157
+ */
158
+ export declare const GetNewsResponseSchema: GenMessage<GetNewsResponse>;
159
+ /**
160
+ * News articles for a specific token
161
+ *
162
+ * @generated from message silvana.news.v1.TokenNews
163
+ */
164
+ export type TokenNews = Message<"silvana.news.v1.TokenNews"> & {
165
+ /**
166
+ * e.g., "btc", "eth", "mina"
167
+ *
168
+ * @generated from field: string token = 1;
169
+ */
170
+ token: string;
171
+ /**
172
+ * Search query used (e.g., "bitcoin", "ethereum")
173
+ *
174
+ * @generated from field: string query = 2;
175
+ */
176
+ query: string;
177
+ /**
178
+ * @generated from field: int32 total_results = 3;
179
+ */
180
+ totalResults: number;
181
+ /**
182
+ * @generated from field: repeated silvana.news.v1.NewsArticle articles = 4;
183
+ */
184
+ articles: NewsArticle[];
185
+ /**
186
+ * @generated from field: google.protobuf.Timestamp fetched_at = 5;
187
+ */
188
+ fetchedAt?: Timestamp;
189
+ };
190
+ /**
191
+ * Describes the message silvana.news.v1.TokenNews.
192
+ * Use `create(TokenNewsSchema)` to create a new message.
193
+ */
194
+ export declare const TokenNewsSchema: GenMessage<TokenNews>;
195
+ /**
196
+ * Request for streaming news updates
197
+ *
198
+ * @generated from message silvana.news.v1.StreamNewsRequest
199
+ */
200
+ export type StreamNewsRequest = Message<"silvana.news.v1.StreamNewsRequest"> & {
201
+ /**
202
+ * Cryptocurrency tokens to stream news for
203
+ *
204
+ * @generated from field: repeated string tokens = 1;
205
+ */
206
+ tokens: string[];
207
+ /**
208
+ * Minimum time between updates in seconds
209
+ *
210
+ * Default: 300 (5 minutes)
211
+ *
212
+ * @generated from field: optional int32 update_interval = 2;
213
+ */
214
+ updateInterval?: number;
215
+ };
216
+ /**
217
+ * Describes the message silvana.news.v1.StreamNewsRequest.
218
+ * Use `create(StreamNewsRequestSchema)` to create a new message.
219
+ */
220
+ export declare const StreamNewsRequestSchema: GenMessage<StreamNewsRequest>;
221
+ /**
222
+ * @generated from service silvana.news.v1.NewsService
223
+ */
224
+ export declare const NewsService: GenService<{
225
+ /**
226
+ * Get news articles for specific cryptocurrencies
227
+ *
228
+ * @generated from rpc silvana.news.v1.NewsService.GetNews
229
+ */
230
+ getNews: {
231
+ methodKind: "unary";
232
+ input: typeof GetNewsRequestSchema;
233
+ output: typeof GetNewsResponseSchema;
234
+ };
235
+ /**
236
+ * Stream real-time news updates (optional future enhancement)
237
+ *
238
+ * @generated from rpc silvana.news.v1.NewsService.StreamNews
239
+ */
240
+ streamNews: {
241
+ methodKind: "server_streaming";
242
+ input: typeof StreamNewsRequestSchema;
243
+ output: typeof NewsArticleSchema;
244
+ };
245
+ }>;
@@ -0,0 +1,44 @@
1
+ // @generated by protoc-gen-es v2.10.1 with parameter "target=ts,js_import_style=module"
2
+ // @generated from file proto/silvana/news/v1/news.proto (package silvana.news.v1, syntax proto3)
3
+ /* eslint-disable */
4
+ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2";
5
+ import { file_google_protobuf_timestamp } from "@bufbuild/protobuf/wkt";
6
+ /**
7
+ * Describes the file proto/silvana/news/v1/news.proto.
8
+ */
9
+ export const file_proto_silvana_news_v1_news = /*@__PURE__*/ fileDesc("CiBwcm90by9zaWx2YW5hL25ld3MvdjEvbmV3cy5wcm90bxIPc2lsdmFuYS5uZXdzLnYxIi4KBlNvdXJjZRIPCgJpZBgBIAEoCUgAiAEBEgwKBG5hbWUYAiABKAlCBQoDX2lkIq8CCgtOZXdzQXJ0aWNsZRInCgZzb3VyY2UYASABKAsyFy5zaWx2YW5hLm5ld3Mud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ludGVydmFsGAIgASgFSACIAQFCEgoQX3VwZGF0ZV9pbnRlcnZhbDKtAQoLTmV3c1NlcnZpY2USTAoHR2V0TmV3cxIfLnNpbHZhbmEubmV3cy52MS5HZXROZXdzUmVxdWVzdBogLnNpbHZhbmEubmV3cy52MS5HZXROZXdzUmVzcG9uc2USUAoKU3RyZWFtTmV3cxIiLnNpbHZhbmEubmV3cy52MS5TdHJlYW1OZXdzUmVxdWVzdBocLnNpbHZhbmEubmV3cy52MS5OZXdzQXJ0aWNsZTABQi9aLWdpdGh1Yi5jb20vU2lsdmFuYU9uZS9jYW50b24tYWdlbnQvcHJvdG87bmV3c2IGcHJvdG8z", [file_google_protobuf_timestamp]);
10
+ /**
11
+ * Describes the message silvana.news.v1.Source.
12
+ * Use `create(SourceSchema)` to create a new message.
13
+ */
14
+ export const SourceSchema = /*@__PURE__*/ messageDesc(file_proto_silvana_news_v1_news, 0);
15
+ /**
16
+ * Describes the message silvana.news.v1.NewsArticle.
17
+ * Use `create(NewsArticleSchema)` to create a new message.
18
+ */
19
+ export const NewsArticleSchema = /*@__PURE__*/ messageDesc(file_proto_silvana_news_v1_news, 1);
20
+ /**
21
+ * Describes the message silvana.news.v1.GetNewsRequest.
22
+ * Use `create(GetNewsRequestSchema)` to create a new message.
23
+ */
24
+ export const GetNewsRequestSchema = /*@__PURE__*/ messageDesc(file_proto_silvana_news_v1_news, 2);
25
+ /**
26
+ * Describes the message silvana.news.v1.GetNewsResponse.
27
+ * Use `create(GetNewsResponseSchema)` to create a new message.
28
+ */
29
+ export const GetNewsResponseSchema = /*@__PURE__*/ messageDesc(file_proto_silvana_news_v1_news, 3);
30
+ /**
31
+ * Describes the message silvana.news.v1.TokenNews.
32
+ * Use `create(TokenNewsSchema)` to create a new message.
33
+ */
34
+ export const TokenNewsSchema = /*@__PURE__*/ messageDesc(file_proto_silvana_news_v1_news, 4);
35
+ /**
36
+ * Describes the message silvana.news.v1.StreamNewsRequest.
37
+ * Use `create(StreamNewsRequestSchema)` to create a new message.
38
+ */
39
+ export const StreamNewsRequestSchema = /*@__PURE__*/ messageDesc(file_proto_silvana_news_v1_news, 5);
40
+ /**
41
+ * @generated from service silvana.news.v1.NewsService
42
+ */
43
+ export const NewsService = /*@__PURE__*/ serviceDesc(file_proto_silvana_news_v1_news, 0);
44
+ //# sourceMappingURL=news_pb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"news_pb.js","sourceRoot":"","sources":["../../../../../../src/proto/silvana/news/v1/news_pb.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,iGAAiG;AACjG,oBAAoB;AAGpB,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAElF,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;AAGxE;;GAEG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAY,aAAa,CACnE,QAAQ,CAAC,8lDAA8lD,EAAE,CAAC,8BAA8B,CAAC,CAAC,CAAC;AAmB7oD;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAuB,aAAa,CAC3D,WAAW,CAAC,+BAA+B,EAAE,CAAC,CAAC,CAAC;AAwDlD;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAA4B,aAAa,CACrE,WAAW,CAAC,+BAA+B,EAAE,CAAC,CAAC,CAAC;AA4ClD;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAA+B,aAAa,CAC3E,WAAW,CAAC,+BAA+B,EAAE,CAAC,CAAC,CAAC;AAwClD;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAgC,aAAa,CAC7E,WAAW,CAAC,+BAA+B,EAAE,CAAC,CAAC,CAAC;AAsClD;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAA0B,aAAa,CACjE,WAAW,CAAC,+BAA+B,EAAE,CAAC,CAAC,CAAC;AAyBlD;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAkC,aAAa,CACjF,WAAW,CAAC,+BAA+B,EAAE,CAAC,CAAC,CAAC;AAElD;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAqBnB,aAAa,CAChB,WAAW,CAAC,+BAA+B,EAAE,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@silvana-one/orderbook",
3
3
  "description": "Silvana Orderbook Client",
4
- "version": "1.1.9",
4
+ "version": "1.1.11",
5
5
  "author": "DFST",
6
6
  "bugs": "https://github.com/SilvanaOne/silvana-lib/issues",
7
7
  "dependencies": {
@@ -10,9 +10,11 @@
10
10
  "@connectrpc/connect-node": "^2.1.0"
11
11
  },
12
12
  "devDependencies": {
13
+ "@noble/ed25519": "^2.1.0",
13
14
  "@types/node": "^24.9.1",
14
- "esbuild": "^0.25.11",
15
15
  "dotenv": "^17.2.3",
16
+ "esbuild": "^0.25.11",
17
+ "ts-node": "^10.9.2",
16
18
  "typescript": "^5.9.3"
17
19
  },
18
20
  "engines": {
@@ -51,7 +53,8 @@
51
53
  "scripts": {
52
54
  "proto:orderbook": "rm -rf src/proto/silvana/orderbook && mkdir -p proto/silvana && cp -R ../../../canton-agent/proto/silvana/orderbook proto/silvana && buf generate --template buf.gen.orderbook.yaml",
53
55
  "proto:pricing": "rm -rf src/proto/silvana/pricing && mkdir -p proto/silvana && cp -R ../../../canton-agent/proto/silvana/pricing proto/silvana && buf generate --template buf.gen.pricing.yaml",
54
- "proto": "npm run proto:orderbook && npm run proto:pricing",
56
+ "proto:news": "rm -rf src/proto/silvana/news && mkdir -p proto/silvana && cp -R ../../../canton-agent/proto/silvana/news proto/silvana && buf generate --template buf.gen.news.yaml",
57
+ "proto": "npm run proto:orderbook && npm run proto:pricing && npm run proto:news",
55
58
  "build": "rm -rf dist && tsc && tsc --build tsconfig.web.json && node build-cjs.js",
56
59
  "release": "npm publish --access public",
57
60
  "test": "NODE_NO_WARNINGS=1 node --loader=ts-node/esm --enable-source-maps -r dotenv/config --require dotenv/config --env-file=.env --test"
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./orderbook.js";
2
2
  export * from "./pricing.js";
3
+ export * from "./news.js";
package/src/news.ts ADDED
@@ -0,0 +1,105 @@
1
+ import { createGrpcTransport } from "@connectrpc/connect-node";
2
+ import { createClient, ConnectError } from "@connectrpc/connect";
3
+ import { create } from "@bufbuild/protobuf";
4
+
5
+ // Export all types and schemas from the generated protobuf file
6
+ export * from "./proto/silvana/news/v1/news_pb.js";
7
+
8
+ import {
9
+ NewsService,
10
+ type GetNewsResponse,
11
+ GetNewsRequestSchema,
12
+ StreamNewsRequestSchema,
13
+ } from "./proto/silvana/news/v1/news_pb.js";
14
+
15
+ /**
16
+ * Custom error class for News client errors
17
+ */
18
+ export class NewsError extends Error {
19
+ constructor(
20
+ message: string,
21
+ public code?: string,
22
+ public details?: any
23
+ ) {
24
+ super(message);
25
+ this.name = 'NewsError';
26
+ }
27
+ }
28
+
29
+ /**
30
+ * News client configuration
31
+ */
32
+ export interface NewsClientConfig {
33
+ /** Base URL of the news service (e.g., "http://localhost:50054") */
34
+ baseUrl: string;
35
+ }
36
+
37
+ /**
38
+ * News client for interacting with the Silvana News Service
39
+ */
40
+ export class NewsClient {
41
+ private client: ReturnType<typeof createClient<typeof NewsService>>;
42
+
43
+ /**
44
+ * Creates a new NewsClient instance
45
+ * @param config Client configuration
46
+ */
47
+ constructor(config: NewsClientConfig) {
48
+ const transport = createGrpcTransport({
49
+ baseUrl: config.baseUrl,
50
+ });
51
+
52
+ this.client = createClient(NewsService, transport);
53
+ }
54
+
55
+ /**
56
+ * Wraps async calls with error handling
57
+ */
58
+ private async wrapCall<T>(
59
+ operation: () => Promise<T>,
60
+ operationName: string
61
+ ): Promise<T> {
62
+ try {
63
+ return await operation();
64
+ } catch (error) {
65
+ if (error instanceof ConnectError) {
66
+ throw new NewsError(
67
+ `${operationName} failed: ${error.message}`,
68
+ String(error.code),
69
+ error.metadata
70
+ );
71
+ }
72
+ throw new NewsError(
73
+ `${operationName} failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
74
+ 'UNKNOWN',
75
+ error
76
+ );
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Get news articles for specific cryptocurrencies
82
+ */
83
+ async getNews(params?: {
84
+ tokens?: string[];
85
+ limit?: number;
86
+ language?: string;
87
+ hours?: number;
88
+ }): Promise<GetNewsResponse> {
89
+ return await this.wrapCall(async () => {
90
+ const request = create(GetNewsRequestSchema, params || {});
91
+ return await this.client.getNews(request);
92
+ }, 'getNews');
93
+ }
94
+
95
+ /**
96
+ * Stream real-time news updates
97
+ */
98
+ streamNews(params?: {
99
+ tokens?: string[];
100
+ updateInterval?: number;
101
+ }) {
102
+ const request = create(StreamNewsRequestSchema, params || {});
103
+ return this.client.streamNews(request);
104
+ }
105
+ }