@@ -22,16 +22,14 @@ class Shoonya {
22
22
public const FeedTouchLine = 't ' , FeedSnapQuoate = 'd ' ;
23
23
public const PriceMarket = 'MKT ' , PriceLimit = 'LMT ' , PrinceSLLmit = 'SL-LMT ' , PriceSLM = 'SL-MKT ' , DS = 'DS ' , L2 = '2L ' , L3 = '3L ' ;
24
24
public const Buy = 'B ' , Sell = 'S ' , AITG = 'LTP_A_O ' , AITL = 'LTP_B_O ' ;
25
- public const CIQ = 'lib/chartIQ/FCIQ/index.php? ' , TVC = 'lib/tvcl/? ' ;
26
-
25
+ public const CIQ = 'lib/chartIQ/FCIQ/index.php? ' , TVC = 'NorenCharts/? ' ;
27
26
public $ tmp ;
28
27
protected $ urls = [
29
28
'host ' => 'https://api.shoonya.com/ ' ,
30
29
'ws_endpoint ' => 'wss://api.shoonya.com/NorenWSTP ' ,
31
30
'endpoint ' => 'https://api.shoonya.com/NorenWClientTP ' ,
32
- 'eodhost ' => 'https://api.shoonya.com/chartApi/getdata ' ,
33
- 'webchart ' => 'https://trade.shoonya.com/ ' ,
34
- 'localchart ' => 'http://127.0.0.1:8080/ '
31
+ 'webchart ' =>'https://trade.shoonya.com/ ' ,
32
+ 'localchart ' =>'http://127.0.0.1:8080/ '
35
33
];
36
34
protected $ routes = [
37
35
'login ' => '/QuickAuth ' ,
@@ -67,7 +65,10 @@ class Shoonya {
67
65
'cancelalert ' => '/CancelAlert ' ,
68
66
'modifyalert ' => '/ModifyAlert ' ,
69
67
'getpendingalert ' => '/GetPendingAlert ' ,
70
- 'getenabledalert ' => '/GetEnabledAlertTypes '
68
+ 'getenabledalert ' => '/GetEnabledAlertTypes ' ,
69
+ 'spanCalculator ' =>'/SpanCalc ' ,
70
+ 'optionGreek ' =>'/GetOptionGreek ' ,
71
+ 'DPSeries ' =>'/EODChartData '
71
72
];
72
73
73
74
public function __construct () {
@@ -411,11 +412,7 @@ public function getDailyPriceSeries(string $tysm, string $startDate, string $end
411
412
'to ' => $ et
412
413
];
413
414
414
- $ request = $ this ->guzzle ->post ($ this ->urls ['eodhost ' ], [
415
- 'header ' => ['Content-Type ' => 'application/json ' ],
416
- 'body ' => json_encode ($ values )
417
- ]);
418
- return $ this ->decode ($ request ->getBody ());
415
+ return $ this ->request ('DPSeries ' , $ values );
419
416
}
420
417
421
418
/**
@@ -799,27 +796,31 @@ public function connectWS() {
799
796
'actid ' => $ this ->accountId ,
800
797
'ordersource ' => 'API ' ,
801
798
'susertoken ' => $ this ->jKey ];
802
- $ this ->wsC = new \WSSC \WebSocketClient ($ this ->urls ['ws_endpoint ' ], new \WSSC \Components \ClientConfig ());
803
- $ this ->wsC ->send (json_encode ($ value ));
804
- print_r ($ this ->wsC ->receive ());
805
- if ($ this ->wsC ->isConnected ()) {
806
- return true ;
799
+ return json_encode ($ value );
807
800
}
808
- echo 'Failed to connect to WSS ' . PHP_EOL ;
809
- return false ;
810
- }
811
801
812
- public function subscribe (array |string $ intst , $ feedType = self ::FeedTouchLine) {
802
+ /**
803
+ * Subscribe to quotes feeds (websocket)
804
+ * @param array|string $intst
805
+ * @param type $feedType
806
+ */
807
+ public function subscribeFeed (array |string $ intst , $ feedType = self ::FeedTouchLine) {
813
808
$ values = [];
814
809
$ values ['t ' ] = $ feedType ;
815
810
if (is_array ($ intst )) {
816
811
$ values ['k ' ] = implode ('# ' , $ intst );
817
812
} else {
818
813
$ values ['k ' ] = $ intst ;
819
814
}
815
+ return json_encode ($ values );
820
816
}
821
817
822
- public function unsubscribe (array |string $ intst , $ feedType = self ::FeedTouchLine) {
818
+ /**
819
+ * Unsubscribe to quotes feed(websocket)
820
+ * @param array|string $intst
821
+ * @param type $feedType
822
+ */
823
+ public function unsubscribeFeed (array |string $ intst , $ feedType = self ::FeedTouchLine) {
823
824
$ values = [];
824
825
if ($ feedType == self ::FeedTouchLine) {
825
826
$ values ['t ' ] = 'u ' ;
@@ -835,12 +836,20 @@ public function unsubscribe(array|string $intst, $feedType = self::FeedTouchLine
835
836
}
836
837
837
838
/**
838
- * @todo
839
+ * subscribe to orders feed (websocket)
840
+ * @return type
839
841
*/
840
- public function subscribeOrders () {
841
- $ values = ['t ' => 'o ' , 'actid ' => $ this ->accountId ];
842
+ public function subscribeOrdersFeed () {
843
+ return json_encode ( ['t ' => 'o ' , 'actid ' => $ this ->accountId ]) ;
842
844
}
843
845
846
+ /**
847
+ * unsubscribe orders feed(websocket)
848
+ */
849
+ public function unSubscibeOrdersFeed () {
850
+ return json_encode (['t ' =>'uo ' ,'t ' =>'uok ' ]);
851
+ }
852
+
844
853
/**
845
854
* Set Alert
846
855
* @param string $tsym
@@ -930,7 +939,7 @@ public function loadChart(string $tsym = 'nifty 50', string $exch = 'NSE', strin
930
939
($ tsym == 'NIFTY50 ' || $ tsym == 'nifty50 ' ) ? $ tsym = 'NIFTY_50 ' : $ tsym . '-EQ ' ;
931
940
$ encode = base64_encode ('user= ' . $ this ->uid . '&token= ' . $ this ->jKey . "&exch_tsym=NSE: $ tsym: $ tsym&p=Web " );
932
941
}
933
- return $ this ->urls ['localchart ' ] . $ chartType . $ encode ;
942
+ return ( $ chartType == self :: TVC ) ? $ this ->urls ['webchart ' ]. $ chartType . $ encode : $ this -> urls [ ' localchart ' ]. $ chartType. $ encode ;
934
943
}
935
944
936
945
/**
@@ -1024,4 +1033,7 @@ private function sessionJson() {
1024
1033
return file_put_contents ('session.json ' , json_encode ($ this ->getSessionData (), JSON_PRETTY_PRINT ));
1025
1034
}
1026
1035
1036
+ public function __destruct () {
1037
+ $ this ->logout ();
1038
+ }
1027
1039
}
0 commit comments