@ganaka/sdk 0.0.1
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/LICENSE +41 -0
- package/README.md +260 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.js +8450 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +8450 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +102 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ganaka
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# Ganaka SDK
|
|
2
|
+
|
|
3
|
+
TypeScript/JavaScript client library for the Ganaka trading platform.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the package using your preferred package manager:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @ganaka/sdk
|
|
11
|
+
# or
|
|
12
|
+
yarn add @ganaka/sdk
|
|
13
|
+
# or
|
|
14
|
+
pnpm add @ganaka/sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { GanakaClient } from "@ganaka/sdk";
|
|
21
|
+
|
|
22
|
+
// Initialize the client
|
|
23
|
+
const client = new GanakaClient({
|
|
24
|
+
apiKey: "your-api-key",
|
|
25
|
+
baseUrl: "https://api.ganaka.com",
|
|
26
|
+
debug: true,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Check API health
|
|
30
|
+
const health = await client.health();
|
|
31
|
+
console.log(health);
|
|
32
|
+
|
|
33
|
+
// Get shortlists
|
|
34
|
+
const shortlists = await client.getShortlists();
|
|
35
|
+
if (shortlists.success) {
|
|
36
|
+
console.log("Shortlists:", shortlists.data);
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Configuration
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
const client = new GanakaClient({
|
|
44
|
+
apiKey: "your-api-key", // API key for authentication
|
|
45
|
+
baseUrl: "http://localhost:3000", // API base URL
|
|
46
|
+
wsUrl: "ws://localhost:3000", // WebSocket URL for real-time data
|
|
47
|
+
timeout: 30000, // Request timeout in milliseconds
|
|
48
|
+
debug: false, // Enable debug logging
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## API Methods
|
|
53
|
+
|
|
54
|
+
### Shortlists
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
// Get all shortlists
|
|
58
|
+
const shortlists = await client.getShortlists();
|
|
59
|
+
|
|
60
|
+
// Get a specific shortlist
|
|
61
|
+
const shortlist = await client.getShortlist("shortlist-id");
|
|
62
|
+
|
|
63
|
+
// Create a new shortlist
|
|
64
|
+
const newShortlist = await client.createShortlist({
|
|
65
|
+
name: "My Watchlist",
|
|
66
|
+
symbols: ["AAPL", "GOOGL", "MSFT"],
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Update a shortlist
|
|
70
|
+
const updated = await client.updateShortlist("shortlist-id", {
|
|
71
|
+
name: "Updated Watchlist",
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Delete a shortlist
|
|
75
|
+
await client.deleteShortlist("shortlist-id");
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Instruments
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
// Search instruments
|
|
82
|
+
const results = await client.searchInstruments("apple");
|
|
83
|
+
|
|
84
|
+
// Get instrument details
|
|
85
|
+
const instrument = await client.getInstrument("AAPL");
|
|
86
|
+
|
|
87
|
+
// Get multiple instruments
|
|
88
|
+
const instruments = await client.getInstruments(["AAPL", "GOOGL"]);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Strategies
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
// Get all strategies
|
|
95
|
+
const strategies = await client.getStrategies();
|
|
96
|
+
|
|
97
|
+
// Create a strategy
|
|
98
|
+
const strategy = await client.createStrategy({
|
|
99
|
+
name: "My Strategy",
|
|
100
|
+
type: "momentum",
|
|
101
|
+
parameters: {
|
|
102
|
+
period: 20,
|
|
103
|
+
threshold: 0.02,
|
|
104
|
+
},
|
|
105
|
+
status: "inactive",
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Start/stop a strategy
|
|
109
|
+
await client.startStrategy("strategy-id");
|
|
110
|
+
await client.stopStrategy("strategy-id");
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Orders
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
// Place an order
|
|
117
|
+
const order = await client.placeOrder({
|
|
118
|
+
symbol: "AAPL",
|
|
119
|
+
quantity: 100,
|
|
120
|
+
orderType: "market",
|
|
121
|
+
side: "buy",
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Get orders
|
|
125
|
+
const orders = await client.getOrders();
|
|
126
|
+
|
|
127
|
+
// Cancel an order
|
|
128
|
+
await client.cancelOrder("order-id");
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## WebSocket - Real-time Data
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
// Get WebSocket client
|
|
135
|
+
const ws = client.getWebSocket();
|
|
136
|
+
|
|
137
|
+
// Connect to WebSocket
|
|
138
|
+
await client.connectWebSocket();
|
|
139
|
+
|
|
140
|
+
// Subscribe to events
|
|
141
|
+
ws.on("connected", () => {
|
|
142
|
+
console.log("Connected to real-time data");
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
ws.on("tick", (data) => {
|
|
146
|
+
console.log("Tick data:", data);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
ws.on("error", (error) => {
|
|
150
|
+
console.error("WebSocket error:", error);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// Subscribe to tick data for symbols
|
|
154
|
+
ws.subscribeTicks(["AAPL", "GOOGL"]);
|
|
155
|
+
|
|
156
|
+
// Unsubscribe
|
|
157
|
+
ws.unsubscribeTicks(["AAPL"]);
|
|
158
|
+
|
|
159
|
+
// Disconnect
|
|
160
|
+
client.disconnectWebSocket();
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Error Handling
|
|
164
|
+
|
|
165
|
+
All API methods return an `ApiResponse` object with the following structure:
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
interface ApiResponse<T> {
|
|
169
|
+
success: boolean;
|
|
170
|
+
data?: T;
|
|
171
|
+
error?: string;
|
|
172
|
+
message?: string;
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Example error handling:
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
const response = await client.getShortlists();
|
|
180
|
+
|
|
181
|
+
if (response.success) {
|
|
182
|
+
console.log("Data:", response.data);
|
|
183
|
+
} else {
|
|
184
|
+
console.error("Error:", response.error);
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## TypeScript Support
|
|
189
|
+
|
|
190
|
+
This SDK is written in TypeScript and provides full type definitions:
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
import type { Shortlist, Instrument, Order, Strategy, User } from "@ganaka/sdk";
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Development
|
|
197
|
+
|
|
198
|
+
### Building
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
# Install dependencies
|
|
202
|
+
pnpm install
|
|
203
|
+
|
|
204
|
+
# Build the library
|
|
205
|
+
pnpm run build
|
|
206
|
+
|
|
207
|
+
# Watch mode
|
|
208
|
+
pnpm run dev
|
|
209
|
+
|
|
210
|
+
# Type checking
|
|
211
|
+
pnpm run lint
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Publishing
|
|
215
|
+
|
|
216
|
+
To publish a new version to npm:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
# Build before publishing
|
|
220
|
+
pnpm run build
|
|
221
|
+
|
|
222
|
+
# Login to npm (if not already logged in)
|
|
223
|
+
npm login
|
|
224
|
+
|
|
225
|
+
# Publish to npm
|
|
226
|
+
npm publish
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**Note:**
|
|
230
|
+
- You must be a member of the `ganaka` organization on npm to publish
|
|
231
|
+
- The package will be published as `@ganaka/sdk` to the public npm registry
|
|
232
|
+
- Ensure you have the correct version number in `package.json` before publishing
|
|
233
|
+
|
|
234
|
+
## License
|
|
235
|
+
|
|
236
|
+
MIT
|
|
237
|
+
|
|
238
|
+
## Contributing
|
|
239
|
+
|
|
240
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { default as default_2 } from 'zod';
|
|
2
|
+
import { growwQuotePayloadSchema } from '@ganaka/schemas';
|
|
3
|
+
import { growwQuoteSchema } from '@ganaka/schemas';
|
|
4
|
+
import { v1_dashboard_schemas } from '@ganaka/schemas';
|
|
5
|
+
import { v1_developer_groww_schemas } from '@ganaka/schemas';
|
|
6
|
+
import { v1_developer_lists_schemas } from '@ganaka/schemas';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
|
|
9
|
+
declare class ApiClient {
|
|
10
|
+
private developerToken;
|
|
11
|
+
private apiDomain;
|
|
12
|
+
constructor({ developerToken, apiDomain }: ApiClientConfig);
|
|
13
|
+
private getHeaders;
|
|
14
|
+
get<T>(path: string, params?: Record<string, any>): Promise<T>;
|
|
15
|
+
post<T>(path: string, data?: any): Promise<T>;
|
|
16
|
+
patch<T>(path: string, data?: any): Promise<T>;
|
|
17
|
+
delete<T>(path: string): Promise<T>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare interface ApiClientConfig {
|
|
21
|
+
developerToken: string;
|
|
22
|
+
apiDomain: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
declare const fetchCandles: ({ developerToken, apiDomain, runId, currentTimestamp, currentTimezone, }: {
|
|
26
|
+
developerToken: string;
|
|
27
|
+
apiDomain: string;
|
|
28
|
+
runId: string | null;
|
|
29
|
+
currentTimestamp: Date;
|
|
30
|
+
currentTimezone?: string;
|
|
31
|
+
}) => (params: default_2.infer<typeof v1_developer_groww_schemas.getGrowwHistoricalCandles.query>) => Promise<default_2.infer<typeof v1_developer_groww_schemas.getGrowwHistoricalCandles.response>["data"]>;
|
|
32
|
+
|
|
33
|
+
export declare type FetchCandlesResponse = Awaited<ReturnType<ReturnType<typeof fetchCandles>>>;
|
|
34
|
+
|
|
35
|
+
declare const fetchQuote: ({ developerToken, apiDomain, runId, currentTimestamp, currentTimezone, }: {
|
|
36
|
+
developerToken: string;
|
|
37
|
+
apiDomain: string;
|
|
38
|
+
runId: string | null;
|
|
39
|
+
currentTimestamp: Date;
|
|
40
|
+
currentTimezone?: string;
|
|
41
|
+
}) => (params: default_2.infer<typeof v1_developer_groww_schemas.getGrowwQuote.query>) => Promise<default_2.infer<typeof v1_developer_groww_schemas.getGrowwQuote.response>["data"] | null>;
|
|
42
|
+
|
|
43
|
+
export declare type FetchQuoteResponse = Awaited<ReturnType<ReturnType<typeof fetchQuote>>>;
|
|
44
|
+
|
|
45
|
+
declare const fetchQuoteTimeline: ({ developerToken, apiDomain, runId, currentTimestamp, currentTimezone, }: {
|
|
46
|
+
developerToken: string;
|
|
47
|
+
apiDomain: string;
|
|
48
|
+
runId: string | null;
|
|
49
|
+
currentTimestamp: Date;
|
|
50
|
+
currentTimezone?: string;
|
|
51
|
+
}) => (symbol: string, date: Date) => Promise<default_2.infer<typeof v1_developer_groww_schemas.getGrowwQuoteTimeline.response>["data"]["quoteTimeline"]>;
|
|
52
|
+
|
|
53
|
+
export declare type FetchQuoteTimelineResponse = Awaited<ReturnType<ReturnType<typeof fetchQuoteTimeline>>>;
|
|
54
|
+
|
|
55
|
+
declare const fetchShortlist: ({ developerToken, apiDomain, runId, currentTimestamp, currentTimezone, }: {
|
|
56
|
+
developerToken: string;
|
|
57
|
+
apiDomain: string;
|
|
58
|
+
runId: string | null;
|
|
59
|
+
currentTimestamp: Date;
|
|
60
|
+
currentTimezone?: string;
|
|
61
|
+
}) => (queryParams: default_2.infer<typeof v1_developer_lists_schemas.getLists.query>) => Promise<default_2.infer<typeof v1_developer_lists_schemas.getLists.response>["data"] | null>;
|
|
62
|
+
|
|
63
|
+
export declare type FetchShortlistResponse = Awaited<ReturnType<ReturnType<typeof fetchShortlist>>>;
|
|
64
|
+
|
|
65
|
+
export declare function ganaka<T>({ fn, startTime, endTime, intervalMinutes, deleteRunAfterCompletion, }: {
|
|
66
|
+
fn: (context: RunContext) => Promise<T>;
|
|
67
|
+
startTime: Date;
|
|
68
|
+
endTime: Date;
|
|
69
|
+
intervalMinutes: number;
|
|
70
|
+
/**
|
|
71
|
+
* Delete run after completion.
|
|
72
|
+
* Used to test the function without keeping the run and related data in the database
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
deleteRunAfterCompletion?: boolean;
|
|
76
|
+
}): Promise<void>;
|
|
77
|
+
|
|
78
|
+
export { growwQuotePayloadSchema }
|
|
79
|
+
|
|
80
|
+
export { growwQuoteSchema }
|
|
81
|
+
|
|
82
|
+
declare const placeOrder: ({ runId, apiClient }: {
|
|
83
|
+
runId: string | null;
|
|
84
|
+
apiClient: ApiClient;
|
|
85
|
+
}) => (data: z.infer<typeof v1_dashboard_schemas.v1_dashboard_runs_schemas.createOrder.body>) => Promise<void>;
|
|
86
|
+
|
|
87
|
+
export declare interface RunContext {
|
|
88
|
+
placeOrder: ReturnType<typeof placeOrder>;
|
|
89
|
+
fetchCandles: ReturnType<typeof fetchCandles>;
|
|
90
|
+
fetchQuote: ReturnType<typeof fetchQuote>;
|
|
91
|
+
fetchQuoteTimeline: ReturnType<typeof fetchQuoteTimeline>;
|
|
92
|
+
fetchShortlist: ReturnType<typeof fetchShortlist>;
|
|
93
|
+
currentTimestamp: Date;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export { }
|