Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
Add documentation link
  • Loading branch information
BennyThadikaran authored Apr 29, 2024
1 parent 811a58c commit 318afb3
Showing 1 changed file with 7 additions and 117 deletions.
124 changes: 7 additions & 117 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ This Library is currently in Alpha. Expect breaking changes. Once testing is com

If you ❤️ my work so far, please 🌟 this repo.

## Documentation

https://bennythadikaran.github.io/Aio-Trader

API reference will be added in a day or two.

## Installation

**1. Clone the repo**
Expand Down Expand Up @@ -61,123 +67,7 @@ else:

This setup works well with `aio_dns` no need to set an event loop policy on Windows.

## Kite API usage

**Kite Web login (via interactive user input)** - Requires user_id, password and twofa.
To avoid interactive inputs, pass full or partial info to `kite.authorize`. Any missing information will require user input.

```python
# Kite Web Login Example 1
from aio_trader.kite import Kite
import asyncio


async def main():
async with Kite() as kite:
# Starts an interactive prompt for Kite Web login
await kite.authorize()

# Kite Web tokens are stored in cookies and reused on subsequent runs
print(kite.enctoken)


asyncio.run(main())
```

When using a library like [pyotp](https://github.com/pyauth/pyotp), pass the function, to `kite.authorize` as below.

```python
import pyotp

totp = pyotp.TOTP('base32secret3232')
# totp.now() to get OTP

async with Kite() as kite:
await kite.authorize(
user_id=config["user_id"],
password=config["password"],
twofa=totp.now,
)
```

**KiteConnect Login** - Requires api_key, request_token and api_secret.

```python
async with Kite(api_key=config['api_key']) as kite:
await kite.authorize(
request_token=config['request_token'],
secret=config['secret']
)

# Can be stored and reused on subsequent runs
print(kite.access_token)
```

## Kite Websocket usage

```python
from aio_trader.kite import KiteFeed
from aio_trader import utils
from typing import List
import asyncio


# Define handlers
def on_tick(tick: List, binary=False):
print(tick)


def on_connect(kws: KiteFeed):
print("connected")

# Subscribe to Aarti Industries
asyncio.create_task(kws.subscribe_symbols([1793]))


async def cleanup(kws):
# perform cleanup operations here
await kws.close()


async def main():
enctoken = "STORED_ENCTOKEN"
user_id = "KITE_WEB_USER_ID"

async with KiteFeed(
user_id=user_id,
enctoken=enctoken,
) as kws:
kws.on_tick = on_tick
kws.on_connect = on_connect

# Handle KeyboardInterupt
utils.add_signal_handlers(cleanup, kws)

# No code executes after this line
await kws.connect()


asyncio.run(main())
```

Another example without `asyncio.run`

```python
kws = KiteFeed(
user_id=user_id,
enctoken=enctoken,
)

kws.on_tick = on_tick
kws.on_connect = on_connect

# Handle KeyboardInterupt
utils.add_signal_handlers(cleanup, kws)

kws.run_forever() # No code will run after this line
```

## Differences between Aio-Trader and pykiteconnect(KiteConnect Official library)
## Differences between Aio-Trader and pykiteconnect (KiteConnect Official library)

| aio-trader | pykiteconnect |
|---|---|
Expand Down

0 comments on commit 318afb3

Please sign in to comment.