-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMOFSLOPENAPI.py
More file actions
3107 lines (2393 loc) · 122 KB
/
MOFSLOPENAPI.py
File metadata and controls
3107 lines (2393 loc) · 122 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import requests
from requests import get
import json
import os
from datetime import datetime, timezone
import sys
import socket
import re, uuid
import hashlib
import platform
# import wmi
import geocoder
import websocket
# import requests
# import json
# import hashlib
# import re, uuid
# from requests import get
# import socket
from struct import *
# import sys
# import os
import time
# from datetime import datetime
import datetime as dt
from queue import Queue
from threading import Thread
# Constant
# Api-Version
version = "V.1.1.0"
# ErrorLogs
try:
os.mkdir('Logs')
except FileExistsError:
null = 0
try:
MainPath = os.getcwd()
os.chdir('Logs')
LogPath = os.getcwd()
os.chdir(MainPath)
except:
print('\nError in Assigning Path!!!')
sys.exit()
def WriteIntoLog(f_status, f_filename, f_message):
try:
dt = datetime.now()
x = dt.strftime("%Y-%m-%d %H:%M:%S")
logmessage = str(x) + (" ") + f_status + (" ") + f_filename + (" ") + f_message + "\n"
os.chdir(LogPath)
strdate = datetime.now()
Logfile = open(str(strdate.strftime("%d-%b-%Y")) + "_OpenApiLibrary(python).Log","a+")
os.chdir(MainPath)
Logfile.write(logmessage)
Logfile.close()
except:
print('\nError in Writing Logs!!!')
sys.exit()
def WriteIntoLog_Broadcast(f_status, f_filename, f_message):
try:
dt = datetime.now()
x = dt.strftime("%Y-%m-%d %H:%M:%S")
logmessage = str(x) + (" ") + f_status + (" ") + f_filename + (" ") + f_message + "\n"
os.chdir(LogPath)
strdate = datetime.now()
Logfile = open(str(strdate.strftime("%d-%b-%Y")) + "_OpenApiBroadcast(python).Log","a+")
os.chdir(MainPath)
Logfile.write(logmessage)
Logfile.close()
except:
print('\nError in Writing Logs!!!')
sys.exit()
def WriteIntoLog_TradeStatus(f_status, f_filename, f_message):
try:
dt = datetime.now()
x = dt.strftime("%Y-%m-%d %H:%M:%S")
logmessage = str(x) + (" ") + f_status + (" ") + f_filename + (" ") + f_message + "\n"
os.chdir(LogPath)
strdate = datetime.now()
Logfile = open(str(strdate.strftime("%d-%b-%Y")) + "_OpenApiTradeStatus(python).Log","a+")
os.chdir(MainPath)
Logfile.write(logmessage)
Logfile.close()
except:
print('\nError in Writing Logs!!!')
sys.exit()
# def WriteIntoLog(f_status, f_filename, f_message):
# try:
# os.mkdir("Logs")
# except FileExistsError:
# null = 0
# try:
# MainPath = os.getcwd()
# os.chdir('Logs')
# LogPath = os.getcwd()
# os.chdir(MainPath)
# except:
# print('\nError in Assigning Path!!!')
# sys.exit()
# try:
# dt = datetime.now()
# x = dt.strftime("%Y-%m-%d %H:%M:%S")
# logmessage = str(x) + (" ") + f_status + (" ") + f_filename + (" ") + f_message + "\n"
# os.chdir(LogPath)
# strdate = datetime.now()
# Logfile = open(str(strdate.strftime("%d-%b-%Y")) + "_OpenApiLibrary(python).Log","a+")
# os.chdir(MainPath)
# Logfile.write(logmessage)
# Logfile.close()
# except:
# print('\nError in Writing Logs!!!')
# sys.exit()
# UserInfo
def GetMacAddress():
try:
clientMacAddress=':'.join(re.findall('..', '%012x' % uuid.getnode()))
return clientMacAddress
except Exception as e:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", ("GetMacAddress" + str(e)))
print(e)
return "00:00:00:00:00:00"
def GetLocalIPAddress():
try:
hostname = socket.gethostname()
local_ip = socket.gethostbyname(hostname)
return local_ip
except Exception as e:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", ("GetLocalIPAddress" + str(e)))
print(e)
return "1.2.3.4"
def GetPublicIPAddress():
try:
public_ip = get('http://checkip.dyndns.org/').text
ipaddress=str(re.findall(r'[0-9]+(?:\.[0-9]+){3}',public_ip))
finalipppp=ipaddress.replace("'","")
finalipppp=finalipppp.replace("[","")
finalipppp=finalipppp.replace("]","")
if not finalipppp:
finalipppp = "1.2.3.4"
return finalipppp
except Exception as e:
print(e)
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", ("GetPublicIPAddress" + str(e)))
return "1.2.3.4"
# print(GetLocalIPAddress())
# print(GetPublicIPAddress())
# print(GetMacAddress())
# System Info
# c = wmi.WMI()
# objsystem = c.Win32_ComputerSystem()[0]
# system = platform.uname()
def GetOsName():
try:
# osname = system.system
osname = "Ubuntu 20.04.3 LTS"
return osname
except Exception as e:
print(e)
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", ("GetOsName" + str(e)))
# return "Win32NT"
def GetOsVersion():
try:
# osversion = system.version
osversion= "20.04"
return osversion
except Exception as e:
print(e)
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", ("GetOsVersion" + str(e)))
# return "10.0.19044.0"
def GetInstalledAppid():
try:
installedappid = uuid.uuid1()
return installedappid
except Exception as e:
print(e)
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", ("GetInstalledAppid" + str(e)))
# return "10.0.19044.0"
def GetDeviceModel():
try:
# devicemodel = objsystem.Model
devicemodel = "VMware Virtual Platform"
return devicemodel
except Exception as e:
print(e)
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", ("GetDeviceModel" + str(e)))
# return "VMware Virtual Platform"
def GetManufacturer():
try:
# manufacturer = objsystem.Manufacturer
manufacturer = "unknown"
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", ("GetManufacturer" +manufacturer) )
if manufacturer==None:
return "unknown"
elif len(manufacturer) > 25 or len(manufacturer) < 1:
return "unknown"
return manufacturer
except Exception as e:
print(e)
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", ("GetManufacturer" + str(e)))
return "unknown"
# return "Phoenix Technologies LTD"
def GetProductName():
try:
productname = "Investor"
return productname
except Exception as e:
print(e)
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", ("GetProductName" + str(e)))
# return "Investor"
def GetProductVersion():
try:
productversion = "1"
return productversion
except Exception as e:
print(e)
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", ("GetProductVersion" + str(e)))
# return "1"
def GetLatitudeLongitude():
try:
# ipaddress = geocoder.ip('me')
lst_latlng = [0,0]
# print(var[0],var[1] )
if lst_latlng == None:
lst_latlng = [19.0760, 72.8777]
return lst_latlng
except Exception as e:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", ("GetLongitudeLatitude" + str(e)))
ipaddress = geocoder.ip('106.193.137.95') #106.193.137.95
lst_latlng = ipaddress.latlng
# print(var[0],var[1] )
if lst_latlng == None:
lst_latlng = [19.0760, 72.8777]
return lst_latlng
class MOFSLOPENAPI(object):
m_strMOFSLToken=""
m_strClientPublicIP = ""
m_strClientLocalIP = ""
m_strMACAddress = ""
m_strSourceID = "" # Web,Desktop,Mobile
m_strApikey = ""
m_strApiSecretkey = ""
m_strUseragent = "MOSL/" + version
m_Base_Url = ""
m_vendorinfo = ""
m_clientcodeDealer = ""
m_osname = ""
m_osversion = ""
m_installedappid = ""
m_devicemodel = ""
m_manufacturer = ""
m_browsername = ""
m_browserversion = ""
m_imeino = "" #--- In 15digit in strings format eg= "987456321987654"
m_productname = ""
m_productversion = ""
m_latitudelongitude = ""
m_MaxBroadcastLimit = 0 # self.getbroadcastmaxlimit(self.m_clientcodeDealer)
m_scriptask = ""
m_TCPscriptask = ""
m_indextask = ""
m_TCPindextask = ""
l_scrip_code = []
l_TCPscrip_code = []
l_exchange_index = []
l_TCPexchange_index = []
m_clientcode = ""
Websocket_version = "VER 2.0"
q_msg = Queue()
ws1 = None
ws2 = None
# TCPSocket
s = None
AttemptCountSocket = 1
m_responsepacketlength = 30
m_TCPresponsepacketlength = 30
TradeStatusHeartbeat_flag = True
BroadcastAutoRelogin_flag = True
TCPBroadcastAutoRelogin_flag = True
Broadcast_Logout_flag = True
TCPBroadcast_Logout_flag = True
BroadcastAutoRelogin_counter = 1
TCPBroadcastAutoRelogin_counter = 1
m_LastMsgTime = 0
def __init__(self, f_apikey, f_Base_Url, f_clientcode, f_strSourceID, f_browsername, f_browserversion):
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "Initilize Constructor")
self.m_strApikey = f_apikey
self.m_strMACAddress = GetMacAddress()
self.m_strClientLocalIP = GetLocalIPAddress()
self.m_strClientPublicIP = GetPublicIPAddress()
self.m_strSourceID = f_strSourceID
self.m_strApiSecretkey = self.m_strApiSecretkey
self.m_Base_Url = f_Base_Url
self.m_clientcodeDealer = f_clientcode
self.m_osname = GetOsName()
self.m_osversion = GetOsVersion()
self.m_installedappid = str(GetInstalledAppid())
self.m_devicemodel = GetDeviceModel()
self.m_manufacturer = GetManufacturer()
self.m_productname = GetProductName()
self.m_productversion = GetProductVersion()
self.m_browsername = f_browsername
self.m_browserversion = f_browserversion
self.m_latitudelongitude = GetLatitudeLongitude()
# self.Websocket_URL = self.Websocket_URL
# self.l_scrip_code = []
# self.l_exchange_index = []
self.Websocket_version = self.Websocket_version
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "Initilize Constructor Done")
def GetUrl(self, f_ApiPath):
base_Url= self.m_Base_Url
# ver = "/rest/v1"
try:
if f_ApiPath =="Login":
# Login URL
Login_ApiPath = "/rest/login/v4/authdirectapi"
URL = (str(base_Url)+str(Login_ApiPath))
elif f_ApiPath =="Logout":
# Logout URL
Logout_ApiPath = "/rest/login/v1/logout"
URL = (str(base_Url)+str(Logout_ApiPath))
elif f_ApiPath =="GetProfile":
# GetProfile URL
GetProfile_ApiPath = "/rest/login/v1/getprofile"
URL = (str(base_Url)+str(GetProfile_ApiPath))
elif f_ApiPath =="OrderBook":
# OrderBook URL
OrderBook_ApiPath = "/rest/book/v1/getorderbook"
URL = (str(base_Url)+str(OrderBook_ApiPath))
elif f_ApiPath =="TradeBook":
# TradeBook URL
TradeBook_ApiPath = "/rest/book/v1/gettradebook"
URL = (str(base_Url)+str(TradeBook_ApiPath))
elif f_ApiPath =="GetPosition":
# GetPosition URL
GetPosition_ApiPath = "/rest/book/v1/getposition"
URL = (str(base_Url)+str(GetPosition_ApiPath))
elif f_ApiPath =="DPHolding":
# TradeBook URL
DPHolding_ApiPath = "/rest/report/v1/getdpholding"
URL = (str(base_Url)+str(DPHolding_ApiPath))
elif f_ApiPath =="PlaceOrder":
# PlaceOrder URL
PlaceOrder_ApiPath = "/rest/trans/v1/placeorder"
URL = (str(base_Url)+str(PlaceOrder_ApiPath))
elif f_ApiPath =="ModifyOrder":
# ModifyOrder URL
ModifyOrder_ApiPath = "/rest/trans/v2/modifyorder"
URL = (str(base_Url)+str(ModifyOrder_ApiPath))
elif f_ApiPath =="CancelOrder":
# CancelOrder URL
CancelOrder_ApiPath = "/rest/trans/v1/cancelorder"
URL = (str(base_Url)+str(CancelOrder_ApiPath))
elif f_ApiPath =="positionconversion":
# positionconversion URL
positionconversion_ApiPath = "/rest/trans/v1/positionconversion"
URL = (str(base_Url)+str(positionconversion_ApiPath))
elif f_ApiPath =="marginreport":
# MarginReport URL
marginreport_ApiPath = "/rest/report/v1/getreportmargin"
URL = (str(base_Url)+str(marginreport_ApiPath))
elif f_ApiPath =="marginsummary":
# MarginSummary URL
marginsummary_ApiPath = "/rest/report/v1/getreportmarginsummary"
URL = (str(base_Url)+str(marginsummary_ApiPath))
elif f_ApiPath =="margindetail":
# MarginDetail URL
margindetail_ApiPath = "/rest/report/v1/getreportmargindetail"
URL = (str(base_Url)+str(margindetail_ApiPath))
elif f_ApiPath =="ltadata":
# LTA Data URL
ltadata_ApiPath = "/rest/report/v1/getltpdata"
URL = (str(base_Url)+str(ltadata_ApiPath))
elif f_ApiPath =="exchangedata":
# EXCHANGE DATA URL
exchangedata_ApiPath = "/rest/report/v1/getscripsbyexchangename"
URL = (str(base_Url)+str(exchangedata_ApiPath))
elif f_ApiPath =="getorderdetailbyunqueorderid":
# Getorderdetailbyunqueorderid
getorderdetailbyunqueorderid_Apipath = "/rest/book/v1/getorderdetailbyuniqueorderid"
URL = (str(base_Url)+str(getorderdetailbyunqueorderid_Apipath))
elif f_ApiPath =="getbrokeragedetail":
# getbrokeragedetail
getbrokeragedetail_Apipath = "/rest/report/v1/getbrokeragedetail"
URL = (str(base_Url)+str(getbrokeragedetail_Apipath))
elif f_ApiPath =="getbroadcastmaxlimit":
# getbroadcastmaxlimit
getbroadcastmaxlimit_Apipath = "/rest/report/v1/getbroadcastmaxlimit"
URL = (str(base_Url)+str(getbroadcastmaxlimit_Apipath))
elif f_ApiPath =="resendotp":
# resendotp
resendotp_Apipath = "/rest/login/v3/resendotp"
URL = (str(base_Url)+str(resendotp_Apipath))
elif f_ApiPath =="verifyotp":
# verifyotp
verifyotp_Apipath = "/rest/login/v3/verifyotp"
URL = (str(base_Url)+str(verifyotp_Apipath))
else:
print("Error in GetURL")
return URL
except Exception as e:
print(e)
def validate(self, f_URL, f_Data):
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "Initilize Post WebRequest Sent")
try:
m_headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization" : self.m_strMOFSLToken,
"User-Agent" : self.m_strUseragent,
"apikey": self.m_strApikey,
"apisecretkey" : self.m_strApiSecretkey,
"macaddress": self.m_strMACAddress,
"clientlocalip": self.m_strClientLocalIP,
"sourceid": self.m_strSourceID,
"clientpublicip": self.m_strClientPublicIP,
"vendorinfo": self.m_vendorinfo,
"osname": self.m_osname,
"osversion" : self.m_osversion,
"installedappid": self.m_installedappid,
"devicemodel": self.m_devicemodel,
"manufacturer": self.m_manufacturer,
"productname": self.m_productname,
"productversion": self.m_productversion,
"latitude": str("%.4f" % self.m_latitudelongitude[0]),
"longitude": str("%.4f" % self.m_latitudelongitude[1]),
"sdkversion":"Python 3.0"
# "browsername": self.m_browsername,
# "browserversion": self.m_browserversion,
# "imeino": self.m_imeino
}
if self.m_strSourceID.upper() == "WEB":
m_headers["browsername"] = self.m_browsername
m_headers["browserversion"] = self.m_browserversion
# print(m_headers)
response = requests.post(f_URL, headers= m_headers, data = json.dumps(f_Data))
# print("JSON Response ", response.content)
j_ResponseMessage = response.content.decode('utf-8')
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "Post WebRequest Send Successfully")
return j_ResponseMessage
except Exception as e:
l_boolisconnect = MOFSLOPENAPI.checkinternet(self)
if l_boolisconnect == False:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", "Network connection is unavailable")
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", str(e))
return ("POST ERROR " + str(e))
def checkinternet(self):
url = "https://www.google.co.in"
timeout = 3
try:
# requesting URL
request = requests.get(url, timeout=timeout)
return True
# catching exception
except (requests.ConnectionError, requests.Timeout) as exception:
return False
# resendotp API
def resendotp(self):
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "Initilaize resendotp request send")
l_resendotpResponse = {}
try:
l_strApiUrl = MOFSLOPENAPI.GetUrl(self, "resendotp")
l_strGetdata = {
"clientcode" : ""
}
l_strJSON = MOFSLOPENAPI.validate(self, l_strApiUrl, l_strGetdata)
if "GET ERROR " not in l_strJSON:
l_strDICT = json.loads(l_strJSON)
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "resendotp request sent Successfully")
l_resendotpResponse = l_strDICT
else:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", l_strJSON.replace("GET ERROR ", ""))
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", "resendotp Request failed")
l_resendotpResponse["status"] = "FAILED"
l_resendotpResponse["message"] = l_strJSON.replace("GET ERROR ", "")
l_resendotpResponse["errorcode"] = ""
l_resendotpResponse["data"] = {"null"}
except Exception as e:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", str(e))
l_resendotpResponse["status"] = "FAILED"
l_resendotpResponse["message"] = str(e)
l_resendotpResponse["errorcode"] = ""
l_resendotpResponse["data"] = {"null"}
return l_resendotpResponse
# verifyotp API
def verifyotp(self, f_otp):
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "Initilaize verifyotp request send")
l_verifyotpResponse = {}
try:
l_strApiUrl = MOFSLOPENAPI.GetUrl(self, "verifyotp")
l_strGetdata = {
"otp": f_otp
}
l_strJSON = MOFSLOPENAPI.validate(self, l_strApiUrl, l_strGetdata)
if "GET ERROR " not in l_strJSON:
l_strDICT = json.loads(l_strJSON)
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "verifyotp request sent Successfully")
l_verifyotpResponse = l_strDICT
else:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", l_strJSON.replace("GET ERROR ", ""))
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", "verifyotp Request failed")
l_verifyotpResponse["status"] = "FAILED"
l_verifyotpResponse["message"] = l_strJSON.replace("GET ERROR ", "")
l_verifyotpResponse["errorcode"] = ""
l_verifyotpResponse["data"] = {"null"}
except Exception as e:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", str(e))
l_verifyotpResponse["status"] = "FAILED"
l_verifyotpResponse["message"] = str(e)
l_verifyotpResponse["errorcode"] = ""
l_verifyotpResponse["data"] = {"null"}
return l_verifyotpResponse
# login function with username and password
def login(self, f_clientID, f_password, f_twoFA, f_totp = None ,f_vendorinfo = None):
l_loginResponse = {}
try:
if f_clientID == "" or f_password == "":
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", "login_Client_id or Password is empty")
else:
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "Initilize login request send")
self.m_vendorinfo = f_vendorinfo
self.m_clientcode = f_clientID
f_strallcombine = f_password + self.m_strApikey
h = hashlib.sha256(f_strallcombine.encode("utf-8"))
checksum = h.hexdigest()
# print(checksum, type(checksum))
l_PostData = {
"userid": f_clientID,
"password": checksum,
"2FA": f_twoFA ,
"totp": f_totp
}
l_URL = MOFSLOPENAPI.GetUrl(self, "Login")
l_strJSON = MOFSLOPENAPI.validate(self ,l_URL, l_PostData)
if "POST ERROR " not in l_strJSON:
l_strDICT = json.loads(l_strJSON)
if l_strDICT["status"] == "SUCCESS" :
self.m_strMOFSLToken = l_strDICT["AuthToken"]
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "Login sucessfully")
else:
WriteIntoLog(l_strDICT["status"], "MOFSLOPENAPI.py", l_strDICT["message"])
l_loginResponse = l_strDICT
else :
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", "login_Error while sending the webRequest")
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", "Login Request failed")
l_loginResponse["status"] = "FAILED"
l_loginResponse["message"] = l_strJSON.replace("POST ERROR ", "")
l_loginResponse["errorcode"] = ""
l_loginResponse["AuthToken"] = ""
except Exception as e:
l_loginResponse["status"] = "FAILED"
l_loginResponse["message"] = str(e)
l_loginResponse["errorcode"] = ""
l_loginResponse["AuthToken"] = ""
return l_loginResponse
def logout(self, f_strclientcode = None):
l_logoutResponse = {}
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "Initilize Logout Request")
l_URL = MOFSLOPENAPI.GetUrl(self, "Logout")
l_PostData = {
"userid": f_strclientcode
}
try:
l_strJSON = MOFSLOPENAPI.validate(self, l_URL, l_PostData)
if "POST ERROR " not in l_strJSON:
l_strDICT = json.loads(l_strJSON)
if l_strDICT["status"] == "SUCCESS" :
self.m_strMOFSLToken = ""
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "Logout sucessfully")
else:
WriteIntoLog(l_strDICT["status"], "MOFSLOPENAPI.py", l_strDICT["message"])
l_logoutResponse = l_strDICT
else:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", "logout_Error while sending the webRequest")
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", "Logout Request failed")
l_logoutResponse["status"] = "FAILED"
l_logoutResponse["message"] = l_strJSON.replace("POST ERROR ", "")
l_logoutResponse["errorcode"] = ""
except Exception as e :
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", str(e))
l_logoutResponse["status"] = "FAILED"
l_logoutResponse["message"] = str(e)
l_logoutResponse["errorcode"] = ""
return l_logoutResponse
def GetProfile(self, f_strclientcode = None):
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "Initilaize GetProfile request send")
l_GetProfileResponse = {}
try:
l_strApiUrl = MOFSLOPENAPI.GetUrl(self, "GetProfile")
l_strGetdata = {
"clientcode": f_strclientcode
}
l_strJSON = MOFSLOPENAPI.validate(self, l_strApiUrl, l_strGetdata)
if "GET ERROR " not in l_strJSON:
l_strDICT = json.loads(l_strJSON)
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "GetProfile request sent Successfully")
l_GetProfileResponse = l_strDICT
else:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", l_strJSON.replace("GET ERROR ", ""))
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", "GetProfile Request failed")
l_GetProfileResponse["status"] = "FAILED"
l_GetProfileResponse["message"] = l_strJSON.replace("GET ERROR ", "")
l_GetProfileResponse["errorcode"] = ""
l_GetProfileResponse["data"] = {"null"}
except Exception as e:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", str(e))
l_GetProfileResponse["status"] = "FAILED"
l_GetProfileResponse["message"] = str(e)
l_GetProfileResponse["errorcode"] = ""
l_GetProfileResponse["data"] = {"null"}
return l_GetProfileResponse
def GetOrderBook(self, f_OrderBookInfo):
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "Initilaize GetOrderBook request send")
l_OrderBookResponse = {}
try:
l_strApiUrl = MOFSLOPENAPI.GetUrl(self, "OrderBook")
l_strGetdata = f_OrderBookInfo
l_strJSON = MOFSLOPENAPI.validate(self, l_strApiUrl, l_strGetdata)
if "GET ERROR " not in l_strJSON:
l_strDICT = json.loads(l_strJSON)
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "GetOrderBook request sent Successfully")
l_OrderBookResponse = l_strDICT
else:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", l_strJSON.replace("GET ERROR ", ""))
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", "GetOrderBook Request failed")
l_OrderBookResponse["status"] = "FAILED"
l_OrderBookResponse["message"] = l_strJSON.replace("GET ERROR ", "")
l_OrderBookResponse["errorcode"] = ""
l_OrderBookResponse["data"] = {"null"}
except Exception as e:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", str(e))
l_OrderBookResponse["status"] = "FAILED"
l_OrderBookResponse["message"] = str(e)
l_OrderBookResponse["errorcode"] = ""
l_OrderBookResponse["data"] = {"null"}
return l_OrderBookResponse
def GetTradeBook(self, f_strclientcode = None):
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "Initilaize GetTradeBook request send")
l_TradeBookResponse = {}
try:
l_strApiUrl = MOFSLOPENAPI.GetUrl(self, "TradeBook")
l_strGetdata = {
"clientcode": f_strclientcode
}
l_strJSON = MOFSLOPENAPI.validate(self, l_strApiUrl, l_strGetdata)
if "GET ERROR " not in l_strJSON:
l_strDICT = json.loads(l_strJSON)
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "GetTradeBook request sent Successfully")
l_TradeBookResponse = l_strDICT
else:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", l_strJSON.replace("GET ERROR ", ""))
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", "GetTradeBook Request failed")
l_TradeBookResponse["status"] = "FAILED"
l_TradeBookResponse["message"] = l_strJSON.replace("GET ERROR ", "")
l_TradeBookResponse["errorcode"] = ""
l_TradeBookResponse["data"] = {"null"}
except Exception as e:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", str(e))
l_TradeBookResponse["status"] = "FAILED"
l_TradeBookResponse["message"] = str(e)
l_TradeBookResponse["errorcode"] = ""
l_TradeBookResponse["data"] = {"null"}
return l_TradeBookResponse
def GetPosition(self, f_strclientcode = None):
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "Initilaize GetPosition request send")
l_GetPositionResponse = {}
try:
l_strApiUrl = MOFSLOPENAPI.GetUrl(self, "GetPosition")
l_strGetdata = {
"clientcode": f_strclientcode
}
l_strJSON = MOFSLOPENAPI.validate(self, l_strApiUrl, l_strGetdata)
if "GET ERROR " not in l_strJSON:
l_strDICT = json.loads(l_strJSON)
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "GetPosition request sent Successfully")
l_GetPositionResponse = l_strDICT
else:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", l_strJSON.replace("GET ERROR ", ""))
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", "GetPosition Request failed")
l_GetPositionResponse["status"] = "FAILED"
l_GetPositionResponse["message"] = l_strJSON.replace("GET ERROR ", "")
l_GetPositionResponse["errorcode"] = ""
l_GetPositionResponse["data"] = {"null"}
except Exception as e:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", str(e))
l_GetPositionResponse["status"] = "FAILED"
l_GetPositionResponse["message"] = str(e)
l_GetPositionResponse["errorcode"] = ""
l_GetPositionResponse["data"] = {"null"}
return l_GetPositionResponse
def GetDPHolding(self, f_strclientcode = None):
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "Initilaize GetDPHolding request send")
l_DPHoldingResponse = {}
try:
l_strApiUrl = MOFSLOPENAPI.GetUrl(self, "DPHolding")
l_strGetdata = {
"clientcode": f_strclientcode
}
l_strJSON = MOFSLOPENAPI.validate(self, l_strApiUrl, l_strGetdata)
if "GET ERROR " not in l_strJSON:
l_strDICT = json.loads(l_strJSON)
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "GetDPHolding request sent Successfully")
l_DPHoldingResponse = l_strDICT
else:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", l_strJSON.replace("GET ERROR ", ""))
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", "GetDPHolding Request failed")
l_DPHoldingResponse["status"] = "FAILED"
l_DPHoldingResponse["message"] = l_strJSON.replace("GET ERROR ", "")
l_DPHoldingResponse["errorcode"] = ""
l_DPHoldingResponse["data"] = {"null"}
except Exception as e:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", str(e))
l_DPHoldingResponse["status"] = "FAILED"
l_DPHoldingResponse["message"] = str(e)
l_DPHoldingResponse["errorcode"] = ""
l_DPHoldingResponse["data"] = {"null"}
return l_DPHoldingResponse
def PlaceOrder(self, f_PlaceOrderInfo):
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "Initilaize PlaceOrder request send")
l_PlaceOrderResponse = {}
try:
l_strApiUrl = MOFSLOPENAPI.GetUrl(self, "PlaceOrder")
l_strGetdata = f_PlaceOrderInfo
l_strJSON = MOFSLOPENAPI.validate(self, l_strApiUrl, l_strGetdata)
if "GET ERROR " not in l_strJSON:
l_strDICT = json.loads(l_strJSON)
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "PlaceOrder request sent Successfully")
l_PlaceOrderResponse = l_strDICT
else:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", l_strJSON.replace("GET ERROR ", ""))
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", "PlaceOrder Request failed")
l_PlaceOrderResponse["status"] = "FAILED"
l_PlaceOrderResponse["message"] = l_strJSON.replace("GET ERROR ", "")
l_PlaceOrderResponse["errorcode"] = ""
l_PlaceOrderResponse["uniqueorderid"] = ""
except Exception as e:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", str(e))
l_PlaceOrderResponse["status"] = "FAILED"
l_PlaceOrderResponse["message"] = str(e)
l_PlaceOrderResponse["errorcode"] = ""
l_PlaceOrderResponse["uniqueorderid"] = ""
return l_PlaceOrderResponse
def ModifyOrder(self, f_ModifyOrderInfo):
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "Initilaize ModifyOrder request send")
l_ModifyOrderResponse = {}
try:
l_strApiUrl = MOFSLOPENAPI.GetUrl(self, "ModifyOrder")
l_strGetdata = f_ModifyOrderInfo
l_strJSON = MOFSLOPENAPI.validate(self, l_strApiUrl, l_strGetdata)
if "GET ERROR " not in l_strJSON:
l_strDICT = json.loads(l_strJSON)
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "ModifyOrder request sent Successfully")
l_ModifyOrderResponse = l_strDICT
else:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", l_strJSON.replace("GET ERROR ", ""))
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", "ModifyOrder Request failed")
l_ModifyOrderResponse["status"] = "FAILED"
l_ModifyOrderResponse["message"] = l_strJSON.replace("GET ERROR ", "")
l_ModifyOrderResponse["errorcode"] = ""
except Exception as e:
WriteIntoLog("FAILED", "MOFSLOPENAPI.py", str(e))
l_ModifyOrderResponse["status"] = "FAILED"
l_ModifyOrderResponse["message"] = str(e)
l_ModifyOrderResponse["errorcode"] = ""
return l_ModifyOrderResponse
def CancelOrder(self, f_orderid, f_clientcode = None):
WriteIntoLog("SUCCESS", "MOFSLOPENAPI.py", "Initilaize CancelOrder request send")
l_CancelOrderResponse = {}
try:
l_strApiUrl = MOFSLOPENAPI.GetUrl(self, "CancelOrder")