mcxlib 0.1__tar.gz
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.
- mcxlib-0.1/LICENSE +202 -0
- mcxlib-0.1/MANIFEST.in +0 -0
- mcxlib-0.1/PKG-INFO +99 -0
- mcxlib-0.1/README.md +81 -0
- mcxlib-0.1/mcxlib/__init__.py +6 -0
- mcxlib-0.1/mcxlib/libutil.py +81 -0
- mcxlib-0.1/mcxlib/logger.py +15 -0
- mcxlib-0.1/mcxlib/market_data.py +375 -0
- mcxlib-0.1/mcxlib.egg-info/PKG-INFO +99 -0
- mcxlib-0.1/mcxlib.egg-info/SOURCES.txt +14 -0
- mcxlib-0.1/mcxlib.egg-info/dependency_links.txt +1 -0
- mcxlib-0.1/mcxlib.egg-info/requires.txt +2 -0
- mcxlib-0.1/mcxlib.egg-info/top_level.txt +1 -0
- mcxlib-0.1/setup.cfg +7 -0
- mcxlib-0.1/setup.py +28 -0
mcxlib-0.1/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
mcxlib-0.1/MANIFEST.in
ADDED
|
File without changes
|
mcxlib-0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mcxlib
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: python library to get MCX India data
|
|
5
|
+
Home-page: https://github.com/RuchiTanmay/mcxlib
|
|
6
|
+
Author: RuchiTanmay
|
|
7
|
+
Author-email: ruchitanmay@gmail.com
|
|
8
|
+
Keywords: mcx,mcx india,python,mcx data,mcx history data,commodity,mcx python,mcx python library,mcx library
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Natural Language :: English
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
|
|
19
|
+
# mcxlib 0.1
|
|
20
|
+
|
|
21
|
+
Python Library to get publicly available data on MCX website.
|
|
22
|
+
|
|
23
|
+
Release Notes
|
|
24
|
+
* Compatible and Tested with Python 3.8 and above
|
|
25
|
+
* Future release will be done on requirement basic
|
|
26
|
+
|
|
27
|
+
## Libraries Required
|
|
28
|
+
- requests
|
|
29
|
+
- numpy
|
|
30
|
+
- pandas
|
|
31
|
+
- lxml
|
|
32
|
+
|
|
33
|
+
For Windows systems you can install Anaconda, this will cover many dependencies (You'll have to install requests additionally though)
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
Fresh installation
|
|
37
|
+
|
|
38
|
+
```$pip install mcxlib```
|
|
39
|
+
|
|
40
|
+
Upgrade
|
|
41
|
+
|
|
42
|
+
```$pip install mcxlib --upgrade```
|
|
43
|
+
|
|
44
|
+
## Function list
|
|
45
|
+
|
|
46
|
+
* get_recent_expires
|
|
47
|
+
* get_market_watch
|
|
48
|
+
* get_top_gainers
|
|
49
|
+
* get_heat_map
|
|
50
|
+
* get_top_gainers
|
|
51
|
+
* get_top_losers
|
|
52
|
+
* get_most_active_contracts
|
|
53
|
+
* get_most_active_puts_calls
|
|
54
|
+
* get_bhav_copy
|
|
55
|
+
* get_historical_data
|
|
56
|
+
* get_pro_cli_details
|
|
57
|
+
* get_option_chain
|
|
58
|
+
* get_put_call_ratio
|
|
59
|
+
* get_category_wise_oi
|
|
60
|
+
* get_category_wise_turnover
|
|
61
|
+
* get_mcx_icomdex_indices
|
|
62
|
+
* get_trading_statistics
|
|
63
|
+
* get_ccl_delivery
|
|
64
|
+
|
|
65
|
+
Example :
|
|
66
|
+
|
|
67
|
+
import mcxlib
|
|
68
|
+
|
|
69
|
+
data = get_live_market_watch()
|
|
70
|
+
|
|
71
|
+
bhav_copy = get_bhav_copy(trade_date= '20231102', instrument = 'ALL')
|
|
72
|
+
|
|
73
|
+
option_chain = get_option_chain(commodity = 'CRUDEOIL', expiry = '15NOV2023')
|
|
74
|
+
|
|
75
|
+
cli_details = get_pro_cli_details(trade_month = '202301')
|
|
76
|
+
|
|
77
|
+
NB: always follow the function hint to apply valid parameter.
|
|
78
|
+
|
|
79
|
+
More functions will be available in future releases...
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
## How can I contribute?
|
|
83
|
+
There are multiple ways in which you can contribute-
|
|
84
|
+
|
|
85
|
+
### Write about your project
|
|
86
|
+
|
|
87
|
+
There are working on to add many function to this library. mcxlib at the moment is short of good documentation. There are lot of features in mcxlib yet to come :( , so till we complete the documentation, I'll need support from the community.
|
|
88
|
+
|
|
89
|
+
Please write about your projects in blogs, quora answers and other forums, so that people find working examples to get started.
|
|
90
|
+
|
|
91
|
+
### Raising issues, bugs, enhancement requests
|
|
92
|
+
|
|
93
|
+
For quick resolution please raise issues both [here on issue page](https://github.com/RuchiTanmay/mcxlib/issues). I'll try my best to address the issues quickly on github as and when I get notified, but raising it on stackoverflow will provide you access to a larger group and someone else might solve your problem before I do.
|
|
94
|
+
|
|
95
|
+
### Submit patches
|
|
96
|
+
|
|
97
|
+
If you have fixed an issue or added a new feature, please fork this repository, make your changes and submit a pull request. [Here's good article on how to do this.](https://code.tutsplus.com/tutorials/how-to-collaborate-on-github--net-34267)
|
|
98
|
+
|
|
99
|
+
Looking forward for healthy participation from community.
|
mcxlib-0.1/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# mcxlib 0.1
|
|
2
|
+
|
|
3
|
+
Python Library to get publicly available data on MCX website.
|
|
4
|
+
|
|
5
|
+
Release Notes
|
|
6
|
+
* Compatible and Tested with Python 3.8 and above
|
|
7
|
+
* Future release will be done on requirement basic
|
|
8
|
+
|
|
9
|
+
## Libraries Required
|
|
10
|
+
- requests
|
|
11
|
+
- numpy
|
|
12
|
+
- pandas
|
|
13
|
+
- lxml
|
|
14
|
+
|
|
15
|
+
For Windows systems you can install Anaconda, this will cover many dependencies (You'll have to install requests additionally though)
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
Fresh installation
|
|
19
|
+
|
|
20
|
+
```$pip install mcxlib```
|
|
21
|
+
|
|
22
|
+
Upgrade
|
|
23
|
+
|
|
24
|
+
```$pip install mcxlib --upgrade```
|
|
25
|
+
|
|
26
|
+
## Function list
|
|
27
|
+
|
|
28
|
+
* get_recent_expires
|
|
29
|
+
* get_market_watch
|
|
30
|
+
* get_top_gainers
|
|
31
|
+
* get_heat_map
|
|
32
|
+
* get_top_gainers
|
|
33
|
+
* get_top_losers
|
|
34
|
+
* get_most_active_contracts
|
|
35
|
+
* get_most_active_puts_calls
|
|
36
|
+
* get_bhav_copy
|
|
37
|
+
* get_historical_data
|
|
38
|
+
* get_pro_cli_details
|
|
39
|
+
* get_option_chain
|
|
40
|
+
* get_put_call_ratio
|
|
41
|
+
* get_category_wise_oi
|
|
42
|
+
* get_category_wise_turnover
|
|
43
|
+
* get_mcx_icomdex_indices
|
|
44
|
+
* get_trading_statistics
|
|
45
|
+
* get_ccl_delivery
|
|
46
|
+
|
|
47
|
+
Example :
|
|
48
|
+
|
|
49
|
+
import mcxlib
|
|
50
|
+
|
|
51
|
+
data = get_live_market_watch()
|
|
52
|
+
|
|
53
|
+
bhav_copy = get_bhav_copy(trade_date= '20231102', instrument = 'ALL')
|
|
54
|
+
|
|
55
|
+
option_chain = get_option_chain(commodity = 'CRUDEOIL', expiry = '15NOV2023')
|
|
56
|
+
|
|
57
|
+
cli_details = get_pro_cli_details(trade_month = '202301')
|
|
58
|
+
|
|
59
|
+
NB: always follow the function hint to apply valid parameter.
|
|
60
|
+
|
|
61
|
+
More functions will be available in future releases...
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
## How can I contribute?
|
|
65
|
+
There are multiple ways in which you can contribute-
|
|
66
|
+
|
|
67
|
+
### Write about your project
|
|
68
|
+
|
|
69
|
+
There are working on to add many function to this library. mcxlib at the moment is short of good documentation. There are lot of features in mcxlib yet to come :( , so till we complete the documentation, I'll need support from the community.
|
|
70
|
+
|
|
71
|
+
Please write about your projects in blogs, quora answers and other forums, so that people find working examples to get started.
|
|
72
|
+
|
|
73
|
+
### Raising issues, bugs, enhancement requests
|
|
74
|
+
|
|
75
|
+
For quick resolution please raise issues both [here on issue page](https://github.com/RuchiTanmay/mcxlib/issues). I'll try my best to address the issues quickly on github as and when I get notified, but raising it on stackoverflow will provide you access to a larger group and someone else might solve your problem before I do.
|
|
76
|
+
|
|
77
|
+
### Submit patches
|
|
78
|
+
|
|
79
|
+
If you have fixed an issue or added a new feature, please fork this repository, make your changes and submit a pull request. [Here's good article on how to do this.](https://code.tutsplus.com/tutorials/how-to-collaborate-on-github--net-34267)
|
|
80
|
+
|
|
81
|
+
Looking forward for healthy participation from community.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
from market_data import get_market_watch, get_top_gainers, get_heat_map, get_top_gainers, get_recent_expires, \
|
|
2
|
+
get_top_losers, get_most_active_contracts, get_most_active_puts_calls, get_bhav_copy, \
|
|
3
|
+
get_historical_date_wise_data, get_pro_cli_details, get_option_chain, get_put_call_ratio, get_category_wise_oi, \
|
|
4
|
+
get_category_wise_turnover, get_mcx_icomdex_indices, get_trading_statistics, get_ccl_delivery
|
|
5
|
+
|
|
6
|
+
__version__ = 0.1
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
header = {
|
|
5
|
+
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
|
6
|
+
'Accept-Language': 'en-US,en;q=0.5',
|
|
7
|
+
'Connection': 'keep-alive',
|
|
8
|
+
'Content-Length': '0',
|
|
9
|
+
'Content-Type': 'application/json',
|
|
10
|
+
'Cookie': 'ASP.NET_SessionId=p4dkpr24k2j2ck1w2qnov1h5',
|
|
11
|
+
'Origin': 'https://www.mcxindia.com',
|
|
12
|
+
'Referer': 'https://www.mcxindia.com/market-data/market-watch',
|
|
13
|
+
'Sec-Fetch-Dest': 'empty',
|
|
14
|
+
'Sec-Fetch-Mode': 'cors',
|
|
15
|
+
'Sec-Fetch-Site': 'same-origin',
|
|
16
|
+
'Sec-GPC': '1',
|
|
17
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36',
|
|
18
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
19
|
+
'sec-ch-ua': '"Chromium";v="118", "Brave";v="118", "Not=A?Brand";v="99"',
|
|
20
|
+
'sec-ch-ua-mobile': '?0',
|
|
21
|
+
'sec-ch-ua-platform': '"Windows"'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class CalenderNotFound(Exception):
|
|
26
|
+
def __init__(self, message):
|
|
27
|
+
|
|
28
|
+
# Call the base class constructor with the parameters it needs
|
|
29
|
+
super(CalenderNotFound, self).__init__(message)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class MCXdataNotFound(Exception):
|
|
33
|
+
def __init__(self, message):
|
|
34
|
+
super(MCXdataNotFound, self).__init__(message)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def get_headers(use_for:str = 'market-watch'):
|
|
38
|
+
return {
|
|
39
|
+
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
|
40
|
+
'Accept-Language': 'en-US,en;q=0.5',
|
|
41
|
+
'Connection': 'keep-alive',
|
|
42
|
+
'Content-Length': '0',
|
|
43
|
+
'Content-Type': 'application/json',
|
|
44
|
+
'Origin': 'https://www.mcxindia.com',
|
|
45
|
+
'Referer': f'https://www.mcxindia.com/market-data/{use_for}',
|
|
46
|
+
'Sec-GPC': '1',
|
|
47
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36',
|
|
48
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
49
|
+
'sec-ch-ua': '"Chromium";v="118", "Brave";v="118", "Not=A?Brand";v="99"',
|
|
50
|
+
'sec-ch-ua-platform': '"Windows"'
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def validate_date_param(start_date:str, end_date:str):
|
|
55
|
+
if not start_date or not end_date:
|
|
56
|
+
raise ValueError(' Please provide the valid parameters')
|
|
57
|
+
try:
|
|
58
|
+
start_date = datetime.strptime(start_date, '%Y%m%d')
|
|
59
|
+
end_date = datetime.strptime(end_date, '%Y%m%d')
|
|
60
|
+
time_delta = (end_date - start_date).days
|
|
61
|
+
if time_delta < 1:
|
|
62
|
+
raise ValueError(f'end_date should greater than start_date ')
|
|
63
|
+
elif time_delta > 365:
|
|
64
|
+
raise ValueError(f'Date range cannot be greater than 365 days')
|
|
65
|
+
except Exception as e:
|
|
66
|
+
print(e)
|
|
67
|
+
raise ValueError(f'either or both start_date = {start_date} || end_date = {end_date} are not valid value')
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def get_mcxlib_path():
|
|
71
|
+
"""
|
|
72
|
+
Extract isap file path
|
|
73
|
+
"""
|
|
74
|
+
mydir = os.getcwd()
|
|
75
|
+
return mydir.split(r'\mcxlib', 1)[0]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# if __name__ == '__main__':
|
|
80
|
+
# # data = derive_from_and_to_date('6M')
|
|
81
|
+
# print(trading_holiday_calendar())
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# Create a custom logger
|
|
6
|
+
def mylogger(logger):
|
|
7
|
+
logger.setLevel(logging.DEBUG)
|
|
8
|
+
# Create handlers
|
|
9
|
+
c_handler = logging.StreamHandler(sys.stdout)
|
|
10
|
+
# Create formatters and add it to handlers
|
|
11
|
+
f_format = logging.Formatter('%(name)s::%(levelname)s::%(message)s')
|
|
12
|
+
c_handler.setFormatter(f_format)
|
|
13
|
+
# Add handlers to the logger
|
|
14
|
+
logger.addHandler(c_handler)
|
|
15
|
+
return logger
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import requests
|
|
3
|
+
from mcxlib.libutil import *
|
|
4
|
+
import json
|
|
5
|
+
import calendar
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def get_recent_expires(commodity:str = 'ALL') -> pd.DataFrame:
|
|
9
|
+
"""
|
|
10
|
+
get recent expiry for commodity
|
|
11
|
+
:param commodity: any of the list ['ALL', 'CRUDEOIL', 'COPPER', 'GOLD', 'GOLDM', 'NATURALGAS', 'SILVER', 'SILVERM', 'ZINC']
|
|
12
|
+
:return: panda dataframe
|
|
13
|
+
"""
|
|
14
|
+
url = "https://www.mcxindia.com/backpage.aspx/GetExpirywisePutCallRatio"
|
|
15
|
+
payload = {}
|
|
16
|
+
headers = get_headers(use_for='put-call-ratio')
|
|
17
|
+
try:
|
|
18
|
+
data_dict = requests.post(url, headers=headers, data=payload).json()
|
|
19
|
+
data_df = pd.DataFrame.from_dict(data_dict['d']['Data'])
|
|
20
|
+
data_df.drop(columns=['ExtensionData', 'Date', 'Ratio'], inplace=True)
|
|
21
|
+
except Exception as e:
|
|
22
|
+
raise ValueError(f" data not found / Invalid request : MCX error:{e}")
|
|
23
|
+
if not commodity == 'ALL':
|
|
24
|
+
data_df = data_df[data_df['Symbol'] == commodity]
|
|
25
|
+
if data_df.empty:
|
|
26
|
+
raise ValueError("Apply a valid commodity name")
|
|
27
|
+
return data_df
|
|
28
|
+
|
|
29
|
+
def get_market_watch() -> pd.DataFrame:
|
|
30
|
+
"""
|
|
31
|
+
get live market watch on MCX
|
|
32
|
+
:return: panda dataframe
|
|
33
|
+
"""
|
|
34
|
+
url="https://www.mcxindia.com/backpage.aspx/GetMarketWatch"
|
|
35
|
+
payload = {}
|
|
36
|
+
headers = get_headers(use_for='market-watch')
|
|
37
|
+
try:
|
|
38
|
+
data_dict = requests.request("POST", url, headers=headers, data=payload).json()
|
|
39
|
+
data_df = pd.DataFrame.from_dict(data_dict['d']['Data'])
|
|
40
|
+
data_df.drop(columns=['__type', 'LTT'], inplace=True)
|
|
41
|
+
except Exception as e:
|
|
42
|
+
raise ValueError(f" No Data Found : MCX error:{e}")
|
|
43
|
+
return data_df
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def get_heat_map() -> pd.DataFrame:
|
|
47
|
+
"""
|
|
48
|
+
get live market heat map on MCX
|
|
49
|
+
:return: panda dataframe
|
|
50
|
+
"""
|
|
51
|
+
url="https://www.mcxindia.com/backpage.aspx/GetHeatMap"
|
|
52
|
+
payload = {}
|
|
53
|
+
headers = get_headers(use_for='heatmap')
|
|
54
|
+
try:
|
|
55
|
+
data_dict = requests.post(url, headers=headers, data=payload).json()
|
|
56
|
+
data_df = pd.DataFrame.from_dict(data_dict['d']['Data'])
|
|
57
|
+
data_df.drop(columns=['__type', 'Dttm'], inplace=True)
|
|
58
|
+
except Exception as e:
|
|
59
|
+
raise ValueError(f" No heatmap Data Found : MCX error:{e}")
|
|
60
|
+
return data_df
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def get_top_gainers() -> pd.DataFrame:
|
|
64
|
+
"""
|
|
65
|
+
get live market top gainers on MCX
|
|
66
|
+
:return: panda dataframe
|
|
67
|
+
"""
|
|
68
|
+
url = "https://www.mcxindia.com/backpage.aspx/GetGainer"
|
|
69
|
+
payload = {}
|
|
70
|
+
headers = get_headers(use_for='top-gainers')
|
|
71
|
+
try:
|
|
72
|
+
data_dict = requests.post(url, headers=headers, data=payload).json()
|
|
73
|
+
data_df = pd.DataFrame.from_dict(data_dict['d']['Data'])
|
|
74
|
+
data_df.drop(columns=['ExtensionData', 'LTT'], inplace=True)
|
|
75
|
+
except Exception as e:
|
|
76
|
+
raise ValueError(f" No top-gainers Data Found / Invalid request : MCX error:{e}")
|
|
77
|
+
return data_df
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def get_top_losers() -> pd.DataFrame:
|
|
81
|
+
"""
|
|
82
|
+
get live market top losers on MCX
|
|
83
|
+
:return: panda dataframe
|
|
84
|
+
"""
|
|
85
|
+
url = "https://www.mcxindia.com/backpage.aspx/GetLosers"
|
|
86
|
+
payload = {}
|
|
87
|
+
headers = get_headers(use_for='top-losers')
|
|
88
|
+
try:
|
|
89
|
+
data_dict = requests.post(url, headers=headers, data=payload).json()
|
|
90
|
+
data_df = pd.DataFrame.from_dict(data_dict['d']['Data'])
|
|
91
|
+
data_df.drop(columns=['ExtensionData', 'LTT'], inplace=True)
|
|
92
|
+
except Exception as e:
|
|
93
|
+
raise ValueError(f" No top-losers Data Found / Invalid request : MCX error:{e}")
|
|
94
|
+
return data_df
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def get_most_active_contracts(instrument:str = 'ALL') -> pd.DataFrame:
|
|
98
|
+
"""
|
|
99
|
+
get live market most active contract on MCX
|
|
100
|
+
:param instrument: any value from the list ['ALL','FUTCOM','FUTIDX','OPTCOM','OPTFUT']
|
|
101
|
+
:return: panda dataframe
|
|
102
|
+
"""
|
|
103
|
+
headers = get_headers(use_for='most-active-contracts')
|
|
104
|
+
url = "https://www.mcxindia.com/backpage.aspx/GetMostActiveContractByVolumeFilter"
|
|
105
|
+
payload = json.dumps({
|
|
106
|
+
"InstrumentType": f'{instrument}'
|
|
107
|
+
})
|
|
108
|
+
try:
|
|
109
|
+
data_dict = requests.request("POST", url, headers=headers, data=payload).json()
|
|
110
|
+
data_df = pd.DataFrame.from_dict(data_dict['d']['Data'])
|
|
111
|
+
data_df.drop(columns=['ExtensionData', 'Date', 'Unit'], inplace=True)
|
|
112
|
+
except Exception as e:
|
|
113
|
+
raise ValueError(f" No most-active-contracts Data Found / Invalid request : MCX error:{e}")
|
|
114
|
+
return data_df
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def get_most_active_puts_calls(option_type:str = 'PE',
|
|
118
|
+
product:str = 'ALL',
|
|
119
|
+
instrument:str = 'OPTFUT') -> pd.DataFrame:
|
|
120
|
+
"""
|
|
121
|
+
get live market most active put/calls on MCX
|
|
122
|
+
:param option_type: any value from the list ['PE','CE']
|
|
123
|
+
:param product: any value from the list ['ALL','COPPER','CRUDEOIL','GOLD','GOLDM','NATURALGAS',
|
|
124
|
+
'SILVER','SILVERM','ZINC']
|
|
125
|
+
:param instrument: any value from the list ['OPTCOM','OPTIONS']
|
|
126
|
+
:return: panda dataframe
|
|
127
|
+
"""
|
|
128
|
+
headers = get_headers(use_for='most-active-puts-calls')
|
|
129
|
+
url = "https://www.mcxindia.com/backpage.aspx/GetMostActiveOptionsContractsByVolume"
|
|
130
|
+
payload_param = {'OptionType':f'{option_type}','Product':f'{product}','InstrumentType':f'{instrument}'}
|
|
131
|
+
payload = f"{payload_param}"
|
|
132
|
+
try:
|
|
133
|
+
data_dict = requests.request("POST", url, headers=headers, data=payload).json()
|
|
134
|
+
data_df = pd.DataFrame.from_dict(data_dict['d']['Data'])
|
|
135
|
+
data_df.drop(columns=['ExtensionData', 'LTT'], inplace=True)
|
|
136
|
+
except Exception as e:
|
|
137
|
+
raise ValueError(f" No Data Found / Invalid request : MCX error:{e}")
|
|
138
|
+
return data_df
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def get_bhav_copy(trade_date:str = '20230102',
|
|
142
|
+
instrument:str = 'ALL') -> pd.DataFrame:
|
|
143
|
+
"""
|
|
144
|
+
get bhav copy
|
|
145
|
+
:param trade_date: in str format : YYYYMMDD
|
|
146
|
+
:param instrument: any value from the list ['ALL','FUTCOM','FUTIDX','OPTCOM','OPTFUT']
|
|
147
|
+
:return: panda dataframe
|
|
148
|
+
"""
|
|
149
|
+
headers = get_headers(use_for='bhavcopy')
|
|
150
|
+
url="https://www.mcxindia.com/backpage.aspx/GetDateWiseBhavCopy"
|
|
151
|
+
payload_param = {'Date': f'{trade_date}', 'InstrumentName': f'{instrument}'}
|
|
152
|
+
payload = f"{payload_param}"
|
|
153
|
+
try:
|
|
154
|
+
data_dict = requests.request("POST", url, headers=headers, data=payload).json()
|
|
155
|
+
data_df = pd.DataFrame.from_dict(data_dict['d']['Data'])
|
|
156
|
+
data_df.drop(columns='__type', inplace=True)
|
|
157
|
+
except Exception as e:
|
|
158
|
+
raise ValueError(f" No Data Found / Invalid parameters : MCX error:{e}")
|
|
159
|
+
return data_df
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def get_historical_date_wise_data(start_date:str = '20230101',
|
|
163
|
+
end_date:str = '20231103',) -> pd.DataFrame:
|
|
164
|
+
"""
|
|
165
|
+
to get date wise history data in a panda dataframe
|
|
166
|
+
Date range cannot be greater than 365 days
|
|
167
|
+
:param start_date: in str format : YYYYMMDD
|
|
168
|
+
:param end_date: in str format : YYYYMMDD
|
|
169
|
+
:return: panda dataframe
|
|
170
|
+
"""
|
|
171
|
+
headers = get_headers(use_for='historical-data')
|
|
172
|
+
url = "https://www.mcxindia.com/backpage.aspx/GetHistoricalDataDetails"
|
|
173
|
+
payload = json.dumps({
|
|
174
|
+
"GroupBy": "D",
|
|
175
|
+
"Segment": "ALL",
|
|
176
|
+
"CommodityHead": "ALL",
|
|
177
|
+
"Commodity": "ALL",
|
|
178
|
+
"Startdate": f"{start_date}",
|
|
179
|
+
"EndDate": f"{end_date}",
|
|
180
|
+
"InstrumentName": "ALL"
|
|
181
|
+
})
|
|
182
|
+
validate_date_param(start_date=start_date, end_date=end_date)
|
|
183
|
+
try:
|
|
184
|
+
data_dict = requests.request("POST", url, headers=headers, data=payload).json()
|
|
185
|
+
data_df = pd.DataFrame.from_dict(data_dict['d']['Data'])
|
|
186
|
+
data_df['Date'] = pd.to_datetime(data_df['Date'])
|
|
187
|
+
data_df.drop(columns=['__type', 'Year', 'Month'], inplace=True)
|
|
188
|
+
except Exception as e:
|
|
189
|
+
raise ValueError(f" No Data Found / Invalid parameters : MCX error:{e}")
|
|
190
|
+
return data_df
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def get_mcx_icomdex_indices() -> pd.DataFrame:
|
|
194
|
+
"""
|
|
195
|
+
get MCX iCOMDEX Indices
|
|
196
|
+
:return: panda dataframe
|
|
197
|
+
"""
|
|
198
|
+
url = "https://www.mcxindia.com/backpage.aspx/GetMCXIComdexIndicesDetails"
|
|
199
|
+
payload = json.dumps({
|
|
200
|
+
"Instrument_Identifier": "0",
|
|
201
|
+
"Lang": "en"
|
|
202
|
+
})
|
|
203
|
+
headers = get_headers(use_for='mcx-icomdex-indices')
|
|
204
|
+
try:
|
|
205
|
+
data_dict = requests.post(url, headers=headers, data=payload).json()
|
|
206
|
+
data_df = pd.DataFrame.from_dict(data_dict['d']['Data'])
|
|
207
|
+
data_df.drop(columns=['__type'], inplace=True)
|
|
208
|
+
except Exception as e:
|
|
209
|
+
raise ValueError(f" No Data Found / Invalid request : MCX error:{e}")
|
|
210
|
+
return data_df
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def get_pro_cli_details(trade_month:str = '202301') -> pd.DataFrame:
|
|
214
|
+
"""
|
|
215
|
+
get PRO CLI Details for given month
|
|
216
|
+
:param trade_month: in str format : YYYYMM
|
|
217
|
+
:return: panda dataframe
|
|
218
|
+
"""
|
|
219
|
+
headers = get_headers(use_for='pro-cli-details')
|
|
220
|
+
url = "https://www.mcxindia.com/backpage.aspx/GetPROClientDetailsSegmentWise"
|
|
221
|
+
payload = json.dumps({
|
|
222
|
+
"GroupBy": "M",
|
|
223
|
+
"Segment": "ALL",
|
|
224
|
+
"CommodityHead": "ALL",
|
|
225
|
+
"Commodity": "ALL",
|
|
226
|
+
"Startdate": f"{trade_month}"
|
|
227
|
+
})
|
|
228
|
+
try:
|
|
229
|
+
data_dict = requests.request("POST", url, headers=headers, data=payload).json()
|
|
230
|
+
data_df = pd.DataFrame.from_dict(data_dict['d']['Data'])
|
|
231
|
+
data_df['Date'] = pd.to_datetime(data_df['Date'])
|
|
232
|
+
data_df.drop(columns=['ExtensionData', 'TradingDate', 'Date'], inplace=True)
|
|
233
|
+
except Exception as e:
|
|
234
|
+
raise ValueError(f" No Data Found / Invalid parameters : MCX error:{e}")
|
|
235
|
+
return data_df
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def get_option_chain(commodity:str = 'CRUDEOIL', expiry:str = '15NOV2023') -> pd.DataFrame:
|
|
239
|
+
"""
|
|
240
|
+
get live option chain from MCX site, the expiry date is different for different commodity
|
|
241
|
+
:param commodity: any of the list ['CRUDEOIL', 'COPPER', 'GOLD', 'GOLDM', 'NATURALGAS', 'SILVER', 'SILVERM', 'ZINC']
|
|
242
|
+
:param expiry: in the format od 'DDMMMYYYY' eg:'15NOV2023'
|
|
243
|
+
:return: panda dataframe
|
|
244
|
+
"""
|
|
245
|
+
headers = get_headers(use_for='option-chain')
|
|
246
|
+
url = "https://www.mcxindia.com/backpage.aspx/GetOptionChain"
|
|
247
|
+
payload_param = {'Commodity':f'{commodity}','Expiry':f'{expiry}'}
|
|
248
|
+
payload = f"{payload_param}"
|
|
249
|
+
try:
|
|
250
|
+
data_dict = requests.request("POST", url, headers=headers, data=payload).json()
|
|
251
|
+
data_df = pd.DataFrame.from_dict(data_dict['d']['Data'])
|
|
252
|
+
data_df.drop(columns=['ExtensionData', 'PE_LTT', 'CE_LTT', 'LTT', 'Symbol'], inplace=True)
|
|
253
|
+
data_df = data_df[(data_df['CE_OpenInterest']>0) | (data_df['PE_OpenInterest']>0)].copy()
|
|
254
|
+
except Exception as e:
|
|
255
|
+
raise ValueError(f" Invalid parameters : MCX error:{e}")
|
|
256
|
+
data_df.reset_index(inplace=True)
|
|
257
|
+
data_df.drop(columns='index', inplace=True)
|
|
258
|
+
return data_df
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def get_put_call_ratio(ratio_type:str = 'expiry_wise') -> pd.DataFrame:
|
|
262
|
+
"""
|
|
263
|
+
get recent expiry wise put call ratio
|
|
264
|
+
:param ratio_type: 'expiry_wise' or 'commodity_wise'
|
|
265
|
+
:return: panda dataframe
|
|
266
|
+
"""
|
|
267
|
+
if ratio_type =='expiry_wise':
|
|
268
|
+
url = "https://www.mcxindia.com/backpage.aspx/GetExpirywisePutCallRatio"
|
|
269
|
+
elif ratio_type =='commodity_wise':
|
|
270
|
+
url = "https://www.mcxindia.com/backpage.aspx/GetCommoditywisePutCallRatio"
|
|
271
|
+
else:
|
|
272
|
+
raise ValueError(" Please apply valid ratio type")
|
|
273
|
+
payload = {}
|
|
274
|
+
headers = get_headers(use_for='put-call-ratio')
|
|
275
|
+
try:
|
|
276
|
+
data_dict = requests.post(url, headers=headers, data=payload).json()
|
|
277
|
+
data_df = pd.DataFrame.from_dict(data_dict['d']['Data'])
|
|
278
|
+
data_df.drop(columns=['ExtensionData', 'Date'], inplace=True)
|
|
279
|
+
except Exception as e:
|
|
280
|
+
raise ValueError(f" call put ratio data not found / Invalid request : MCX error:{e}")
|
|
281
|
+
return data_df
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def get_category_wise_turnover(year:int = 2023, month_number:int = 9) -> pd.DataFrame:
|
|
285
|
+
"""
|
|
286
|
+
get the category wise turnover data
|
|
287
|
+
:param year: int format : YYYY
|
|
288
|
+
:param month_number: int between (1 to 12)
|
|
289
|
+
:return: pandas dataframe
|
|
290
|
+
"""
|
|
291
|
+
month_long = calendar.month_name[month_number].lower()
|
|
292
|
+
month_short = calendar.month_abbr[month_number].lower()
|
|
293
|
+
try:
|
|
294
|
+
url=f"https://www.mcxindia.com/docs/default-source/market-data/historicaldata/{str(year)}/{month_long}/" \
|
|
295
|
+
f"category-wise-turnover-{month_short}-{str(year)}.xlsx"
|
|
296
|
+
data_df = pd.read_excel(url, skiprows=2, skipfooter=9)
|
|
297
|
+
except Exception as e:
|
|
298
|
+
raise ValueError(f" apply valid parameter : MCX error:{e}")
|
|
299
|
+
return data_df
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def get_category_wise_oi(year:int = 2023, month_number:int = 9) -> pd.DataFrame:
|
|
303
|
+
"""
|
|
304
|
+
get the category wise open interest data
|
|
305
|
+
:param year: int format : YYYY
|
|
306
|
+
:param month_number: int between (1 to 12)
|
|
307
|
+
:return: pandas dataframe
|
|
308
|
+
"""
|
|
309
|
+
month_long = calendar.month_name[month_number].lower()
|
|
310
|
+
month_short = calendar.month_abbr[month_number].lower()
|
|
311
|
+
try:
|
|
312
|
+
url = f"https://www.mcxindia.com/docs/default-source/market-data/historicaldata/{str(year)}/{month_long}/" \
|
|
313
|
+
f"category-wise-oi-{month_short}-{str(year)}.xlsx"
|
|
314
|
+
data_df = pd.read_excel(url, skiprows=3, skipfooter=8)
|
|
315
|
+
except Exception as e:
|
|
316
|
+
raise ValueError(f" apply valid parameter : MCX error:{e}")
|
|
317
|
+
data_df.columns = ['Date', 'Commodity', 'Instrument', 'Open Interest', 'FPOs/ Farmers(Long OI)',
|
|
318
|
+
'FPOs/ Farmers(Short OI)', 'VCPs/ Hedger(Long OI)', 'VCPs/ Hedger(Short OI)',
|
|
319
|
+
'Proprietary traders(Long OI)', 'Proprietary traders(Short OI)',
|
|
320
|
+
'Domestic Financial institutional investors(Long OI)',
|
|
321
|
+
'Domestic Financial institutional investors(Short OI)', 'Foreign Participants(Long OI)',
|
|
322
|
+
'Foreign Participants(Short OI)', 'Others(Long OI)', 'Others(Short OI)']
|
|
323
|
+
return data_df
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def get_ccl_delivery(year:int = 2023, month_number:int = 9) -> pd.DataFrame:
|
|
327
|
+
"""
|
|
328
|
+
get the ccl delivery data
|
|
329
|
+
:param year: int format : YYYY
|
|
330
|
+
:param month_number: int between (1 to 12)
|
|
331
|
+
:return: pandas dataframe
|
|
332
|
+
"""
|
|
333
|
+
month_long = calendar.month_name[month_number].lower()
|
|
334
|
+
month_short = calendar.month_abbr[month_number].lower()
|
|
335
|
+
try:
|
|
336
|
+
url=f"https://www.mcxindia.com/docs/default-source/market-data/historicaldata/{str(year)}/{month_long}/" \
|
|
337
|
+
f"ccl_delivery.xlsx"
|
|
338
|
+
data_df = pd.read_excel(url)
|
|
339
|
+
except Exception as e:
|
|
340
|
+
raise ValueError(f" apply valid parameter : MCX error:{e}")
|
|
341
|
+
data_df.dropna(inplace=True)
|
|
342
|
+
data_df.reset_index(inplace=True)
|
|
343
|
+
data_df.drop(columns='index', inplace=True)
|
|
344
|
+
return data_df
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def get_trading_statistics(year:int = 2023, month_number:int = 9) -> pd.DataFrame:
|
|
348
|
+
"""
|
|
349
|
+
get the trading statistics data from MCX
|
|
350
|
+
:param year: int format : YYYY
|
|
351
|
+
:param month_number: int between (1 to 12)
|
|
352
|
+
:return: pandas dataframe
|
|
353
|
+
"""
|
|
354
|
+
month_long = calendar.month_name[month_number].lower()
|
|
355
|
+
month_short = calendar.month_abbr[month_number].lower()
|
|
356
|
+
try:
|
|
357
|
+
url=f"https://www.mcxindia.com/docs/default-source/market-data/historicaldata/{str(year)}/{month_long}/" \
|
|
358
|
+
f"trading-statistics-{month_short}-{str(year)}.xlsx"
|
|
359
|
+
data_df = pd.read_excel(url, skipfooter=5)
|
|
360
|
+
except Exception as e:
|
|
361
|
+
raise ValueError(f" apply valid parameter : MCX error:{e}")
|
|
362
|
+
data_df.rename(columns={"Mode of Trading (% of Turnover)": "Mode of ALGO Trading (% of Turnover)",
|
|
363
|
+
"Unnamed: 25": "Mode of Non-ALGO Trading (% of Turnover)"},inplace=True)
|
|
364
|
+
data_df.dropna(inplace=True)
|
|
365
|
+
data_df.reset_index(inplace=True)
|
|
366
|
+
data_df.drop(columns='index', inplace=True)
|
|
367
|
+
return data_df
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
# if __name__ == '__main__':
|
|
371
|
+
# df = get_recent_expires(commodity='COPPE')
|
|
372
|
+
# print(df.columns)
|
|
373
|
+
# print(df)
|
|
374
|
+
|
|
375
|
+
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mcxlib
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: python library to get MCX India data
|
|
5
|
+
Home-page: https://github.com/RuchiTanmay/mcxlib
|
|
6
|
+
Author: RuchiTanmay
|
|
7
|
+
Author-email: ruchitanmay@gmail.com
|
|
8
|
+
Keywords: mcx,mcx india,python,mcx data,mcx history data,commodity,mcx python,mcx python library,mcx library
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Natural Language :: English
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
|
|
19
|
+
# mcxlib 0.1
|
|
20
|
+
|
|
21
|
+
Python Library to get publicly available data on MCX website.
|
|
22
|
+
|
|
23
|
+
Release Notes
|
|
24
|
+
* Compatible and Tested with Python 3.8 and above
|
|
25
|
+
* Future release will be done on requirement basic
|
|
26
|
+
|
|
27
|
+
## Libraries Required
|
|
28
|
+
- requests
|
|
29
|
+
- numpy
|
|
30
|
+
- pandas
|
|
31
|
+
- lxml
|
|
32
|
+
|
|
33
|
+
For Windows systems you can install Anaconda, this will cover many dependencies (You'll have to install requests additionally though)
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
Fresh installation
|
|
37
|
+
|
|
38
|
+
```$pip install mcxlib```
|
|
39
|
+
|
|
40
|
+
Upgrade
|
|
41
|
+
|
|
42
|
+
```$pip install mcxlib --upgrade```
|
|
43
|
+
|
|
44
|
+
## Function list
|
|
45
|
+
|
|
46
|
+
* get_recent_expires
|
|
47
|
+
* get_market_watch
|
|
48
|
+
* get_top_gainers
|
|
49
|
+
* get_heat_map
|
|
50
|
+
* get_top_gainers
|
|
51
|
+
* get_top_losers
|
|
52
|
+
* get_most_active_contracts
|
|
53
|
+
* get_most_active_puts_calls
|
|
54
|
+
* get_bhav_copy
|
|
55
|
+
* get_historical_data
|
|
56
|
+
* get_pro_cli_details
|
|
57
|
+
* get_option_chain
|
|
58
|
+
* get_put_call_ratio
|
|
59
|
+
* get_category_wise_oi
|
|
60
|
+
* get_category_wise_turnover
|
|
61
|
+
* get_mcx_icomdex_indices
|
|
62
|
+
* get_trading_statistics
|
|
63
|
+
* get_ccl_delivery
|
|
64
|
+
|
|
65
|
+
Example :
|
|
66
|
+
|
|
67
|
+
import mcxlib
|
|
68
|
+
|
|
69
|
+
data = get_live_market_watch()
|
|
70
|
+
|
|
71
|
+
bhav_copy = get_bhav_copy(trade_date= '20231102', instrument = 'ALL')
|
|
72
|
+
|
|
73
|
+
option_chain = get_option_chain(commodity = 'CRUDEOIL', expiry = '15NOV2023')
|
|
74
|
+
|
|
75
|
+
cli_details = get_pro_cli_details(trade_month = '202301')
|
|
76
|
+
|
|
77
|
+
NB: always follow the function hint to apply valid parameter.
|
|
78
|
+
|
|
79
|
+
More functions will be available in future releases...
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
## How can I contribute?
|
|
83
|
+
There are multiple ways in which you can contribute-
|
|
84
|
+
|
|
85
|
+
### Write about your project
|
|
86
|
+
|
|
87
|
+
There are working on to add many function to this library. mcxlib at the moment is short of good documentation. There are lot of features in mcxlib yet to come :( , so till we complete the documentation, I'll need support from the community.
|
|
88
|
+
|
|
89
|
+
Please write about your projects in blogs, quora answers and other forums, so that people find working examples to get started.
|
|
90
|
+
|
|
91
|
+
### Raising issues, bugs, enhancement requests
|
|
92
|
+
|
|
93
|
+
For quick resolution please raise issues both [here on issue page](https://github.com/RuchiTanmay/mcxlib/issues). I'll try my best to address the issues quickly on github as and when I get notified, but raising it on stackoverflow will provide you access to a larger group and someone else might solve your problem before I do.
|
|
94
|
+
|
|
95
|
+
### Submit patches
|
|
96
|
+
|
|
97
|
+
If you have fixed an issue or added a new feature, please fork this repository, make your changes and submit a pull request. [Here's good article on how to do this.](https://code.tutsplus.com/tutorials/how-to-collaborate-on-github--net-34267)
|
|
98
|
+
|
|
99
|
+
Looking forward for healthy participation from community.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
setup.cfg
|
|
5
|
+
setup.py
|
|
6
|
+
mcxlib/__init__.py
|
|
7
|
+
mcxlib/libutil.py
|
|
8
|
+
mcxlib/logger.py
|
|
9
|
+
mcxlib/market_data.py
|
|
10
|
+
mcxlib.egg-info/PKG-INFO
|
|
11
|
+
mcxlib.egg-info/SOURCES.txt
|
|
12
|
+
mcxlib.egg-info/dependency_links.txt
|
|
13
|
+
mcxlib.egg-info/requires.txt
|
|
14
|
+
mcxlib.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mcxlib
|
mcxlib-0.1/setup.cfg
ADDED
mcxlib-0.1/setup.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import setuptools
|
|
2
|
+
|
|
3
|
+
with open("README.md", "r") as fh:
|
|
4
|
+
long_description = fh.read()
|
|
5
|
+
|
|
6
|
+
setuptools.setup(
|
|
7
|
+
name='mcxlib',
|
|
8
|
+
packages=setuptools.find_packages(),
|
|
9
|
+
version='0.1',
|
|
10
|
+
include_package_data=True,
|
|
11
|
+
description='python library to get MCX India data',
|
|
12
|
+
long_description=long_description,
|
|
13
|
+
long_description_content_type="text/markdown", author='RuchiTanmay',
|
|
14
|
+
author_email='ruchitanmay@gmail.com',
|
|
15
|
+
url='https://github.com/RuchiTanmay/mcxlib',
|
|
16
|
+
install_requires=['requests', 'pandas'],
|
|
17
|
+
keywords=['mcx', 'mcx india', 'python', 'mcx data', 'mcx history data', 'commodity', 'mcx python',
|
|
18
|
+
'mcx python library', 'mcx library'],
|
|
19
|
+
classifiers=[
|
|
20
|
+
'Intended Audience :: Developers',
|
|
21
|
+
'Natural Language :: English',
|
|
22
|
+
'Operating System :: OS Independent',
|
|
23
|
+
'Programming Language :: Python',
|
|
24
|
+
'Programming Language :: Python :: 3',
|
|
25
|
+
'Programming Language :: Python :: Implementation :: PyPy',
|
|
26
|
+
'Topic :: Software Development :: Libraries :: Python Modules'
|
|
27
|
+
],
|
|
28
|
+
)
|