Skip to content

Commit

Permalink
Add enums, New docs (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
anurag-roy authored Apr 15, 2023
1 parent 327f526 commit 5e7c7e9
Show file tree
Hide file tree
Showing 74 changed files with 8,781 additions and 160 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-bags-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'kiteconnect-ts': minor
---

Add enums for KiteConnect and KiteTicker. See [note on enum usage](https://github.com/anurag-roy/kiteconnect-ts#using-provided-enums) for more details.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
*.log
.DS_Store
node_modules
dist
docs
dist
10 changes: 7 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ pnpm install
```

3. Make your change and commit it to your forked repo.
4. Make changes to the docs if necessary. Docs are generated from TsDoc comments and can be previewed by
4. Make changes to the docs if necessary.

Docs are generated from TsDoc comments and kept in a separate `docs` folder, which is a Next.js/Nextra project. To view the docs in development mode:

```
pnpm docs:generate && pnpm docs:preview
pnpm generateDocs
cd docs
pnpm dev
```

5. Create a new changeset documenting your changes and commit the file.
Expand All @@ -41,4 +45,4 @@ Please try to keep PRs limited to a single area of change and try not to club mu

---

:sparkles: Thanks for your contribution! It is highly appreciated.
Thanks for your contribution! It is highly appreciated.
68 changes: 56 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Kite Connect <img src="https://static.npmjs.com/255a118f56f5346b97e56325a1217a16.svg" width="20" height="20" />
# kiteconnect-ts

Unofficial library for the Kite Connect trading APIs, written in [TypeScript](https://www.typescriptlang.org/).

Expand All @@ -8,19 +8,16 @@ If you notice a bug, please [open an issue](https://github.com/anurag-roy/kiteco

## Documentation

Docs are auto-generated from TsDoc comments using [TypeDoc](https://typedoc.org/).
Docs are auto-generated from TsDoc comments using [TypeDoc](https://typedoc.org/), [typedoc-plugin-markdown](https://github.com/tgreyuk/typedoc-plugin-markdown) and [Nextra](https://nextra.site/).

Browse the full docs [here](https://kiteconnect.anuragroy.dev) or go to a specific part:

### KiteConnect
### kiteconnect-ts

- [Class, properties and methods](https://kiteconnect.anuragroy.dev/classes/KiteConnect.KiteConnect.html)
- [Extra types and interfaces](https://kiteconnect.anuragroy.dev/modules/KiteConnect.html)

### KiteTicker

- [Class, properties and methods](https://kiteconnect.anuragroy.dev/classes/KiteTicker.KiteTicker.html)
- [Extra types and interfaces](https://kiteconnect.anuragroy.dev/modules/KiteTicker.html)
- [KiteConnect Class, properties and methods](https://kiteconnect.anuragroy.dev/classes/KiteConnect)
- [KiteTicker Class, properties and methods](https://kiteconnect.anuragroy.dev/classes/KiteTicker)
- [Enums](https://kiteconnect.anuragroy.dev/modules#enumerations)
- [Interfaces](https://kiteconnect.anuragroy.dev/modules#interfaces)

### Other

Expand Down Expand Up @@ -105,6 +102,55 @@ ticker.on('connect', () => {
ticker.connect();
```

## Using provided enums

This library does not export Typescript enums, but rather JavaScript const objects. This was a design decision taken consciously to allow using the value from the object as well as a string literal, which has a better dx in my opinion. Constants are also present in the classes as readonly members, mainly for backwards compatibility with kiteconnectjs. So in total there are 3 ways you can these, pick one that works for you!

### Option 1: As a string

All params which accept specific values provide type validation and autocomplete. So a simple string literal works as follows:

```typescript
import { KiteConnect } from 'kiteconnect-ts';
import env from './env.json';

const kc = new KiteConnect({
api_key: env.API_KEY,
});

const instruments = await kc.getInstruments(['NSE']);
```

### Option 2: As an enum

You could also import the enum and use as follows:

```typescript
import { Exchange, KiteConnect } from 'kiteconnect-ts';
import env from './env.json';

const kc = new KiteConnect({
api_key: env.API_KEY,
});

const instruments = await kc.getInstruments([Exchange.NSE]);
```

### Option 3: As a class member

This is mainly for backwards compatibility if you are migrating `kiteconnectjs` code to `kiteconnect-ts`.

```typescript
import { KiteConnect } from 'kiteconnect-ts';
import env from './env.json';

const kc = new KiteConnect({
api_key: env.API_KEY,
});

const instruments = await kc.getInstruments([kc.EXCHANGE_NSE]);
```

## Browser Support

Unfortunately this library does not work on the browser, so you cannot use it on your Angular, React, Vue, etc front-ends. However, if you use a meta/full-stack framework (Next.js, Nuxt, etc) with SSR, you can definitely install and use it on the server side.
Expand Down Expand Up @@ -164,8 +210,6 @@ ws.onmessage = async (message) => {
console.log(ticks);
}
};

export {};
```

## Todos
Expand Down
2 changes: 2 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.next
out
13 changes: 13 additions & 0 deletions docs/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const withNextra = require('nextra')({
theme: 'nextra-theme-docs',
themeConfig: './theme.config.jsx',
});

module.exports = withNextra({
images: {
unoptimized: true,
},
});

// If you have other Next.js configurations, you can pass them as the parameter:
// module.exports = withNextra({ /* other next.js config */ })
21 changes: 21 additions & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "docs",
"version": "1.0.0",
"description": "Docs for kiteconnect-ts using Nextra",
"main": "index.js",
"scripts": {
"dev": "next",
"build": "next build && next export",
"start": "next start"
},
"keywords": [],
"author": "Anurag Roy <[email protected]> (https://anuragroy.dev/)",
"license": "MIT",
"dependencies": {
"next": "^13.2.4",
"nextra": "^2.3.0",
"nextra-theme-docs": "^2.3.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}
1 change: 1 addition & 0 deletions docs/pages/.nojekyll
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.
52 changes: 52 additions & 0 deletions docs/pages/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# kiteconnect-ts

## 0.4.5

### Patch Changes

- a018479: Fix return types for margin APIs when `compact` flag is true

## 0.4.4

### Patch Changes

- 0a89c53: Add notes on browser support

## 0.4.3

### Patch Changes

- 60d0dbb: fix: Configure axios params serializer
- 0ed0c9f: fix: Add `change` to TickerQuote and TickerFull types

fix: Make `modeFull`, `modeQuote` and `modeLTP` in KiteTicker non-static for better compatibility with kiteconnectjs

## 0.4.2

### Patch Changes

- 2a30929: fix: Allow axios to transform responses by default

## 0.4.1

### Patch Changes

- 21fce0a: fix: Make parameter optional in `getInstruments`

## 0.4.0

### Minor Changes

- b56ae78: Add KiteConnect module

## 0.3.1

### Patch Changes

- ff21cf7: Add types for tick packets

## 0.3.0

### Minor Changes

- 2e51217: Overall package rewrite to match existing `kiteconnect` APIs for easy migrations and compatibility with existing code.
80 changes: 80 additions & 0 deletions docs/pages/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our community include:

- Demonstrating empathy and kindness toward other people
- Being respectful of differing opinions, viewpoints, and experiences
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
- Focusing on what is best not just for us as individuals, but for the overall community

Examples of unacceptable behavior include:

- The use of sexualized language or imagery, and sexual attention or advances of any kind
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or email address, without their explicit permission
- Contacting individual members, contributors, or leaders privately, outside designated community mechanisms, without their explicit permission
- Other conduct which could reasonably be considered inappropriate in a professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.

Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [email protected]. All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series of actions.

**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within the community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at <https://www.contributor-covenant.org/version/2/0/code_of_conduct.html>.

Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see the FAQ at <https://www.contributor-covenant.org/faq>. Translations are available at <https://www.contributor-covenant.org/translations>.
48 changes: 48 additions & 0 deletions docs/pages/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Contribution Guide

Please make sure you have gone through the [Code of Conduct](./CODE_OF_CONDUCT.md) and maintain a friendly environment.

## Have a question?

Have a question on how to use the library or a suggestion to improve anything, [create a discussion](https://github.com/anurag-roy/kiteconnect-ts/discussions/new/choose).

## Found a bug?

Something not working as expected like types not matching the actual response or something wrong with docs, feel free to [open an issue](https://github.com/anurag-roy/kiteconnect-ts/issues/new) detailing your problem.

## How to contribute

`pnpm` is used as the package manager of choice. Installation instructions can be found [here](https://pnpm.io/installation).

1. Fork the repository and clone it locally on your machine.
2. Install dependencies.

```
pnpm install
```

3. Make your change and commit it to your forked repo.
4. Make changes to the docs if necessary.

Docs are generated from TsDoc comments and kept in a separate `docs` folder, which is a Next.js/Nextra project. To view the docs in development mode:

```
pnpm generateDocs
cd docs
pnpm dev
```

5. Create a new changeset documenting your changes and commit the file.

```
pnpm changeset
```

6. Push your changes and you're ready to raise a PR!
7. Tag [me](https://github.com/anurag-roy) as a reviewer and I'll get your PR reviewed and merged.

Please try to keep PRs limited to a single area of change and try not to club multiple changes in a single PR.

---

✨ Thanks for your contribution! It is highly appreciated.
5 changes: 5 additions & 0 deletions docs/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import '../styles.css';

export default function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />;
}
11 changes: 11 additions & 0 deletions docs/pages/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"index": "Introduction",
"quickStart": "Quick Start",
"modules": "Modules",
"classes": "Classes",
"enums": "Enums",
"interfaces": "Interfaces",
"CHANGELOG": "Changelog",
"CONTRIBUTING": "Contributing",
"CODE_OF_CONDUCT": "Code of Conduct"
}
Loading

1 comment on commit 5e7c7e9

@vercel
Copy link

@vercel vercel bot commented on 5e7c7e9 Apr 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.