Advertisement
xmd79

mtfz9

Mar 14th, 2024
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. from binance.client import Client
  2. import numpy as np
  3. import talib as ta
  4. import asyncio
  5. from binance.exceptions import BinanceAPIException
  6.  
  7. class Trader:
  8. def __init__(self, file):
  9. self.connect(file)
  10.  
  11. def connect(self, file):
  12. with open(file) as f:
  13. lines = f.readlines()
  14. key = lines[0].strip()
  15. secret = lines[1].strip()
  16. self.client = Client(key, secret)
  17.  
  18. def get_latest_price(self, symbol):
  19. ticker = self.client.get_symbol_ticker(symbol=symbol)
  20. return float(ticker['price'])
  21.  
  22. trader = Trader('credentials.txt')
  23.  
  24. filtered_pairs1 = []
  25. filtered_pairs2 = []
  26. filtered_pairs3 = []
  27. filtered_pairs4 = []
  28. selected_pair = []
  29. selected_pairCMO = []
  30.  
  31. async def filter_trading_pairs():
  32. trading_pairs = [symbol['symbol'] for symbol in trader.client.futures_exchange_info()['symbols'] if 'USDT' in symbol['symbol']]
  33. print("Trading pairs:", trading_pairs) # Print out trading pairs for debugging
  34. for pair in trading_pairs:
  35. await filter1(pair)
  36. return True
  37.  
  38. async def filter1(pair):
  39. interval = '4h'
  40. try:
  41. klines = trader.client.get_klines(symbol=pair, interval=interval)
  42. close = [float(entry[4]) for entry in klines]
  43.  
  44. x = close
  45. y = range(len(x))
  46.  
  47. best_fit_line1 = np.poly1d(np.polyfit(y, x, 1))(y)
  48. best_fit_line3 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 0.99
  49.  
  50. if x[-1] < best_fit_line3[-1] and best_fit_line1[0] <= best_fit_line1[-1]:
  51. filtered_pairs1.append(pair)
  52. print(f'Found dip on 4h timeframe for {pair}')
  53. elif x[-1] < best_fit_line3[-1] and best_fit_line1[0] >= best_fit_line1[-1]:
  54. filtered_pairs1.append(pair)
  55. print(f'Found top on 4h timeframe for {pair}')
  56. else:
  57. print(f'Searching for {pair}')
  58. except BinanceAPIException as e:
  59. if e.code == -1121:
  60. pass # Ignore invalid symbol error
  61. else:
  62. print(f"Error processing {pair}: {e}")
  63.  
  64. async def main():
  65. await filter_trading_pairs()
  66.  
  67. asyncio.run(main())
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement