-
Notifications
You must be signed in to change notification settings - Fork 1
/
KFC_Nobitex_Robot_Real10.6.py
1420 lines (1239 loc) · 47 KB
/
KFC_Nobitex_Robot_Real10.6.py
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
EndPoint="api.nobitex.ir"
#EndPoint="testnetapi.nobitex.ir"
def tick():
global TradeAllowed
global order_price
if(dst.get().lower()=="usdt"):
symb1=src.get()+"USDT"
else:
symb1=src.get()+"IRT"
window.title(str(Username)+" : "+unixstamp2date(int(time.time()))+' - KFC Nobitex Robot 10.6')
###################################################
global layer
global Lastid
ka=0.1
kb=0.2
kc=0.2
p=get_lastprice2(symb1.upper())#change all to uppercase to avoid error
try:
r2=VR2.get()
r1=VR1.get()
s1=VS1.get()
s2=VS2.get()
r3r2=VR3.get()-VR2.get()
r2r1=VR2.get()-VR1.get()
r1s1=VR1.get()-VS1.get()
s1s2=VS1.get()-VS2.get()
s2s3=VS2.get()-VS3.get()
except Exception as e:
messagebox.showerror(
title='set values',
message="Something is wrong\n"+e.__class__.__name__+": "+str(e)+"\n" #e is a class so used str
)
VR2.set(0)
VR1.set(0)
VS1.set(0)
VS2.set(0)
VR3.set(0)
VS3.set(0)
r2=VR2.get()
r1=VR1.get()
s1=VS1.get()
s2=VS2.get()
r3r2=VR3.get()-VR2.get()
r2r1=VR2.get()-VR1.get()
r1s1=VR1.get()-VS1.get()
s1s2=VS1.get()-VS2.get()
s2s3=VS2.get()-VS3.get()
######################
#open buy scenarios
######################
if(layer=="None" and p>s2+ka*s1s2 and p<s2+kb*s1s2 and TradeAllowed):
order_price=str(p)
print("-------------------------------------------------")
print("Condition : buy at S2",order_price," , ",s2+ka*s1s2," , ",s2+kb*s1s2)
res=RunBuy()
while(True):
ss=get_order_status(Lastid)
if(ss=="Done"):
layer="S2"
print("buy opened at S2 : Done")
get_order_detail(Lastid)
print("-------------------------------------------------")
break
if(ss=="Failed"):
print("buy opened at S2 : Failed")
print("-------------------------------------------------")
break
if(ss=="Canceled"):
layer="None"
print("buy at S2 : Canceled")
print("-------------------------------------------------")
break
if(layer=="None" and p>s1+ka*r1s1 and p<s1+kb*r1s1 and TradeAllowed):
order_price=str(p)
print("-------------------------------------------------")
print("Condition : buy at S1",order_price," , ",s1+ka*r1s1," , ",s1+kb*r1s1)
res=RunBuy()
while(True):
ss=get_order_status(Lastid)
if(ss=="Done"):
layer="S1"
print("buy opened at S1 : Done")
get_order_detail(Lastid)
print("-------------------------------------------------")
break
if(ss=="Failed"):
print("buy opened at S1 : Failed")
print("-------------------------------------------------")
break
if(ss=="Canceled"):
layer="None"
print("buy at S1 : Canceled")
print("-------------------------------------------------")
break
if(layer=="None" and p>r2+ka*r3r2 and p<r2+kb*r3r2 and TradeAllowed):
order_price=str(p)
print("-------------------------------------------------")
print("Condition : buy at R2",order_price," , ",r2+ka*r3r2," , ",r2+kb*r3r2)
res=RunBuy()
while(True):
ss=get_order_status(Lastid)
if(ss=="Done"):
layer="R2"
print("buy opened at R2 : Done")
get_order_detail(Lastid)
print("-------------------------------------------------")
break
if(ss=="Failed"):
print("buy opened at R2 : Failed")
print("-------------------------------------------------")
break
if(ss=="Canceled"):
layer="None"
print("buy at R2 : Canceled")
print("-------------------------------------------------")
break
if(layer=="None" and p>r1+ka*r2r1 and p<r1+kb*r2r1 and TradeAllowed):
order_price=str(p)
print("-------------------------------------------------")
print("Condition : buy at R1",order_price," , ",r1+ka*r2r1," , ",r1+kb*r2r1)
res=RunBuy()
while(True):
ss=get_order_status(Lastid)
if(ss=="Done"):
layer="R1"
print("buy opened at R1 : Done")
get_order_detail(Lastid)
print("-------------------------------------------------")
break
if(ss=="Failed"):
print("buy opened at R1 : Failed")
print("-------------------------------------------------")
break
if(ss=="Canceled"):
layer="None"
print("buy at R1 : Canceled")
print("-------------------------------------------------")
break
######################
#sell scenarios(after buy)
######################
if(layer=="S2" and (p>s1-kc*s1s2 or p<s2-kc*s2s3) and TradeAllowed):
order_price=str(p)
print("-------------------------------------------------")
print("Condition : sell at S2",order_price," , ",s1-kc*s1s2," , ",s2-kc*s2s3)
res=RunSell()
while(True):
ss=get_order_status(Lastid)
if(ss=="Done"):
layer="None"
print("sell at S2 : Done")
get_order_detail(Lastid)
print("-------------------------------------------------")
break
if(ss=="Failed"):
print("sell at S2 : Failed")
print("-------------------------------------------------")
break
if(ss=="Canceled"):
layer="None"
print("sell at S2 : Canceled")
print("-------------------------------------------------")
break
if(layer=="S1" and (p>r1-kc*r1s1 or p<s1-kc*s1s2) and TradeAllowed):
order_price=str(p)
print("-------------------------------------------------")
print("Condition : sell at S1",order_price," , ",r1-kc*r1s1," , ",s1-kc*s1s2)
res=RunSell()
while(True):
ss=get_order_status(Lastid)
if(ss=="Done"):
layer="None"
print("sell at S1 : Done")
get_order_detail(Lastid)
print("-------------------------------------------------")
break
if(ss=="Failed"):
print("sell at S1 : Failed")
print("-------------------------------------------------")
break
if(ss=="Canceled"):
layer="None"
print("sell at S1 : Canceled")
print("-------------------------------------------------")
break
if(layer=="R2" and (p>r3-kc*r3r2 or p<r2-kc*r2r1) and TradeAllowed):
order_price=str(p)
print("-------------------------------------------------")
print("Condition : sell at R2",order_price," , ",r3-kc*r3r2," , ",p<r2-kc*r2r1)
res=RunSell()
while(True):
ss=get_order_status(Lastid)
if(ss=="Done"):
layer="None"
print("sell at R2 : Done")
get_order_detail(Lastid)
print("-------------------------------------------------")
break
if(ss=="Failed"):
print("sell at R2 : Failed")
print("-------------------------------------------------")
break
if(ss=="Canceled"):
layer="None"
print("sell at R2 : Canceled")
print("-------------------------------------------------")
break
if(layer=="R1" and (p>r2-kc*r2r1 or p<r1-kc*r1s1) and TradeAllowed):
order_price=str(p)
print("-------------------------------------------------")
print("Condition : sell at R1",order_price," , ",r2-kc*r2r1," , ",r1-kc*r1s1)
res=RunSell()
while(True):
ss=get_order_status(Lastid)
if(ss=="Done"):
layer="None"
print("sell at R1 : Done")
get_order_detail(Lastid)
print("-------------------------------------------------")
break
if(ss=="Failed"):
print("sell at R1 : Failed")
print("-------------------------------------------------")
break
if(ss=="Canceled"):
layer="None"
print("sell at R1 : Canceled")
print("-------------------------------------------------")
break
## ########################################################
## #check order status for next action
## if(Lastid !="None" and get_order_status(Lastid)=="Done"):
## TradeAllowed=False
## else:
## TradeAllowed=True
## ########################################################
time_string = "Price : "+str(p).ljust(12, ' ')+" Traded Level : "+layer#+"\n"+str(ss2).ljust(20, ' ')
clock.config(text=time_string)
clock.after(15000, tick)
def RunBuy():
global TradeAllowed
if(TradeAllowed):
print("Try to buy at best market price")
global myToken
global Lastid
Lastid="None"
if(float(entry_Vamount.get()) <=0):
messagebox.showerror(
title='Buy status',
message="Enter amount Correctly"
)
am=eg.enterbox(msg="Enter amount")
if(am != None):
Vamount.set(am)
return("Failed")
try:
a=Buy_Market(src.get(),dst.get(),entry_Vamount.get(),order_price,"",myToken,EndPoint)
idu=str(a["order"]["id"])
stat=str(a["order"]["status"])
print("id=",idu)
Lastid=idu
#rr=get_order_status(idu)
return(stat)
except Exception as e:
messagebox.showerror(
title='Buy status',
message="Something is wrong\n"+e.__class__.__name__+": "+str(e)+"\n"+a["message"] #e is a class so used str
)
return("Failed")
def RunSell():
global TradeAllowed
if(TradeAllowed):
print("Try to sell at best market price")
global myToken
global Lastid
Lastid="None"
if(float(entry_Vamount.get()) <=0):
messagebox.showerror(
title='Buy status',
message="Enter amount Correctly"
)
am=eg.enterbox(msg="Enter amount")
if(am != None):
Vamount.set(am)
return("Failed")
try:
a=Sell_Market(src.get(),dst.get(),entry_Vamount.get(),order_price,"",myToken,EndPoint)
idu=str(a["order"]["id"])
stat=str(a["order"]["status"])
print("id=",idu)
Lastid=idu
#rr=get_order_status(idu)
return(stat)
except Exception as e:
messagebox.showerror(
title='Sell status',
message="Something is wrong\n"+e.__class__.__name__+": "+str(e) #e is a class so used str
)
return("Failed")
def show_dic(dic):
try:
msg=""
for key in dic.keys():
if(not(type(dic[key]) is dict)):
msg=msg+key + ": "+str(dic[key])+"\n"
#print(type(a[key]))
else:
#print(dic[key])
#pish=pish+" "
msg=msg+key + ": "+show_dic(dic[key])#+"\n"#msg+key + ": "+"DICT"+"\n"
return(msg)
except Exception as e:
print("error in show_dic()"+e.__class__.__name__+": "+str(e)) #e is a class so used str")
def GetToken():
#import easygui as eg
global myToken #to define global variable from inside of a function
global Username
unpw = eg.enterbox(msg="Enter Username,Password")
tfa = eg.enterbox(msg="Enter Two Factor Authentication Code")
if(unpw==None or tfa==None):
#os._exit(0)
messagebox.showerror(
title='Get Token',
message="to get token you should :\n1-enter username and password\n2-Enter Two Factor Authentication Code"
)
return(0)
try:
un=unpw.split(",")[0]
pw=unpw.split(",")[1]
tok=get_token(un,pw,tfa)
myToken=tok
Username=get_username(get_user_profile(myToken)).split("@")[0]
print(Username," Token : ",myToken)
showinfo(
title='Get Token',
message="Token : "+tok
)
return(tok)
#print(un,"__",pw)
except Exception as e:
showerror(
title='Get Token',
message="Something is wrong\n"+e.__class__.__name__+": "+str(e) #e is a class so used str
)
return(0)
def ExecuteCommand():
showinfo(
title='Result Message',
message=selected_size.get()
)
def get_lastprice2(sym_name):
#change sym_name to uppercase beforehand to avoid error
try:
#last sym_name price
import http.client
#import pandas as pd
import json
conn = http.client.HTTPSConnection(EndPoint)
payload = ''
headers = {}
tf="180" #180 minites =H3 time frame
tto=int(get_current_unixstamp())
tfrom=tto-1000000
cmd="/market/udf/history?symbol=" + sym_name+"&resolution="+tf+"&from="+str(tfrom)+ "&to="+str(tto)
conn.request("GET", cmd, payload, headers)
res = conn.getresponse()
data = res.read()
#print(data.decode("utf-8"))
#df = pd.read_json(data.decode("utf-8"))
#print(df)
prices=json.loads(data.decode("utf-8"))
return(prices["c"][-1]) #close prices "c" is a list we return last price [-1]
except:
return(0)
def get_lastprice_orderbook(sym_name):
#sym_name="BTCIRT" ,"ETCIRT",...
import http.client
import json
conn = http.client.HTTPSConnection(EndPoint)
payload = ''
headers = {}
cmd="/v2/orderbook/"+sym_name
conn.request("GET", cmd, payload, headers)
res = conn.getresponse()
data = res.read()
w=data.decode("utf-8")
#print(w)
#string to dictionary
dc = json.loads(w)
#get dictioaru items (last price)
lastp=float(dc['lastTradePrice'])
#print("Last price:",lastp)
return(lastp)
def append2file(filename,itemsList):
#append elements of a list with comma delimiter to a file
#note that
import csv
with open(filename, mode='a',newline='') as out_file:
f1 = csv.writer(out_file, delimiter=',')
f1.writerow(itemsList)
def get_dir_tree_files(mypath):
#return list of full address of all files inside and under subdirectories in the path
import os
# Get the list of all files in directory tree at given path
listOfFiles = list()
for (dirpath, dirnames, filenames) in os.walk(mypath):
listOfFiles += [os.path.join(dirpath, file) for file in filenames]
return(listOfFiles)
def create_folder(mypath,folderName):
import os
try:
# Create target Directory
outdirName=os.path.join(mypath,folderName)
os.mkdir(outdirName)
print("Directory " , outdirName , " Created ")
except FileExistsError:
print("Directory " , outdirName , " already exists")
def readAccountsPath(filename):
#return account pathes as a list from given file with one column format "account path"
cnt=0
f = open(filename, "r")
mylist=[]
while True:
strlist=f.readline().split(",")
if(strlist != [""]):
accpath=strlist[0].split("\n")[0]
mylist.append(accpath)
cnt=cnt+1
else:
break
f.close()
return(mylist)
def get_current_unixstamp():
import time
ts = time.time()
return(ts)
def unixstamp2date(ts):
import datetime
dt=datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
return(dt)
def unixstamp2date2(timeint):
import datetime
dt=datetime.datetime.fromtimestamp(timeint / 1e3).strftime('%Y-%m-%d %H:%M:%S')
return(dt)
##get_market_trades("BTCIRT")
##get_market_trades("ETCIRT")
def get_market_stats(src1,dst1):
import requests
import json
print("Market stats :", src1,"-", dst1)
url = "https://"+EndPoint+"/market/stats"
payload={'srcCurrency': src1,
'dstCurrency': dst1}
files=[
]
headers = {}
try:
response = requests.request("POST", url, headers=headers, data=payload, files=files)
mkt=json.loads(response.text)
return(mkt)
except Exception as e:
messagebox.showerror(
title='Get Market Stats',
message="Error :\n"+e.__class__.__name__+": "+str(e) #e is a class so used str
)
return(0)
def show_market_stats():
try:
ww5=get_market_stats(src.get(),dst.get())
print(ww5)
messagebox.showinfo(
title='Market Stats : ' + (src.get()+"-"+dst.get()).upper(),
message=ww5
)
except Exception as e:
messagebox.showerror(
title='Market Stats : ' + (src.get()+"-"+dst.get()).upper(),
message="Something is wrong\n"+e.__class__.__name__+": "+str(e) #e is a class so used str
)
return(0)
def get_market_trades(symbol):
#return dict of given symbol market trades
import requests
import json
#to call request symbol must be in upper case contrary to buy sell requests
url = "https://"+EndPoint+"/v2/trades/"+symbol.upper()
print("get market trades :",symbol.upper())
payload={}
headers = {}
try:
response = requests.request("GET", url, headers=headers, data=payload)
tr=response.text
trr=json.loads(tr) #string to json dict
trades=trr["trades"] #get trades dict
for i in trades:
print(unixstamp2date2(i["time"]),"detail:",i)
return(trr)
except Exception as e:
messagebox.showerror(
title='Get Market Trades',
message="Error :\n"+e.__class__.__name__+": "+str(e) #e is a class so used str
)
return(0)
def show_market_trades():
try:
#first we have to change rls to irt in symbolname
symbol=src.get()+dst.get()
if(dst.get().lower()=="usdt"):
symbol=src.get()+"USDT"
else:
symbol=src.get()+"IRT"
ww5=get_market_trades(symbol)
print(ww5)
messagebox.showinfo(
title='Market Trades : ' + (src.get()+"-"+dst.get()).upper(),
message=ww5
)
except Exception as e:
messagebox.showerror(
title='Market Trades : ' + (src.get()+"-"+dst.get()).upper(),
message="Something is wrong\n"+e.__class__.__name__+": "+str(e) #e is a class so used str
)
return(0)
def get_user_limitations():
import requests
import json
global myToken
url = url = "https://"+EndPoint+"/users/limitations"
payload={}
headers = {
'Authorization': 'Token '+ myToken
}
try:
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
uslim=json.loads(response.text) #string to json dict
return(uslim)
except Exception as e:
messagebox.showerror(
title='Get User Limitations',
message="Error :\n"+e.__class__.__name__+": "+str(e) #e is a class so used str
)
return(0)
def show_user_limitations():
try:
ww5=get_user_limitations()
print(ww5)
messagebox.showinfo(
title="User Limitations",
message=ww5
)
except Exception as e:
messagebox.showerror(
title='User Limitations',
message="Something is wrong\n"+e.__class__.__name__+": "+str(e) #e is a class so used str
)
return(0)
def get_user_orders():
#returns json dictionary of given order id (idu is of type string)
global myToken
import requests
import json
url = "https://"+EndPoint+"/market/orders/list?details=2&status=all"
payload={}
headers = {
'Authorization': 'Token '+myToken
}
try:
response = requests.request("GET", url, headers=headers, data=payload)
ww5=json.loads(response.text)
return(ww5)
except Exception as e:
messagebox.showerror(
title='Get order status',
message="Something is wrong\n"+e.__class__.__name__+": "+str(e) #e is a class so used str
)
return("Failed")
def show_user_orders():
try:
ww5=get_user_orders()
print(ww5)
messagebox.showinfo(
title='User Orders',
message=ww5
)
except Exception as e:
messagebox.showerror(
title='User Orders',
message="Something is wrong\n"+e.__class__.__name__+": "+str(e) #e is a class so used str
)
return(0)
def get_user_trades():
#returns json dictionary of given order id (idu is of type string)
global myToken
import requests
import json
url = "https://"+EndPoint+"/market/trades/list"
payload={}
headers = {
'Authorization': 'Token '+myToken
}
try:
response = requests.request("GET", url, headers=headers, data=payload)
ww5=json.loads(response.text)
return(ww5)
except Exception as e:
messagebox.showerror(
title='User Trades',
message="Something is wrong\n"+e.__class__.__name__+": "+str(e) #e is a class so used str
)
return("Failed")
def show_user_trades():
try:
ww5=get_user_trades()
print(ww5)
messagebox.showinfo(
title='User Trades',
message=ww5
)
except Exception as e:
messagebox.showerror(
title='User Trades',
message="Something is wrong\n"+e.__class__.__name__+": "+str(e) #e is a class so used str
)
return(0)
def get_order_status(idu):
#returns json dictionary of given order id (idu is of type string)
global myToken
import requests
import json
url = "https://"+EndPoint+"/market/orders/status?id="+idu
payload={}
headers = {
'Authorization': 'Token '+myToken
}
try:
response = requests.request("GET", url, headers=headers, data=payload)
ww5=json.loads(response.text)
eeid=str(ww5["order"]['status'])
print("Check last order status : ",eeid)
return(eeid)
except Exception as e:
print("Check last order status :"," Failed")
return("Failed")
def get_order_detail(idu):
#returns json dictionary of given order id (idu is of type string)
global myToken
import requests
import json
url = "https://"+EndPoint+"/market/orders/status?id="+idu
payload={}
headers = {
'Authorization': 'Token '+myToken
}
try:
response = requests.request("GET", url, headers=headers, data=payload)
ww5=json.loads(response.text)
## print(str(ww5["order"]['type']))
## print(str(ww5["order"]['execution']))
## print(str(ww5["order"]['tradeType']))
## print(str(ww5["order"]['srcCurrency']))
## print(str(ww5["order"]['dstCurrency']))
## print("price : ",str(ww5["order"]['price']))
## print(str(ww5["order"]['amount']))
print("totalPrice : ",str(ww5["order"]['totalPrice']))
print("totalOrderPrice : ",str(ww5["order"]['totalOrderPrice']))
## print(str(ww5["order"]['matchedAmount']))
## print(str(ww5["order"]['unmatchedAmount']))
## print(str(ww5["order"]['isMyOrder']))
## print(str(ww5["order"]['id']))
## print(str(ww5["order"]['status']))
## print(str(ww5["order"]['partial']))
## print(str(ww5["order"]['fee']))
## print(str(ww5["order"]['user']))
print("averagePrice : ",str(ww5["order"]['averagePrice']))
print("created_at : ",str(ww5["order"]['created_at']))
## print(str(ww5["order"]['market']))
## eeid=str(ww5["order"]['status'])
#print("Check last order status : ",eeid)
return(0)
except Exception as e:
## messagebox.showerror(
## title='Get order status',
## message="Something is wrong\n"+e.__class__.__name__+": "+str(e) #e is a class so used str
## )
print("Check last order status :"," Failed")
return("Failed")
def order_Done(res):
global TradeAllowed
#ww5 is dictionary of order status json data
try:
if(res=="Done"):
TradeAllowed=True
print("Order : Done\n","Trade Allowed : True")
return(True)
if(res=="Active"):
TradeAllowed=False
print("Order : Active\n","Trade Allowed : False")
return(False)
except Exception as e:
messagebox.showerror(
title='Order',
message="Order Not Done\n"+e.__class__.__name__+": "+str(e) #e is a class so used str
)
print("Order Not Done\n"+e.__class__.__name__+": "+str(e)) #e is a class so used str
return(False)
def get_market_settings_options():
#get status of 'status', 'features', 'coins', 'nobitex' including allcoins ,presisions ,daily monthly limitations ,...
#get from "nobitex" sub dict all user level types daily monthly limitations and much more
#you can get user level from get_profile function
import requests
import json
url = "https://"+EndPoint+"/v2/options"
payload={}
headers = {}
response = requests.request("GET", url, headers=headers, data=payload)
mkt=json.loads(response.text)
#print("\n Market :\n",mkt)
return(mkt)
def show_market_settings_options():
try:
ww5=get_market_settings_options()
print(ww5)
messagebox.showinfo(
title='Market Options',
message=ww5
)
except Exception as e:
messagebox.showerror(
title='Market Options',
message="Something is wrong\n"+e.__class__.__name__+": "+str(e) #e is a class so used str
)
return(0)
def get_deposits():
import requests
import json
url = "https://"+EndPoint+"/users/wallets/deposits/list"
payload={}
headers = {
'Authorization': 'Token '+myToken
}
response = requests.request("GET", url, headers=headers, data=payload)
ww5=json.loads(response.text)
#print("\n Market :\n",mkt)
return(ww5)
def show_deposits():
try:
ww5=get_deposits()
print(ww5)
amnt=get_deposits_amounts(ww5)
vamnt=[int(i) for i in amnt]
total=str(sum(vamnt))
print("\ndeposit amounts :\n",amnt, "Total :",total)
messagebox.showinfo(
title='Deposits'+" Total : "+total,
message=ww5
)
except Exception as e:
messagebox.showerror(
title='Deposits',
message="Something is wrong\n"+e.__class__.__name__+": "+str(e) #e is a class so used str
)
return(0)
def get_deposits_amounts(ww5):
#return list of deposit amounts
mylist=[]
for dep in ww5["deposits"]:
mylist.append(dep["amount"])
return(mylist)
def get_withdraws():
import requests
import json
url = "https://"+EndPoint+"/users/wallets/withdraws/list"
payload={}
headers = {
'Authorization': 'Token '+myToken
}
response = requests.request("GET", url, headers=headers, data=payload)
ww5=json.loads(response.text)
return(ww5)
def show_withdraws():
try:
ww5=get_withdraws()
print(ww5)
amnt=get_withdraws_amounts(ww5)
vamnt=[int(i) for i in amnt]
total=str(sum(vamnt))
print("\nwithdraws amounts :\n",amnt, "Total :",total)
messagebox.showinfo(
title='Withdraws'+" Total : "+total,
message=ww5
)
except Exception as e:
messagebox.showerror(
title='Withdraws',
message="Something is wrong\n"+e.__class__.__name__+": "+str(e) #e is a class so used str
)
return(0)
def get_withdraws_amounts(ww5):
#return list of withdraw amounts
mylist=[]
for dep in ww5["withdraws"]:
mylist.append(dep["amount"])
return(mylist)
def get_token(un,pw,twoFA):
#given us and pass and 2FA returns dictionary of keys dict_keys(['status', 'key', 'expiresIn', 'device', 'we_id'])
import requests
import json
url = "https://"+EndPoint+"/auth/login/"
payload={'username': un,
'password': pw,
'remember': 'yes',
'captcha': 'api',
'useragent': 'TraderBot/your_bot'}
files=[
]
headers = {
'X-TOTP': twoFA
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
ww4=json.loads(response.text)#string to json dict
tkn=ww4['key']
print("Token : ",tkn)
return(tkn)
def burn_token():
global myToken
try:
import requests
url = "https://"+EndPoint+"/auth/logout/"
payload={}
headers = {
'Authorization': 'Token '+myToken
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
messagebox.showinfo(
title='Burn Token',
message="Token Burned : " +myToken+"\n"+response.text
)
except Exception as e:
messagebox.showerror(
title='Burn Token',
message="Something is wrong\n"+e.__class__.__name__+": "+str(e) #e is a class so used str
)
return(0)
def get_user_profile(tokenKey):
import requests
import json
url = "https://"+EndPoint+"/users/profile"
payload={}
headers = {
'Authorization': 'Token '+tokenKey
}
response = requests.request("GET", url, headers=headers, data=payload)
#print(response.text)
ww5=json.loads(response.text)#string to json dict
return(ww5)
def show_user_profile():
global myToken
try:
ww5=get_user_profile(myToken)
#Username=get_username(ww5) #set global variable "Username" from profile data
print(ww5)
messagebox.showinfo(
title='Profile Status',
message=ww5
)
except Exception as e:
messagebox.showerror(
title='Profile Status',
message="Something is wrong\n"+e.__class__.__name__+": "+str(e) #e is a class so used str
)
return(0)
def get_username(ww5):
#global Username
try:
un=ww5["profile"]["username"]
print("username :",un)
return(un)
except:
print("Username could not be extracted")
return("Guest")
def get_wallets_money(tokenKey):
#to get some wallet balance use
#wal=get_wallets_money(tokenKey)
#wal["wallets"]["BTC"]["balance"]
import requests
import json
url = "https://"+EndPoint+"/v2/wallets"
payload={}
headers = {
'Authorization': 'Token '+tokenKey
}
response = requests.request("GET", url, headers=headers, data=payload)