Advertisement
Guest User

Untitled

a guest
Nov 26th, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. import mysql.connector
  2. import ccxt
  3. import numpy as np
  4.  
  5.  
  6. bittrex = ccxt.bittrex({
  7. 'enableRateLimit': True, # this option enables the built-in rate limiter
  8. })
  9.  
  10. markets = bittrex.load_markets()
  11. whichmarket = (bittrex.symbols)
  12.  
  13. cnx = mysql.connector.connect(user='root', password='',
  14. host='localhost', database='coinbuys',
  15. auth_plugin='mysql_native_password')
  16.  
  17. mycursor = cnx.cursor()
  18.  
  19. coin_pairs_start = []
  20.  
  21. #get a list of coins that have buy walls
  22.  
  23.  
  24. sql1 = """SELECT * FROM BUYWALLDATA3 """
  25. mycursor.execute(sql1)
  26. myresult = mycursor.fetchall()
  27. for row in myresult:
  28. coin_pairs_start.append(row[1])
  29.  
  30.  
  31. coin_pairs = list(set(coin_pairs_start))
  32.  
  33. #define a few things
  34. avg_coin_price = {}
  35. coin_pairs_ticker = []
  36. f=0
  37. count_row = 0
  38. avg_price_start = 0
  39. avg_price = 0
  40. price = 0
  41. #avg_price_start =[]
  42.  
  43. while f < len(coin_pairs):
  44. sql = """SELECT * FROM BUYWALLDATA3 WHERE COINPAIR = '%s' """ % (coin_pairs[f])
  45. mycursor.execute(sql)
  46. myresult = mycursor.fetchall()
  47. for row in myresult:
  48. price=row[2]
  49. total=row[3]
  50. avg_price_start = avg_price_start + float(row[2])
  51. count_row = count_row + 1
  52. avg_price = avg_price_start / count_row
  53. #avg_price_start.append(row[2])
  54. #for c in avg_price_start:
  55. # print (avg_price_start)
  56.  
  57. coin_pairs_ticker.append(coin_pairs_ticker)
  58. print(coin_pairs[f])
  59. print ('avergae price: ',avg_price)
  60. avg_coin_price[coin_pairs[f]]=avg_price
  61.  
  62. count_row = 0
  63. avg_price_start = 0
  64. f = f +1
  65.  
  66. print(avg_coin_price)
  67.  
  68. #coin_pairs_ticker = list(set(coin_pairs_ticker))
  69.  
  70.  
  71. limit = '10%'
  72. f = 0
  73. coins_with_buy_walls = {}
  74. coins_with_creeping_buy_walls =[]
  75.  
  76. while f < len(coin_pairs):
  77. orderbook = ccxt.bittrex().fetch_order_book(coin_pairs[f], limit)
  78. ticker_info = bittrex.fetch_ticker(coin_pairs[f])
  79. last_price = ticker_info.get('last')
  80. volume = ticker_info.get('quoteVolume')
  81.  
  82. bids = (orderbook['bids'])
  83. i = 0
  84. g = 0
  85. above_average_count = 0
  86. sum_bids = []
  87. while i < len(bids):
  88. var_element = (bids[i])
  89. sum_array = var_element[0] * var_element[1]
  90. i = i + 1
  91. sum_bids.append(sum_array)
  92.  
  93. total_bids = sum(sum_bids)
  94. if total_bids == 0:
  95. total_bids = 1
  96. length_sum_bids = len(sum_bids)
  97. if length_sum_bids == 0:
  98. length_sum_bids =1
  99.  
  100.  
  101. average_bid = total_bids / length_sum_bids
  102.  
  103. #if an order is 10 times larger than the average bid
  104. threshhold = average_bid * 10
  105.  
  106. #check to see any above average buy orders
  107. while g < len(bids):
  108. var_element_check = (bids[g])
  109. sum_array_check = var_element_check[0] * var_element_check[1]
  110. volume_threshold = sum_array_check / volume
  111. #number below is total order size divded by total volume and if its below 0.037 it should be a large order
  112. if sum_array_check > threshhold and volume_threshold < 0.037:
  113.  
  114. #check if theres creeping buy orders
  115. in_key_avg_price = avg_coin_price.get(coin_pairs[f])
  116. # the value 1.03 is 3% above the last buy order price
  117. if (var_element_check[0] * 1.03) > in_key_avg_price:
  118.  
  119. print("Creeping Buy order present")
  120. print(coin_pairs[f])
  121. coins_with_creeping_buy_walls.append(coin_pairs[f])
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130. above_average_count = above_average_count + 1
  131.  
  132. g = g + 1
  133.  
  134.  
  135. if above_average_count >= 1:
  136. coins_with_buy_walls[coin_pairs[f]] = above_average_count
  137.  
  138.  
  139.  
  140. print ("The coin is;",coin_pairs[f])
  141. print ("There are",above_average_count,"buy walls")
  142. print (total_bids,"is the sum of orders")
  143. print ("The average bid is",average_bid)
  144. f = f + 1
  145.  
  146. coins_with_creeping_buy_walls = list(set(coins_with_creeping_buy_walls))
  147.  
  148. print (coins_with_creeping_buy_walls)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement