Advertisement
Guest User

Untitled

a guest
Sep 24th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.48 KB | None | 0 0
  1. def pari():
  2.     get_price = requests.get(ENDPOINT + "/api/v3/ticker/price?symbol=BTCUSDT")
  3.     if get_price.status_code == 200:
  4.         settings.price = float(json.loads(get_price.text)['price'])
  5.         settings.global_pari_status = True
  6.         settings.save()
  7.         for user in BotUser.objects.filter(notifications=True):
  8.             translation.activate(user.language)
  9.             button = Buttons.objects.filter(translations__language_code=user.language).first()
  10.             message = Messages.objects.filter(translations__language_code=user.language).first()
  11.  
  12.             text = str(message.start_pari).replace("{price}", str(settings.price))\
  13.                 .replace("{time}", (datetime.today() + timedelta(hours=5)).strftime("%d/%m/%y %H:%M"))
  14.             print(text)
  15.  
  16.             keyboard = telebot.types.InlineKeyboardMarkup()
  17.             keyboard.add(telebot.types.InlineKeyboardButton(
  18.                 text=_(button.lower_price), callback_data="price_lower"),
  19.                 telebot.types.InlineKeyboardButton(
  20.                     text=_(button.up_price), callback_data="price_up")
  21.                 )
  22.             try:
  23.                 BOT.send_message(user.chat_id, text, reply_markup=keyboard, parse_mode="Markdown")
  24.             except Exception as err:
  25.                 print(err)
  26.                 continue
  27.  
  28.         # time.sleep(10 * 60)
  29.         time.sleep(1 * 60)
  30.         settings.global_pari_status = False
  31.         settings.save()
  32.  
  33.         # time.sleep(120 * 60)
  34.         time.sleep(3 * 60)
  35.  
  36.         get_price = requests.get(ENDPOINT + "/api/v3/ticker/price?symbol=BTCUSDT")
  37.         if get_price.status_code == 200:
  38.             settings.new_price = float(json.loads(get_price.text)['price'])
  39.             pari_result = True if settings.new_price > settings.price else False
  40.  
  41.             all_money = 0
  42.             loser_filter = True if pari_result else False
  43.             for p in Pari.objects.filter(user__rate=loser_filter):
  44.                 all_money += p.rate_summa
  45.             # minus procents
  46.             all_money -= (all_money / 100) * settings.procents
  47.             print(all_money)
  48.  
  49.             for p in Pari.objects.filter(user__rate=pari_result):
  50.                 # procents = p.rate_summa / all_money * 100
  51.                 win_summa = 100 / (all_money / p.rate_summa)
  52.                 print('WIN - ', str(win_summa))
  53.                 p.user.balance += win_summa
  54.                 p.user.save()
  55.                 p.win = True
  56.                 p.profit_or_lose = win_summa
  57.                 p.save()
  58.  
  59.             for user in BotUser.objects.filter(notifications=True):
  60.                 try:
  61.                     translation.activate(user.language)
  62.                     message = Messages.objects.filter(translations__language_code=user.language).first()
  63.                     prices = [price.profit_or_lose for price in Pari.objects.filter(user__rate=pari_result)]
  64.                     text = _(message.end_pari).replace("{price}", str(settings.new_price)) \
  65.                         .replace("{biggest_price}", str(max(prices)))
  66.                     BOT.send_message(user.chat_id, text)
  67.                 except Exception as err:
  68.                     print(err)
  69.                     continue
  70.  
  71.             for p in Pari.objects.all():
  72.                 HistoryPari.objects.create(
  73.                     user = p.user,
  74.                     win = p.win,
  75.                     rate = p.profit_or_lose,
  76.                     date = settings.date_pari
  77.                 )
  78.                 p.delete()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement