Comments (19)
For Websocket the new features are:
-
Auto-Reconnect: Enjoy uninterrupted connectivity by enabling automatic reconnection in case of disconnection. Simply set the reconnect parameter to true during WebSocket initialization, ensuring your application can recover without manual intervention.
If this can be implemented then websocket will be more robust. -
One very important issue which I have in extra-fyers is if websocket gets disconnected due to any reason, I don't get to know. Similar to fyers on_close/on_error can you give a Callback function to be executed on these events. I trade at levelโs so when market reaches a level I want to know, if the socket is down, my code does not get to know and action cannot be taken.
-
We only had order and marketData in websocket, now it supports:
OnOrders(same as order), OnPositions, OnTrades, OnGeneral(same as marketData)
Here the position and trades are of particular interest, as they can give me the data of my realised profit and trade when it happens.
Trade: https://myapi.fyers.in/docsv3#tag/Web-Socket/paths/~1GeneralSocket/get
Position: https://myapi.fyers.in/docsv3#tag/Web-Socket/paths/~1GeneralSocket/put -
Lite Mode, it only gives symbol and LTP, quite helpful as processing of the data will be faster.
https://myapi.fyers.in/docsv3#tag/Web-Socket/paths/~1WebSocket/patch
Other changes in API's:
- Pending Order Cancel : This is an added functionality for exit position API. If a user has open positions in particular stocks and also working opposite order of the particular stock, the user can close the working orders and then exit the open positions.
https://myapi.fyers.in/docsv3#tag/Other-Transactions/paths/~1OtherTrans/get
This was already there in V2, I could not find any way to do this in extra-fyers
Thanks for your lovely contribution.
from extra-fyers.
I guess you are aware that HDFC has merged with HDFC Bank. Use NSE:HDFCBANK-EQ
from extra-fyers.
Please check if this works for you. A bit of recursion may be needed.
// FYERS stateful API.
var api = null;
// Market data connection.
var conn = null;
// On Market data notification.
function onNotification(notification) {
console.log(notification);
// Your code here.
}
// On Market data connection close.
async function setupConnection() {
try {
conn = await api.connectMarketData(onNotification);
conn.on('close', setupConnection);
await api.subscribeMarketDepth(['NSE:SBIN-EQ']);
}
catch (err) {
console.log(err);
setTimeout(setupConnection, 1000);
}
}
function main() {
var appId = fs.readFileTextSync('appId.log');
var accessToken = fs.readFileTextSync('accessToken.log');
api = new fyers.Api(appId, accessToken);
setupConnection();
}
main();
from extra-fyers.
Thanks, Its working fine, Tested today
from extra-fyers.
Hello Shyam
Thanks for the suggestion. Could you help me with the following?
- Could you prepare a list of the features introduced (with links/references)?
- List how the absence of such features affects trading applications?
- What applications would benefit from them?
Thanks in advance.
from extra-fyers.
Shyam, i will first address your primary concern of disconnect event handling in V2 itself with a callback - before moving on to V3. Do give me some time to remind myself of this codebase.
from extra-fyers.
Thanks,
Also following changes are required as fyers have changed the numeric value(10,11,12,20) to string('10','11','12','20').
const TO_SEGMENT = new Map([
['10', "CM"],
['11', "FO"],
['12', "CD"],
['20', "COM"],
]);
from extra-fyers.
Shyam, i looked into the docs, both V2 and V3, and it appears "segment" is still a number in HTTP API. I will try it out.
from extra-fyers.
I am use extra-fyers since Jan 23, it was all fine but one day I could not see the segment, I tried debuging the code and realised fyers folks have changed number to string so I change the extra-fyers code at my side also, now its all working fine. You can check this while testing, I guess document is not changed.
from extra-fyers.
Looks like butter is getting spread too thin at fyers as well :). Lets wait for the market to open tomorrow.
from extra-fyers.
It seems FYERS API is still returning segment as numbers, not string.
Coming to the disconnect issue, i tried turning off my LAN connection but when it turn it back on again, the websocket appears to be resuming again. I guess there may be some timeout event. Note that i return the websocket connection already, so you can listen on events.
var conn = await api.connectMarketData(quote => {
console.log(quote);
});
conn.on('close', () => {
console.log('Connection closed');
});
You could also try reconnecting if no data is recieved for a certain period of time, by calling api.connectMarketData(...)
again.
from extra-fyers.
I am going through FYERS V3 API. When i try the margin calculator, i get the following response.
{
"s": "error",
"code": -50,
"message": "Please provide valid symbols"
}
I am passing the following request to https://api.fyers.in/api/v2/span_margin
.
{
"data": [
{
"symbol": "NSE:HDFC-EQ",
"qty": 50,
"side": 1,
"type": 2,
"productType": "CNC"
}
]
}
Any suggestions?
EDIT
Got it.
from extra-fyers.
How do I listen to the close events.
I am using
var api = new fyers.Api(appId, accessToken);
try{
await api.connectMarketData(quote => {
my code....
});
await api.subscribeMarketQuote(symbols)
} catch (e){
my code....
}
from extra-fyers.
Thanks I will try this.
I missed that I get the connection object from connectMarketData
Thanks
from extra-fyers.
I asked FYERS support by mail and Ajay said they have discontinued support for WebSocket data structures. If you get info on the websoket, you could reopen this issue.
from extra-fyers.
I checked fyers V3 python code(https://pypi.org/project/fyers-apiv3/#files) to understand what are the change in websocket now.
Look like in ORDER_UPDATE_URL (wss://socket.fyers.in/trade/v3) we can get all kind of data(orders, trades,positions and general) in json format. I am attaching the order_ws file for quick reference.
Incase you are not able to do the changed, I can do it and help. please share the IDE you are using and any more details to help me start do the changes.
from extra-fyers.
Hello @shyamg2000
I am listing the old websocket URLs below.
/** Root URL for Market data notifications. */
export const MARKET_DATA_URL: string = "wss://api.fyers.in/socket/v2/dataSock";
/** Root URL for Order update notifications. */
export const ORDER_UPDATE_URL: string = "wss://api.fyers.in/socket/v2/orderSock";
/** Base query string for Market data notifications. */
const MARKET_DATA_QUERY:string = "user-agent=fyers-api&type=symbolUpdate";
/** Base query string for Order update notifications. */
const ORDER_UPDATE_QUERY:string = "user-agent=fyers-api&type=orderUpdate";
From the python code, it can observe the following (as you mentioned):
self.__url = "wss://socket.fyers.in/trade/v3"
file_path = resource_filename('fyers_apiv3.FyersWebsocket', 'map.json')
# ...
self.socket_type = {
"OnOrders": "orders",
"OnTrades": "trades",
"OnPositions": "positions",
"OnGeneral": ["edis", "pricealerts", "login"],
}
# ...
message = json.dumps(
{"T": "SUB_ORD", "SLIST": self.data_type, "SUB_T": 1}
)
# ...
message = json.dumps(
{"T": "SUB_ORD", "SLIST": self.data_type, "SUB_T": -1}
)
Can you decode the new URLs, query strings, request, and response JSONs and list them here? I expect the market data (general) is in binary format (JSON would be a bandwidth killer). BTW is have a few changes ready for V3 REST API, but it looks like little has changed over there.
from extra-fyers.
I was going through all the other code in python and realised you are right the data is in binary format.
I am travelling for a month, when I am back I will try to decode that format. Looking at the python code its possible.
The new URLs are
"wss://socket.fyers.in/trade/v3"
"https://api-t1.fyers.in/data/quotes"
"wss://socket.fyers.in/hsm/v1-5/prod"
from extra-fyers.
@shyamg2000 I have invited you as a collaborator on a relevant repo.
from extra-fyers.
Related Issues (4)
- symbol is coming null HOT 1
- please describe login flow HOT 2
- For F&O data is null HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from extra-fyers.