-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
47 lines (42 loc) · 1.17 KB
/
server.ts
File metadata and controls
47 lines (42 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { KiteConnect } from "kiteconnect";
import dotenv from "dotenv"
dotenv.config();
const apiKey = process.env.API_KEY;
const apiSecret = process.env.API_SECRET;
const requestToken = process.env.REQUEST_TOKEN; // this is token of zerodha's profile, it gives power to place orders inbehalf of others
const kc = new KiteConnect({ api_key: apiKey });
console.log(kc.getLoginURL());
async function init() {
try {
await generateSession();
await getProfile();
} catch (err) {
console.error(err);
}
}
async function generateSession() {
try {
const response = await kc.generateSession(requestToken, apiSecret);
kc.setAccessToken(response.access_token);
console.log("Session generated:", response);
} catch (err) {
console.error("Error generating session:", err);
}
}
async function getProfile() {
try {
const profile = await kc.placeOrder("amo", {
exchange: "NSE",
tradingsymbol: "IDEA",
transaction_type: "SELL",
quantity: 1,
product: "CNC",
order_type: "MARKET",
});
console.log("Profile:", profile);
} catch (err) {
console.error("Error getting profile:", err);
}
}
// Initialize the API calls
init();