示例#1
0
def create_user(form):
    user = User.create(login=form.login.data,
                       password=form.password.data,
                       role='applicant')
    applicant = Applicant.create(first_name=form.first_name.data,
                                 last_name=form.last_name.data,
                                 email=form.email.data,
                                 city=str(form.city.data).lower(),
                                 user=user.id)

    Applicant_methods.assign_id_to_applicant(applicant)
    Applicant_methods.assign_school_to_applicant(applicant)
    interview_methods.assign_interview(applicant)
    msg = "{} {} just registered as an applicant! - codezero".format(
        applicant.first_name, applicant.last_name)
    pushover.send_pushover(msg)
示例#2
0
 def start_thread(market, currency, amount, ask, trailing):
     time.sleep(1)
     global messages
     thread_name = threading.current_thread().name
     while True:
         try:
             buy = api.buylimit(market, amount, ask)
             time.sleep(0.5)
             buy_uuid = buy['uuid']
             time.sleep(0.5)
             buyorder = api.getorder(uuid=buy_uuid)
             push_send = False
             while buyorder['IsOpen'] == True:
                 message = '{0}: Made a buyorder, waiting until it is filled! Remaining: {1:.8f} {2}'.format(
                     thread_name, buyorder['QuantityRemaining'],
                     currency)
                 messages[thread_name] = message
                 if push_send == False:
                     send_pushover(pushover_user, pushover_app, message)
                     send_pushbullet(pushbullet_token, message)
                     push_send = True
                 buyorder = api.getorder(uuid=buy_uuid)
                 time.sleep(10)
             trailing_percentage = float(ask) / 100 * float(trailing)
             trailing_stop_loss = float(ask) - float(
                 trailing_percentage)
             stop_loss_percentage = '-{0:.2f}'.format(trailing)
             buyprice = float(ask)
             lastprice = 0
         except:
             message = '{0}: API error: Was unable to create the buyorder... it was cancelled due to:\n{1}'.format(
                 thread_name, buy)
             messages[thread_name] = message
             send_pushover(pushover_user, pushover_app, message)
             send_pushbullet(pushbullet_token, message)
             break
         while float(ask) > float(trailing_stop_loss):
             try:
                 time.sleep(0.5)
                 values = r.hmget(market, 'Ask')
                 ask = float(values[0])
             except:
                 message = 'Unable to retrieve data from redis.pontstrader.com, trying to recover...'
                 messages[thread_name] = message
             else:
                 percentage = 100 * (float(ask) -
                                     float(buyprice)) / float(buyprice)
                 trailing_percentage = float(ask) / 100 * float(
                     trailing)
                 if float(ask) > float(buyprice) and ask != lastprice:
                     if float(ask) > lastprice and float(ask) > float(
                             buyprice):
                         new_trailing_stop_loss = float(ask) - float(
                             trailing_percentage)
                         if float(new_trailing_stop_loss) > float(
                                 trailing_stop_loss):
                             trailing_stop_loss = float(ask) - float(
                                 trailing_percentage)
                             stop_loss_percentage = 100 * (
                                 float(trailing_stop_loss) -
                                 float(buyprice)) / float(buyprice)
                             message = '{0}: {1} | Buy price {2:.8f} | Price {3:.8f} | Profit: {4:.2f}% | Stop Loss: {5:.8f} ({6:.2f}%)'.format(
                                 thread_name, currency, float(buyprice),
                                 float(ask), float(percentage),
                                 float(trailing_stop_loss),
                                 float(stop_loss_percentage))
                             messages[thread_name] = message
                         else:
                             message = '{0}: {1} | Buy price {2:.8f} | Price {3:.8f} | Profit: {4:.2f}% | Stop Loss: {5:.8f} ({6:.2f}%)'.format(
                                 thread_name, currency, float(buyprice),
                                 float(ask), float(percentage),
                                 float(trailing_stop_loss),
                                 float(stop_loss_percentage))
                             messages[thread_name] = message
                     else:
                         message = '{0}: {1} | Buy price {2:.8f} | Price {3:.8f} | Profit: {4:.2f}% | Stop Loss: {5:.8f} ({6:.2f}%)'.format(
                             thread_name, currency, float(buyprice),
                             float(ask), float(percentage),
                             float(trailing_stop_loss),
                             float(stop_loss_percentage))
                         messages[thread_name] = message
                 elif float(ask) < float(buyprice) and float(
                         ask) != float(lastprice):
                     message = '{0}: {1} | Buy price {2:.8f} | Price {3:.8f} | Profit: {4:.2f}% | Stop Loss: {5:.8f} ({6:.2f}%)'.format(
                         thread_name, currency, float(buyprice),
                         float(ask), float(percentage),
                         float(trailing_stop_loss),
                         float(stop_loss_percentage))
                     messages[thread_name] = message
                 elif float(ask) == float(
                         buyprice) and float(ask) != float(lastprice):
                     pass
                 lastprice = float(ask)
         profit_percentage = 100 * (float(trailing_stop_loss) -
                                    float(buyprice)) / float(buyprice)
         try:
             sell = api.selllimit(market, amount, trailing_stop_loss)
             sell_uuid = sell['uuid']
             time.sleep(0.5)
             sellorder = api.getorder(uuid=sell_uuid)
             while sellorder['IsOpen'] == True:
                 message = '{0}: Stop Loss triggered, waiting until the sell order is completely filled! Remaining: {1:.8f}'.format(
                     thread_name, sellorder['QuantityRemaining'])
                 messages[thread_name] = message
                 try:
                     sellorder = api.getorder(uuid=sell_uuid)
                 except:
                     pass
                 time.sleep(2)
             message = '{0}: {1} SOLD | Buy price {2:.8f} | Sell price {3:.8f} | Profit {4:.2f}% (excl. fee)'.format(
                 thread_name, currency, buyprice, trailing_stop_loss,
                 profit_percentage)
             messages[thread_name] = message
             send_pushover(pushover_user, pushover_app, message)
             send_pushbullet(pushbullet_token, message)
             break
         except:
             message = '{0}: API error: Was unable to create the sellorder... it was cancelled due to:\n{1}'.format(
                 thread_name, sell)
             messages[thread_name] = message
             send_pushover(pushover_user, pushover_app, message)
             send_pushbullet(pushbullet_token, message)
             break
