Example below. You can explore more the kite.margins
kite = KiteConnect(api_key = api_key)
kite.set_access_token(access_token)
kite.margins("equity")["available"]["opening_balance"]
I went and before I can think of anything, my first reaction is - "Man what is this inside on_ticks ? "
Sorry, I got stuck looking at this piece of code itself. This snippet is a death nail to on_ticks
def on_ticks(ws, ticks):
#ticks=[dict[ …
@akhil811 because you pasted code and python is an indentation based language, it is not clear whether you have made indentation mistake or not. Please ensure there is no indentation mistake
if you think there is none, then please share exact inden…
@rsamikan actually you have to simulate it and say spread loss. Imagine when you scale this strategy, you would have massive spread loss. I would rather bucket orders and nullify the conjugate orders like these but internally assume them executed at…
@mlearner
create map for your comfort using the instruments files, which you can download at 8:45am
Like below
df = pd.read_csv("all_instruments", low_memory = False)
my_instrument_type = dict( zip( df.instrument_token, df.instrument_type ) )
my…
If you are having only one symbol then use
data = df['last_price'].resample("5T").ohlc()
If you have more than one symbol then you have to first group by symbols and then apply above
@nikaashpuri
This is error is thrown by the Proxy, mostly likely when the actual service behind it is down or latency is very high. Means Zerodha's API micro service behind the Proxy is down
@Akash_Lodha
Upside you are buying CE whereas downside you are selling CE. Fundamentally it should be
1. Buy ATM CE if Nifty Index crosses above RSI 60
2. Buy ATM PE if Nifty Index crosses below RSI 40
Just a thought for you and the one who is c…
@ravik93
I have MacBook with BigSur and have no issues with what you mentioned
Python 3.8.8 | packaged by conda-forge | (default, Feb 20 2021, 16:12:38)
[Clang 11.0.1 ] on darwin
Type "help", "copyright", "credits" or "license" for more informatio…
@kavanlimbasiya
Run 3 ticker programs, each fetching 900 and pushing it into a queue of a message
Then on the other side use a python program to consumer the queue data
@jijoycanto
Sorry am little late but unless you want to do extremely fast HFT, you don't have to get bothered with so much of latency comparison.
And the day you have to, you won't need Zerodha, you probably would go for direct to NSE connection …
I don't think there is any API route to fetch old orders. But you rather log your orders using
on_order_update
in a file that you can open using pandas or any other analytics tool. Use data filters to check your orders
I think the problem is that you are initialising the sl_factor every time and thus it is getting reset
Are you running this below code inside a quantity / PnL polling loop ? If yes then that is the cause. It should be outside
sl_factor=-1
in your
on_ticks
Whenever you receive a tick write into Redis with a key connection_alive with value 1 and TTL 1 second or whatever x seconds interval you want
SET connection_alive 1 x
At anytime, If you check this key in Redis and you find tha…
@ravimeetra
Simple answer - choose any of the two below
1. Postback
2. Call back to on_order_update
If you don't know these find someone to code this for you.
@ravimeetra I am assuming you are using Kite Tickers for fetching tick data to do programmatic trading and if that be the case then there is
on_order_update
this function receives a order related call back and you can use this
For Web Hook you have to create your application that would bind to a static iP on some Port
then your web hook link would be
http://your_static_ip:port/route
or https whatever you have set in place
@Bromine Pandas OHLC sampling is for offline work not for real time. For real time OHLC over any time frame that you desire, you have to write your own code that does sampling over that time period and saves it into the database
@devarajh Something is wrong with your code. If you are bucketing correctly the OHLC will match with the chart. I have never faced an issue even with 1 minute OHLC without even using sampling
def function_to_read_queue():
# this function is run through a thread
# Read queue within endless while loop
# Do all the mess here
def on_ticks(ws, ticks):
# Push ticks in a Queue the ticks and that is it.
# Nothing else unl…
@rhnvrm
I don't get what you mean by below
If last_price is 600. When trigger_value > 650 it should place order.
If last_price is 700. When trigger_value < 650 it should place order.
@sujith thanks for reply. What am trying to understand is for GTT
Limit Price, Transaction Type, SL and TP does the entire work. Something like bracket order
What is the use of last_price ?
@themohammedfaisal thanks
In below I understand trigger values and in orders the price
What is the purpose of last_price if I give my Limit order price
Place GTT order
trigger_type The type of GTT order(single/two-leg).
tradingsymbol Trading sy…
@sujith Just a continuation to this question. If I place a 2000 shares bracket order of ACC, does it count as 1 trade or you count multiple legs as trades ?
1. Read Record and Push it to a Message Broker - preferably RabbitMQ
2. Use Logstash to read from Message Broker and send to SQLite
Only #1 is small bit of programming, #2 is not
@ZW2914
1. It is "quiet" not "quite"
2. You are assuming what you are doing is the right, just because you are using threads
3. Forum gives snippet support not detailed solution
4. Expectation of detailed solution should come from paid developers…
You need to install the package else when cron would run your code, you code would just fail
Prefer using virtualenv or conda, instead of directly pip installing
In cron cd into the folder of your program && source activate the environmen…
@ZW2914
1. Yes, possible to get OHLC of 1000+ securities in a fraction of second, let alone 100+
2. I have a smart solution and I have implemented in past. You should also think and work your way towards that kind of solution instead of expecting …
You need to flatten the nested data using pandas and then create the data frame out of it
import datetime
from pandas.io.json import json_normalize
ticks = [{'tradable': True, 'mode': 'full', 'instrument_token': 415745, 'last_price': 117.45,'last…
Am writing high level algorithm
from Queue import Queue
# Initialize Global Queue to be used by functions
# Initialize Global DataFrame to be used by functions
def func1_dataframe_update():
# Read queue using While True
# Append Dataframe with…
@alokeranjan What is the difference ? Or are you wanting key with value as list
then you should do in the last line as
my_json = {'list' : my_list}
print(my_json)
@ZW2914 why can't you read OHLC data by end of 9:19:59 ? Why is it that you cannot do a thing as simple as that and want to know an alternative, which might be more complex
@sujith am not concerned about what these stock tips people say. What was alarming was that they knew the number and corresponding name, to say that they are aware of daily trading done. Means something for sure is leaking out of Zerodha
This mobil…
@Somendra86
Cannot understand what do you mean by live market ?
You want a code that captures ticks and also calculates RSI on that tick basis ? If so, then I don't know where can such custom requirement be available over the internet
Question is detailed. If you curl and download the instrument file as csv, it can be read by excel. So what is the issue ?
If you are wanting Excel Visual Basic code to read instrument files and populate cell then search for VB Code to read URL to…
@mohitsx11
There is no hard and fast criteria, Rs 1000+ crore market capital companies are large cap, below that are mid-cap. You can consider below Rs 100+ crore market capitalization as small cap
@adjas
requests and pandas will do the magic
import requests
from io import StringIO
import pandas as pd
URL_FO_MARKET_LOTS = 'https://www.nseindia.com/content/fo/fo_mktlots.csv'
data = requests.get(URL_FO_MARKET_LOTS).content
df = pd.read_cs…
@mohitsx11
From NSE Website also. Around 1600 companies. Don't know if what you are looking for is in it or not
https://www.nseindia.com/corporates/compliance/MarketCap_31012019.xlsx
As per regulation it is not allowed to allow fully automatic trading. And that is why Zerodha cannot provide API for request token. Not that Zerodha cannot provide but it is bound by regulation
@sivadorai Access tokens are expired everyday in the morning.
Safe time to generate access token is everyday at 8:40am and you can keep using it whole day
@Amt,
1. Yes, pd.read_html is pretty simple, personally I would avoid BeautifulSoup unless absolutely necessary
2. I detailed BeautifulSoup approach in context to your first code
Also, blocking my NSE is not basis headers value
I don't use Beaut…
@adjas I think you have complicated the code for no reasons. It looks like a deliberate attempt to fit Object Oriented programming, mixed up with threads. Result is a disaster, forget about the algo, the elementary aspect is not fulfilling
Just sim…
@adjas
roguedelta.RogueDelta(portfolio, orderbook, x)
Does this function return KiteTicker Object ?
Because you are appending the return object to rogue_delta_runners array, on whose elements later you are loop and executing its member elements i…
@adjas Can you just remove your strategies and show your skeleton code ? Interesting to see where you coded incorrectly. It for sure is a bug in your code and not Kite Web Socket
And as I said push ticks in Queue in the on_ticks.
You can have two…
@adjas on reconnect kite automatically connects. As I pointed out before, please pass your thread new websocket handle.
In Linux / Unix, everything this is a file and thus what you get to read / write to it is a handle. You can print pointer / loca…
@Guhan
Use python's Queue. Use global one access from anywhere in program
Firstly, in on_ticks limit yourself to receiving ticks. Python has internal Queue object, use it to pass ticks to it here. Don't overload on_ticks with any other thing. It …
@adjas
Are you changing the state of global variable ws_connected once after it is True in on_connect ?
From where is the log "RogueDelta" printing ?
On reconnection are you sure your Thread is getting the connection handle of the new websocket…
Ok I looked at the code and what he is trying to do is
1. From points, he derived smooth curve
2. Calculated delta for slope = dy/dx and as time between two candles is constant, dx = 1
3. ltp_d is dy/dx wth dx = 1, so dy (ltp_d, means ltp delta) is…
@infotrade how far depends on your RSI Period. If you have RSI period of N, then a 2-3 times of N would be good enough to reduce variance drastically. And if you want to further reduce variance to virtually zero you can increase the size by another …
@infotrade depends on the RSI period. If your data size is N and your RSI period is 10% of N then even if superset size is 1 billion ticks, it doesn't matter. After few panning window of RSI of [N/10] period, error would reduce exponentially and the…
@amandeep179018
Let us say you have the close prices of 5-minute candle in an array variable candle_close[ ]
then last 52 candle close in pure python is
sum(candle_close[-52 : ] ) / 52
That being said, If you don't know how to do this, then you s…
@ayush I don't know what Zerodha is using but VWAP - Volume Weight Average Price means
It is the (Sum Product of Price and Volume) / Sum of Volume, which basically means you are getting price weighted basis volume traded on that price
At least tha…
Honestly, 10% fall is a big fall. I wouldn't average at 10% fall and instead see what happened. I mean why would you want to further buy in a falling meteor ? Haven't you read what happened to people in Yes Bank ?
After 10% fall any which way you h…
@ashishjindal89
Zerodha Kite Chart it seems uses Exponential Weight Moving Average not Simple Moving Average.
And I can see you are using SMA for Average Gain/Loss
Additionally, even in SMA, you are ending up averaging last N-1 elements, while I …