fyers-api-v3 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,170 @@
1
+ # The Fyers API Javascript client - v3
2
+
3
+ The official Javascript node client for communicating with the [Fyers API](https://myapi.fyers.in)
4
+
5
+ ## Documentation
6
+
7
+ - [Javascript client documentation](https://myapi.fyers.in/docs)
8
+
9
+ ## Requirements
10
+
11
+ - NodeJS v12.0.0+
12
+
13
+ ## Installation
14
+
15
+ Install via [npm](...)
16
+
17
+ npm install fyers-api-v3@latest
18
+
19
+ ## Breaking changes - v3
20
+
21
+ `v3` is a **breaking** major release with multiple internal modification to improve user experience.<br>
22
+
23
+ Below are the breaking changes:
24
+
25
+ - Websocket output format have changed completely.
26
+
27
+ ## Getting started with API
28
+
29
+ ```javascript
30
+ var fyersModel= require("fyers-api-v3").fyersModel
31
+
32
+ var fyers= new fyersModel({"path":"path where you want to save logs"})
33
+
34
+ fyers.setAppId("xxxxx-xxx")
35
+
36
+ fyers.setRedirectUrl("Redirect URL here")
37
+
38
+ var URL=fyers.generateAuthCode()
39
+
40
+ //use url to generate auth code
41
+ console.log(URL)
42
+
43
+ var authcode="authcode generated above"
44
+
45
+ fyers.generate_access_token({"client_id":"APPID","secret_key":"secret","auth_code":authcode}).then((response)=>{
46
+ if(response.s=='ok'){
47
+ fyers.setAccessToken(response.access_token)
48
+ }else{
49
+ console.log("error generating access token",response)
50
+ }
51
+ })
52
+
53
+ fyers.get_profile().then((response)=>{
54
+ console.log(response)
55
+ }).catch((err)=>{
56
+ console.log(err)
57
+ })
58
+
59
+ fyers.getQuotes(["NSE:SBIN-EQ","NSE:TCS-EQ"]).then((response)=>{
60
+ console.log(response)
61
+ }).catch((err)=>{
62
+ console.log(err)
63
+ })
64
+
65
+ fyers.getMarketDepth({"symbol":["NSE:SBIN-EQ","NSE:TCS-EQ"],"ohlcv_flag":1}).then((response)=>{
66
+ console.log(response)
67
+ }).catch((err)=>{
68
+ console.log(err)
69
+ })
70
+ ```
71
+
72
+ ## API promises
73
+
74
+ All API calls returns a promise which you can use to call methods like `.then(...)` and `.catch(...)`.
75
+
76
+ ```javascript
77
+ FyersApiCall
78
+ .then(function (v) {
79
+ // On success
80
+ })
81
+ .catch(function (e) {
82
+ // On rejected
83
+ });
84
+ ```
85
+
86
+ ## Getting started order WebSocket
87
+
88
+ ```javascript
89
+ var fyersOrderSocket= require("fyers-api-v3").fyersOrderSocket
90
+
91
+ var skt=new fyersOrderSocket("Acesstoken in format APPID:Accesstoken",
92
+ "path to where you want to save logs")
93
+
94
+ skt.on("error",function (errmsg) {
95
+ console.log(errmsg)
96
+ })
97
+
98
+ skt.on('others',function (msg) {
99
+ console.log(msg)
100
+ })
101
+
102
+ skt.on('connect',function () {
103
+ skt.subscribe([skt.orderUpdates,skt.tradeUpdates,skt.positionUpdates,
104
+ skt.edis,skt.pricealerts])
105
+ console.log(skt.isConnected())
106
+ })
107
+
108
+ skt.on('close',function () {
109
+ console.log('closed')
110
+ })
111
+
112
+ skt.on('orders',function (msg) {
113
+ console.log("orders",msg)
114
+ skt.close()
115
+ })
116
+
117
+ skt.on('trades',function (msg) {
118
+ console.log('trades',msg)
119
+ })
120
+
121
+ skt.on('positions',function (msg) {
122
+ console.log('positions',msg)
123
+ })
124
+
125
+ skt.connect()
126
+ ```
127
+
128
+ ## Getting started data WebSocket
129
+
130
+ ```javascript
131
+ let DataSocket = require("fyers-api-v3").fyersDataSocket;
132
+
133
+ var skt= DataSocket.getInstance("Accesstoken in format APPID:AccessToken",
134
+ "path where to save logs")
135
+
136
+ skt.on("connect",function(){
137
+ skt.subscribe(['NSE:IDEA-EQ',"NSE:SBIN-EQ"])
138
+ //subscribing for market depth data if need of market depth comes as a diffrent tick
139
+ skt.subscribe(['NSE:IDEA-EQ',"NSE:SBIN-EQ"],true)
140
+ //to start lite mode to get fewer data like ltp change
141
+ skt.mode(skt.LiteMode)
142
+ //to revert back to full mode
143
+ // skt.mode(skt.FullMode)
144
+ })
145
+
146
+ skt.on("message",function(message){
147
+ console.log({"TEST":message})
148
+ })
149
+
150
+ skt.on("error",function(message){
151
+ console.log("erroris",message)
152
+ })
153
+
154
+ skt.on("close",function(){
155
+ console.log("socket closed")
156
+ })
157
+ skt.connect()
158
+ ```
159
+
160
+ ## Auto re-connect WebSocket client
161
+
162
+ Optionally you can enable client side auto re-connection to automatically reconnect if the connection is dropped.
163
+
164
+ All you need to do is enable auto re-connection. For example
165
+
166
+ ```javascript
167
+ // Enable auto reconnect with 5 second interval and retry for maximum of 5 times.
168
+ skt.autoReconnect();
169
+ ```
170
+