示例#3
0
        def start_thread_single(market, currency, amount, ask, stoploss,
                                target):
            time.sleep(1)
            global messages
            thread_name = threading.current_thread().name
            done = False
            while True:
                values = r.hmget(market, 'Ask')
                ask = float(values[0])
                try:
                    buy = api.buylimit(market, amount, ask)
                except:
                    message = 'Bittrex API error, unable to buy: {0}'.format(
                        buy)
                    messages[thread_name] = message
                    send_pushover(pushover_user, pushover_app, message)
                    send_pushbullet(pushbullet_token, message)
                    break
                else:
                    time.sleep(0.5)
                    buy_uuid = buy['uuid']
                    time.sleep(0.5)
                    push_send = False
                    try:
                        buyorder = api.getorder(uuid=buy_uuid)
                    except:
                        message = 'Bittrex API error, unable to check the buyorder: {0}'.format(
                            buyorder)
                        messages[thread_name] = message
                    else:
                        if buyorder['IsOpen'] == True:
                            while buyorder['IsOpen'] == True:
                                message = '{0}: Made a buyorder, waiting until it is filled! Remaining: {1:.8f} {2}'.format(
                                    thread_name, buyorder['QuantityRemaining'],
                                    currency)
                                messages[thread_name] = message
                                if push_send == False:
                                    try:
                                        send_pushover(pushover_user,
                                                      pushover_app, message)
                                        send_pushbullet(
                                            pushbullet_token, message)
                                        push_send = True
                                    except:
                                        message = 'Unable to send push notification with the buyorder status'
                                        messages[thread_name] = message
                                try:
                                    buyorder = api.getorder(uuid=buy_uuid)
                                except:
                                    message = 'Bittrex API error, unable to check the buyorder: {0}'.format(
                                        buyorder)
                                    messages[thread_name] = message
                                    pass
                                time.sleep(10)
                        buyprice = float(ask)
                        lastprice = 0
                    while True:
                        try:
                            time.sleep(0.5)
                            values = r.hmget(market, 'Ask')
                            ask = float(values[0])
                        except:
                            message = 'Unable to retrieve data from redis.pontstrader.com, trying to recover...'
                            messages[thread_name] = message
                        else:
                            profit_percentage = 100 * (
                                float(ask) - float(buyprice)) / float(buyprice)
                            if float(ask) >= float(target):
                                try:
                                    sell = api.selllimit(
                                        market, amount, target)
                                    sell_uuid = sell['uuid']
                                    time.sleep(0.5)
                                    sellorder = api.getorder(uuid=sell_uuid)
                                    if sellorder['IsOpen'] == True:
                                        while sellorder['IsOpen'] == True:
                                            message = '{0}: Sell target triggered, waiting until the sell order is completely filled! Remaining: {1:.8f}'.format(
                                                thread_name,
                                                sellorder['QuantityRemaining'])
                                            messages[thread_name] = message
                                            try:
                                                sellorder = api.getorder(
                                                    uuid=sell_uuid)
                                            except:
                                                pass
                                            time.sleep(2)
                                    message = '{0}: {1} SOLD (Target) | Buy price {2:.8f} | Sell price {3:.8f} | Profit {4:.2f}% (excl. fee)'.format(
                                        thread_name, currency, buyprice,
                                        target, profit_percentage)
                                    messages[thread_name] = message
                                    send_pushover(pushover_user, pushover_app,
                                                  message)
                                    send_pushbullet(pushbullet_token, message)
                                    done = True
                                    break
                                except:
                                    message = '{0}: API error: Was unable to create the sellorder... it was cancelled due to:\n{1}'.format(
                                        thread_name, sell)
                                    messages[thread_name] = message
                                    send_pushover(pushover_user, pushover_app,
                                                  message)
                                    send_pushbullet(pushbullet_token, message)
                                    done = True
                                    break
                            elif float(ask) <= float(stoploss):
                                try:
                                    sell = api.selllimit(
                                        market, amount, stoploss)
                                    sell_uuid = sell['uuid']
                                    time.sleep(0.5)
                                    sellorder = api.getorder(uuid=sell_uuid)
                                    if sellorder['IsOpen'] == True:
                                        while sellorder['IsOpen'] == True:
                                            message = '{0}: Stop Loss triggered, waiting until the sell order is completely filled! Remaining: {1:.8f}'.format(
                                                thread_name,
                                                sellorder['QuantityRemaining'])
                                            messages[thread_name] = message
                                            try:
                                                sellorder = api.getorder(
                                                    uuid=sell_uuid)
                                            except:
                                                pass
                                            time.sleep(2)
                                    message = '{0}: {1} SOLD (Stop Loss) | Buy price {2:.8f} | Sell price {3:.8f} | Loss {4:.2f}% (excl. fee)'.format(
                                        thread_name, currency, buyprice,
                                        stoploss, profit_percentage)
                                    messages[thread_name] = message
                                    send_pushover(pushover_user, pushover_app,
                                                  message)
                                    send_pushbullet(pushbullet_token, message)
                                    done = True
                                    break
                                except:
                                    message = '{0}: API error: Was unable to create the sellorder... it was cancelled due to:\n{1}'.format(
                                        thread_name, sell)
                                    messages[thread_name] = message
                                    send_pushover(pushover_user, pushover_app,
                                                  message)
                                    send_pushbullet(pushbullet_token, message)
                                    done = True
                                    break
                            else:
                                message = '{0}: {1} | Buy price {2:.8f} | Price {3:.8f} | Target: {4:.8f} | Profit {5:.2f}% (excl. fee)'.format(
                                    thread_name, currency, buyprice, ask,
                                    target, profit_percentage)
                                messages[thread_name] = message

                if done == True:
                    break