· 6 years ago · Jan 16, 2020, 08:04 AM
1
2PASTEBIN
3GO API TOOLS FAQ DEALS
4paste
5
6cyberghostTM
7FREE
8My Pastes
9
10 market dip finderPython | 10 hours ago
11 market dip scanner...Python | 2 days ago
12 market dip scanner...Python | 2 days ago
13 market dip scanner...Python | 2 days ago
14 market dip scanner...Python | 3 days ago
15 polynomial regress...Python | 3 days ago
16 market dip scanner...Python | 3 days ago
17
18Public Pastes
19
20 Untitled4 sec ago
21 FAQ#11 Augmentation?JSON | 9 sec ago
22 Untitled15 sec ago
23 Untitled16 sec ago
24 Untitled48 sec ago
25 Untitled48 sec ago
26 Untitled52 sec ago
27 Untitled53 sec ago
28
29SHARE
30TWEET
31market dip finder
32cyberghostTM Jan 15th, 2020 (edited) 78 Never
33rawdownloadcloneembedreportprinteditdelete Python 7.79 KB
34
35from binance.client import Client
36import matplotlib.pyplot as plt
37import numpy as np
38from datetime import datetime
39import talib as ta
40#from pandas.plotting import register_matplotlib_converters
41#register_matplotlib_converters()
42#import pandas as pd
43import statsmodels.api as sm
44import os, sys
45
46
47class Trader:
48 def __init__(self, file):
49 self.connect(file)
50
51 """ Creates Binance client """
52 def connect(self,file):
53 lines = [line.rstrip('\n') for line in open(file)]
54 key = lines[0]
55 secret = lines[1]
56 self.client = Client(key, secret)
57
58 """ Gets all account balances """
59 def getBalances(self):
60 prices = self.client.get_withdraw_history()
61 return prices
62
63filename = 'credentials.txt'
64trader = Trader(filename)
65
66trading_pairs = [
67 'ADAUSDT','ALGOUSDT','ANKRUSDT','ARPAUSDT',
68 'ATOMUSDT','BANDUSDT','BATUSDT','BCHUSDT',
69 'BEAMUSDT','BNBUSDT','BTCUSDT','BTTUSDT',
70 'CELRUSDT','CHZUSDT','COCOSUSDT','COSUSDT',
71 'CTXCUSDT','CVCUSDT','DASHUSDT','DENTUSDT',
72 'DOCKUSDT','DOGEUSDT','DUSKUSDT','ENJUSDT',
73 'EOSUSDT','ERDUSDT','ETCUSDT','ETHUSDT',
74 'FETUSDT','FTMUSDT','FTTUSDT','FUNUSDT',
75 'GTOUSDT','HBARUSDT','HCUSDT','HOTUSDT',
76 'ICXUSDT','IOSTUSDT','IOTAUSDT','IOTXUSDT',
77 'KAVAUSDT','KEYUSDT','LINKUSDT','LTCUSDT',
78 'MATICUSDT','MCOUSDT','MFTUSDT','MITHUSDT',
79 'MTLUSDT','NANOUSDT','NEOUSDT','NKNUSDT',
80 'NPXSUSDT','NULSUSDT','OMGUSDT','ONEUSDT',
81 'ONGUSDT','ONTUSDT','PERLUSDT','QTUMUSDT',
82 'RENUSDT','RLCUSDT','RVNUSDT','STORMUSDT',
83 'STXUSDT','TFUELUSDT','THETAUSDT','TOMOUSDT',
84 'TROYUSDT','TRXUSDT','VETUSDT','VITEUSDT',
85 'WANUSDT','WAVESUSDT','WINUSDT','XLMUSDT',
86 'XMRUSDT','XRPUSDT','XTZUSDT','ZECUSDT',
87 'ZILUSDT','ZRXUSDT'
88 ]
89
90filtered_pairs1 = []
91filtered_pairs2 = []
92filtered_pairs3 = []
93selected_pair = []
94selected_pairCMO = []
95
96def filter1(pair):
97 interval = '1h'
98 symbol = pair
99 klines = trader.client.get_klines(symbol=symbol,interval=interval)
100 open_time = [int(entry[0]) for entry in klines]
101 close = [float(entry[4]) for entry in klines]
102 close_array = np.asarray(close)
103
104 print("on 1h timeframe " + symbol)
105
106 x = close
107 y = range(len(x))
108
109 best_fit_line1 = np.poly1d(np.polyfit(y, x, 1))(y)
110 best_fit_line2 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 1.01
111 best_fit_line3 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 0.99
112
113 if x[-1] < best_fit_line3[-1] and best_fit_line1[0] <= best_fit_line1[-1]:
114 filtered_pairs1.append(symbol)
115 print('found')
116
117 elif x[-1] < best_fit_line3[-1] and best_fit_line1[0] >= best_fit_line1[-1]:
118 filtered_pairs1.append(symbol)
119 print('found')
120
121 else:
122 print('searching')
123
124 #plt.figure(figsize=(8,6))
125 #plt.grid(True)
126 #plt.plot(x)
127 #plt.plot(best_fit_line1, '--', color='r')
128 #plt.plot(best_fit_line2, '--', color='r')
129 #plt.plot(best_fit_line3, '--', color='r')
130 #plt.show(block=False)
131 #plt.pause(1)
132 #plt.close()
133
134def filter2(filtered_pairs1):
135 interval = '15m'
136 symbol = filtered_pairs1
137 klines = trader.client.get_klines(symbol=symbol,interval=interval)
138 open_time = [int(entry[0]) for entry in klines]
139 close = [float(entry[4]) for entry in klines]
140 close_array = np.asarray(close)
141
142 print("on 15min timeframe " + symbol)
143
144 x = close
145 y = range(len(x))
146
147 best_fit_line1 = np.poly1d(np.polyfit(y, x, 1))(y)
148 best_fit_line2 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 1.01
149 best_fit_line3 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 0.99
150
151 if x[-1] < best_fit_line3[-1] and best_fit_line1[0] < best_fit_line1[-1]:
152 filtered_pairs2.append(symbol)
153 print('found')
154
155 if x[-1] < best_fit_line3[-1] and best_fit_line1[0] >= best_fit_line1[-1]:
156 filtered_pairs2.append(symbol)
157 print('found')
158
159 #plt.figure(figsize=(8,6))
160 #plt.grid(True)
161 #plt.plot(x)
162 #plt.plot(best_fit_line1, '--', color='r')
163 #plt.plot(best_fit_line2, '--', color='r')
164 #plt.plot(best_fit_line3, '--', color='r')
165 #plt.show(block=False)
166 #plt.pause(1)
167 #plt.close()
168
169def filter3(filtered_pairs2):
170 interval = '5m'
171 symbol = filtered_pairs2
172 klines = trader.client.get_klines(symbol=symbol,interval=interval)
173 open_time = [int(entry[0]) for entry in klines]
174 close = [float(entry[4]) for entry in klines]
175 close_array = np.asarray(close)
176
177 print("on 5m timeframe " + symbol)
178
179 min = ta.MIN(close_array, timeperiod=30)
180 max = ta.MAX(close_array, timeperiod=30)
181
182 wcl = ta.WCLPRICE(max, min, close_array)
183
184 print(close[-1])
185 print()
186 print(min[-1])
187 print(max[-1])
188 print(wcl[-1])
189
190 x = close
191 y = range(len(x))
192
193 best_fit_line1 = np.poly1d(np.polyfit(y, x, 1))(y)
194 best_fit_line2 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 1.01
195 best_fit_line3 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 0.99
196
197 min = ta.MIN(close_array, timeperiod=30)
198 max = ta.MAX(close_array, timeperiod=30)
199
200 wcl = ta.WCLPRICE(max, min, close_array)
201
202 print(close[-1])
203 print()
204 print(min[-1])
205 print(max[-1])
206 print(wcl[-1])
207
208 #plt.figure(figsize=(8,6))
209 #plt.grid(True)
210 #plt.plot(close)
211 #plt.plot(best_fit_line1, '--', color='r')
212 #plt.plot(best_fit_line2, '--', color='r')
213 #plt.plot(best_fit_line3, '--', color='r')
214 #plt.plot(close)
215 #plt.plot(min)
216 #plt.plot(max)
217 #plt.plot(wcl)
218 #plt.show(block=False)
219 #plt.pause(5)
220 #plt.close()
221
222 if x[-1] < best_fit_line1[-1] and best_fit_line1[0] <= best_fit_line1[-1]:
223 filtered_pairs3.append(symbol)
224 print('found')
225
226 elif x[-1] < best_fit_line1[-1] and best_fit_line1[0] > best_fit_line1[-1]:
227 filtered_pairs3.append(symbol)
228 print('found')
229
230 elif x[-1] == min[-1]:
231 filtered_pairs3.append(symbol)
232 print('found')
233
234 elif x[-1] < wcl[-1]:
235 filtered_pairs3.append(symbol)
236 print('found')
237
238 else:
239 print('searching')
240
241def momentum(filtered_pairs3):
242 interval = '1m'
243 symbol = filtered_pairs3
244 klines = trader.client.get_klines(symbol=symbol,interval=interval)
245 open_time = [int(entry[0]) for entry in klines]
246 close = [float(entry[4]) for entry in klines]
247 close_array = np.asarray(close)
248
249 print("on 1m timeframe " + symbol)
250
251 real = ta.CMO(close_array, timeperiod=14)
252 print(real[-1])
253
254 if real[-1] < -50:
255 print('oversold dip found')
256 selected_pair.append(symbol)
257 selected_pairCMO.append(real[-1])
258
259 else:
260 print('searching')
261
262for i in trading_pairs:
263 output = filter1(i)
264 print(filtered_pairs1)
265
266for i in filtered_pairs1:
267 output = filter2(i)
268 print(filtered_pairs2)
269
270for i in filtered_pairs2:
271 output = filter3(i)
272 print(filtered_pairs3)
273
274for i in filtered_pairs3:
275 output = momentum(i)
276 print(selected_pair)
277
278if len(selected_pair) > 1:
279 print('dips are more then 1 oversold')
280 print(selected_pair)
281 print(selected_pairCMO)
282
283 if min(selected_pairCMO) in selected_pairCMO:
284 #print(selected_pairCMO.index(min(selected_pairCMO)))
285 position = selected_pairCMO.index(min(selected_pairCMO))
286
287 for id, value in enumerate(selected_pair):
288 if id == position:
289 print(selected_pair[id])
290 #sys.exit()
291
292elif len(selected_pair) == 1:
293 print('1 dip found')
294 print(selected_pair)
295 print(selected_pairCMO)
296 #sys.exit()
297
298else:
299 print('no oversold dips for the moment, restart script...')
300 print(selected_pair)
301 print(selected_pairCMO)
302 os.execl(sys.executable, sys.executable, *sys.argv)
303
304
305 sys.exit(0)
306
307RAW Paste Data
308from binance.client import Client
309import matplotlib.pyplot as plt
310import numpy as np
311from datetime import datetime
312import talib as ta
313#from pandas.plotting import register_matplotlib_converters
314#register_matplotlib_converters()
315#import pandas as pd
316import statsmodels.api as sm
317import os, sys
318
319
320class Trader:
321 def __init__(self, file):
322 self.connect(file)
323
324 """ Creates Binance client """
325 def connect(self,file):
326 lines = [line.rstrip('\n') for line in open(file)]
327 key = lines[0]
328 secret = lines[1]
329 self.client = Client(key, secret)
330
331 """ Gets all account balances """
332 def getBalances(self):
333 prices = self.client.get_withdraw_history()
334 return prices
335
336filename = 'credentials.txt'
337trader = Trader(filename)
338
339trading_pairs = [
340 'ADAUSDT','ALGOUSDT','ANKRUSDT','ARPAUSDT',
341 'ATOMUSDT','BANDUSDT','BATUSDT','BCHUSDT',
342 'BEAMUSDT','BNBUSDT','BTCUSDT','BTTUSDT',
343 'CELRUSDT','CHZUSDT','COCOSUSDT','COSUSDT',
344 'CTXCUSDT','CVCUSDT','DASHUSDT','DENTUSDT',
345 'DOCKUSDT','DOGEUSDT','DUSKUSDT','ENJUSDT',
346 'EOSUSDT','ERDUSDT','ETCUSDT','ETHUSDT',
347 'FETUSDT','FTMUSDT','FTTUSDT','FUNUSDT',
348 'GTOUSDT','HBARUSDT','HCUSDT','HOTUSDT',
349 'ICXUSDT','IOSTUSDT','IOTAUSDT','IOTXUSDT',
350 'KAVAUSDT','KEYUSDT','LINKUSDT','LTCUSDT',
351 'MATICUSDT','MCOUSDT','MFTUSDT','MITHUSDT',
352 'MTLUSDT','NANOUSDT','NEOUSDT','NKNUSDT',
353 'NPXSUSDT','NULSUSDT','OMGUSDT','ONEUSDT',
354 'ONGUSDT','ONTUSDT','PERLUSDT','QTUMUSDT',
355 'RENUSDT','RLCUSDT','RVNUSDT','STORMUSDT',
356 'STXUSDT','TFUELUSDT','THETAUSDT','TOMOUSDT',
357 'TROYUSDT','TRXUSDT','VETUSDT','VITEUSDT',
358 'WANUSDT','WAVESUSDT','WINUSDT','XLMUSDT',
359 'XMRUSDT','XRPUSDT','XTZUSDT','ZECUSDT',
360 'ZILUSDT','ZRXUSDT'
361 ]
362
363filtered_pairs1 = []
364filtered_pairs2 = []
365filtered_pairs3 = []
366selected_pair = []
367selected_pairCMO = []
368
369def filter1(pair):
370 interval = '1h'
371 symbol = pair
372 klines = trader.client.get_klines(symbol=symbol,interval=interval)
373 open_time = [int(entry[0]) for entry in klines]
374 close = [float(entry[4]) for entry in klines]
375 close_array = np.asarray(close)
376
377 print("on 1h timeframe " + symbol)
378
379 x = close
380 y = range(len(x))
381
382 best_fit_line1 = np.poly1d(np.polyfit(y, x, 1))(y)
383 best_fit_line2 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 1.01
384 best_fit_line3 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 0.99
385
386 if x[-1] < best_fit_line3[-1] and best_fit_line1[0] <= best_fit_line1[-1]:
387 filtered_pairs1.append(symbol)
388 print('found')
389
390 elif x[-1] < best_fit_line3[-1] and best_fit_line1[0] >= best_fit_line1[-1]:
391 filtered_pairs1.append(symbol)
392 print('found')
393
394 else:
395 print('searching')
396
397 #plt.figure(figsize=(8,6))
398 #plt.grid(True)
399 #plt.plot(x)
400 #plt.plot(best_fit_line1, '--', color='r')
401 #plt.plot(best_fit_line2, '--', color='r')
402 #plt.plot(best_fit_line3, '--', color='r')
403 #plt.show(block=False)
404 #plt.pause(1)
405 #plt.close()
406
407def filter2(filtered_pairs1):
408 interval = '15m'
409 symbol = filtered_pairs1
410 klines = trader.client.get_klines(symbol=symbol,interval=interval)
411 open_time = [int(entry[0]) for entry in klines]
412 close = [float(entry[4]) for entry in klines]
413 close_array = np.asarray(close)
414
415 print("on 15min timeframe " + symbol)
416
417 x = close
418 y = range(len(x))
419
420 best_fit_line1 = np.poly1d(np.polyfit(y, x, 1))(y)
421 best_fit_line2 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 1.01
422 best_fit_line3 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 0.99
423
424 if x[-1] < best_fit_line3[-1] and best_fit_line1[0] < best_fit_line1[-1]:
425 filtered_pairs2.append(symbol)
426 print('found')
427
428 if x[-1] < best_fit_line3[-1] and best_fit_line1[0] >= best_fit_line1[-1]:
429 filtered_pairs2.append(symbol)
430 print('found')
431
432 #plt.figure(figsize=(8,6))
433 #plt.grid(True)
434 #plt.plot(x)
435 #plt.plot(best_fit_line1, '--', color='r')
436 #plt.plot(best_fit_line2, '--', color='r')
437 #plt.plot(best_fit_line3, '--', color='r')
438 #plt.show(block=False)
439 #plt.pause(1)
440 #plt.close()
441
442def filter3(filtered_pairs2):
443 interval = '5m'
444 symbol = filtered_pairs2
445 klines = trader.client.get_klines(symbol=symbol,interval=interval)
446 open_time = [int(entry[0]) for entry in klines]
447 close = [float(entry[4]) for entry in klines]
448 close_array = np.asarray(close)
449
450 print("on 5m timeframe " + symbol)
451
452 min = ta.MIN(close_array, timeperiod=30)
453 max = ta.MAX(close_array, timeperiod=30)
454
455 wcl = ta.WCLPRICE(max, min, close_array)
456
457 print(close[-1])
458 print()
459 print(min[-1])
460 print(max[-1])
461 print(wcl[-1])
462
463 x = close
464 y = range(len(x))
465
466 best_fit_line1 = np.poly1d(np.polyfit(y, x, 1))(y)
467 best_fit_line2 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 1.01
468 best_fit_line3 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 0.99
469
470 min = ta.MIN(close_array, timeperiod=30)
471 max = ta.MAX(close_array, timeperiod=30)
472
473 wcl = ta.WCLPRICE(max, min, close_array)
474
475 print(close[-1])
476 print()
477 print(min[-1])
478 print(max[-1])
479 print(wcl[-1])
480
481 #plt.figure(figsize=(8,6))
482 #plt.grid(True)
483 #plt.plot(close)
484 #plt.plot(best_fit_line1, '--', color='r')
485 #plt.plot(best_fit_line2, '--', color='r')
486 #plt.plot(best_fit_line3, '--', color='r')
487 #plt.plot(close)
488 #plt.plot(min)
489 #plt.plot(max)
490 #plt.plot(wcl)
491 #plt.show(block=False)
492 #plt.pause(5)
493 #plt.close()
494
495 if x[-1] < best_fit_line1[-1] and best_fit_line1[0] <= best_fit_line1[-1]:
496 filtered_pairs3.append(symbol)
497 print('found')
498
499 elif x[-1] < best_fit_line1[-1] and best_fit_line1[0] > best_fit_line1[-1]:
500 filtered_pairs3.append(symbol)
501 print('found')
502
503 elif x[-1] == min[-1]:
504 filtered_pairs3.append(symbol)
505 print('found')
506
507 elif x[-1] < wcl[-1]:
508 filtered_pairs3.append(symbol)
509 print('found')
510
511 else:
512 print('searching')
513
514def momentum(filtered_pairs3):
515 interval = '1m'
516 symbol = filtered_pairs3
517 klines = trader.client.get_klines(symbol=symbol,interval=interval)
518 open_time = [int(entry[0]) for entry in klines]
519 close = [float(entry[4]) for entry in klines]
520 close_array = np.asarray(close)
521
522 print("on 1m timeframe " + symbol)
523
524 real = ta.CMO(close_array, timeperiod=14)
525 print(real[-1])
526
527 if real[-1] < -50:
528 print('oversold dip found')
529 selected_pair.append(symbol)
530 selected_pairCMO.append(real[-1])
531
532 else:
533 print('searching')
534
535for i in trading_pairs:
536 output = filter1(i)
537 print(filtered_pairs1)
538
539for i in filtered_pairs1:
540 output = filter2(i)
541 print(filtered_pairs2)
542
543for i in filtered_pairs2:
544 output = filter3(i)
545 print(filtered_pairs3)
546
547for i in filtered_pairs3:
548 output = momentum(i)
549 print(selected_pair)
550
551if len(selected_pair) > 1:
552 print('dips are more then 1 oversold')
553 print(selected_pair)
554 print(selected_pairCMO)
555
556 if min(selected_pairCMO) in selected_pairCMO:
557 #print(selected_pairCMO.index(min(selected_pairCMO)))
558 position = selected_pairCMO.index(min(selected_pairCMO))
559
560 for id, value in enumerate(selected_pair):
561 if id == position:
562 print(selected_pair[id])
563 #sys.exit()
564
565elif len(selected_pair) == 1:
566 print('1 dip found')
567 print(selected_pair)
568 print(selected_pairCMO)
569 #sys.exit()
570
571else:
572 print('no oversold dips for the moment, restart script...')
573 print(selected_pair)
574 print(selected_pairCMO)
575 os.execl(sys.executable, sys.executable, *sys.argv)
576
577sys.exit(0)
578Not a member of Pastebin yet?
579Sign Up, it unlocks many cool features!
580
581create new paste / dealsnew! / syntax languages / archive / faq / tools / night mode / api / scraping api
582privacy statement / cookies policy / terms of service / security disclosure / dmca / contact
583
584By using Pastebin.com you agree to our cookies policy to enhance your experience.
585Site design & logo © 2020 Pastebin; user contributions (pastes) licensed under cc by-sa 3.0 -- FavPNG -- Dedicated Server Hosting by Steadfast
586Share on Facebook!
587Share on Twitter!