예제 #1
0
def check_pump():
    print("Looking for Buy Opportunities...")
    threading.Thread(target=check_sell).start()
    while True:
        try:
            open_orders = db.query(Trade).all()
            for symbol in symbols:
                r2 = requests.get(
                    "https://api.binance.com/api/v1/ticker/24hr?symbol=" +
                    symbol).json()
                prices[symbol] = '{0:.8f}'.format(
                    round(float(r2['lastPrice']), 8))
                pct_change = float(r2['priceChangePercent'])
                if round(float(prices[symbol]), 8) < float(prices[symbol])*(1 + expected_change_buy/100) \
                        and pct_change > expected_change_buy:
                    # print(pct_change, expected_change_buy)
                    current_symbol = symbol
                    if current_symbol not in open_orders:
                        min_price, min_Qty = calculate_min(current_symbol)
                        temp_price = float(
                            prices[symbol]) * final_buy_price_change
                        final_buy_price = temp_price - (temp_price %
                                                        float(min_price))
                        temp_quantity = buy_quantity_btc / float(
                            final_buy_price)
                        quantity = round((temp_quantity -
                                          ((temp_quantity % float(min_Qty)))),
                                         8)
                        try:
                            trade = Trade.find(symbol)
                            if trade is None:
                                order = client.order_limit_buy(  # Place order for buy
                                    symbol=current_symbol,
                                    recvWindow=1000,
                                    quantity='{0:.3f}'.format(float(quantity)),
                                    price='{0:.8f}'.format(
                                        float(final_buy_price)))
                                print("Buy: " + symbol + ' at: ' +
                                      str('{0:.8f}'.format(
                                          float(prices[symbol]) *
                                          final_buy_price_change)) + " from " +
                                      str(prices[symbol]) +
                                      " Due to change % " + str(pct_change))
                                trade = Trade.get_or_create(symbol)
                                trade.price = str('{0:.8f}'.format(
                                    float(prices[symbol])))
                                trade.orderId = order['orderId']
                                trade.quantity = str('{0:.3f}'.format(
                                    float(quantity)))
                                db.commit()
                                check_buy_status(symbol)
                            else:
                                continue
                        except Exception as e:
                            # print(e)
                            pass
                time.sleep(5)

        except Exception as e:
            print(e)
예제 #2
0
def modify(signal, volume, pair):
    try:
        setup = Trade.find(pair)
        if setup.nonce is not None:
            trade = 'TRADE|MODIFY|' + signal + '|' + pair + '|0|' + STOPLOSS + '|' + TAKEPROFIT + \
                    '|IcarusBot Trade|' + setup.nonce + '|' + volume
            s.send_string(trade, encoding='utf-8')
            log("Waiting for metatrader to respond...")
            m = s.recv()
            log("Reply from server " + m.decode('utf-8'))
    except Exception as e:
        log(e)
예제 #3
0
def readmail(volume):
    time.sleep(1.5)
    m = imaplib.IMAP4_SSL(imap)
    m.login(user, pwd)
    m.select('"' + folder + '"')
    resp, items = m.search(None, "NOT SEEN SUBJECT tradingview")
    items = items[0].split()
    for emailid in items:
        resp, data = m.fetch(emailid, "(RFC822)")
        email_body = data[0][1]
        mail = email.message_from_bytes(email_body)
        ts = time.time()
        st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
        nonce = generate_nonce()
        direction = mail['Subject'].split()[3]
        if direction == "Buy":
            signal = "0"
        else:
            signal = "1"
        pair = mail['Subject'].split()[2]
        try:
            if "Close" not in direction:
                setup = Trade.get_or_create(pair)
                m.store(emailid, '+FLAGS', '\Seen')
                log(st + ' ' + direction + ' Triggered on ' + pair)
                if hedging == "0":
                    if setup.nonce is not None:
                        cnr(signal, volume, pair, nonce)
                    else:
                        trade(signal, volume, pair, nonce)
                else:
                    trade(signal, volume, pair, nonce)
            # Close Trade
            else:
                direction = mail['Subject'].split()[4]
                setup = Trade.find(pair)
                if setup is not None:
                    if setup.signal == direction:
                        m.store(emailid, '+FLAGS', '\Seen')
                        close(signal, volume, pair)
                        log(st + " Closed trade on " + pair)
        except Exception as e:
            log(e)
예제 #4
0
def trade(signal, volume, pair, nonce):
    try:
        trade = 'TRADE|OPEN|' + signal + '|' + pair + '|0|' + STOPLOSS + '|' + TAKEPROFIT + \
                '|IcarusBot Trade|' + nonce + '|' + volume
        s.send_string(trade, encoding='utf-8')
        log("Waiting for metatrader to respond...")
        m = s.recv()
        log("Reply from server " + m.decode('utf-8'))
        if signal == "0":
            direction = 'Long'
        else:
            direction = 'Short'
        setup = Trade.find(pair)
        setup.nonce = nonce
        setup.signal = direction
        db.flush()
        # print(setup)
        if pair == "SPX500":
            trade(signal, volume, "DJI30", generate_nonce())
            log('Sell' + ' Triggered on ' + "DJI30")
    except Exception as e:
        log(e)