コード例 #1
0
def handler():
    msg = request.args['Body'].lower().strip()
    client_num = request.args['From']
    # when using notifications.send_sms() method, remember that From and To args received are reversed when message sent

    sql.update_database(client_num, msg)

    if msg.lower().strip() == "update":
        update(client_num)
    elif msg == "register":
        txt = f"You will now receive updates in the morning if it snows overnight " \
              f"on the Vancouver local mountains.\n" \
              f"You can stop it at any moment by sending 'unregister' to this number."
        notifications.send_sms(txt, client_num)
    elif msg == "unregister":
        txt = f"You will stop receiving automatic updates. You can always reactivate the service by sending 'register'."
        notifications.send_sms(txt, client_num)
    elif msg == "remove":
        txt = f"Your phone number has been successfully removed from the database."
        notifications.send_sms(txt, client_num)
    elif msg == "information":
        txt = f"Here are the keywords you can use:\n" \
               "'update': you will receive the current status on the mountain.\n\n" \
               "'register': you will be registered for morning texts if fresh snow on the local mountain.\n\n" \
               "'unregister': you will not receive morning texts anymore.\n\n" \
               "'information': lists all available keywords and their effect."
        notifications.send_sms(txt, client_num)
    else:
        txt = f"Sorry buddy, the only keywords accepted are 'update', 'register' and 'unregister'.\n" \
               "If it's your first time using the app, send 'information' for more insight on the keywords effects."
        notifications.send_sms(txt, client_num)

    return ''  # Flask needs a return str
コード例 #2
0
def get_balance_total():
    balanceinfo = None
    apitry = 0
    while not balanceinfo and apitry < apitrylimit:
        try:
            balanceinfo = bitmex.fetch_balance()
        except Exception as err:
            balanceinfo = None
            log.warning("Failed to get balance, trying again")
            log.warning(err)
            time.sleep(apisleep)
            apitry = apitry + 1

    if apitry == apitrylimit:
        send_sms("Failed to get balance, API tries exhausted!")
        return 0
    else:
        return balanceinfo['total']['BTC']
コード例 #3
0
def report_trade(action, ordersize, stacked, price):
    report_string = "action: %s\tordersize: %d\tstacked: %d\tprice: %.2f" % (
        action, ordersize, stacked, price)
    tl.info(report_string)
    log.debug(report_string)
    send_sms(report_string)
コード例 #4
0
def m15hist_positive(exchgdata):
    # m15 for the div detection
    (t, o, h, l, c, v) = exchgdata.get_split_tohlcv('15m', 34)
    exchgdata.dprint_last_candles('15m', 5)
    (m15kvo, m15signal) = klinger_kama(h, l, c, v)
    m15hist = m15kvo[-1] - m15signal[-1]
    log.info("m15hist is %.2f" % m15hist)
    positive = True
    if m15hist <= 0:
        positive = False
    return positive


sleeptime = 30

send_sms('Trading Bot Active!')

# main loop
bfxdata = ExchgData.ExchgData('bfx')

last_hist_positive = m15hist_positive(bfxdata)
hist_positive = last_hist_positive

while [1]:
    log.debug("Main loop")
    mexorders.update_bracket_pct(config.sl, config.tp)

    hist_positive = m15hist_positive(bfxdata)

    shorts = mexorders.get_position_size('short')
    longs = mexorders.get_position_size('long')
コード例 #5
0
            if resort['24']:
                txt = f"{txt}\n{resort['24']}cm last 24h"
            if resort['info']:
                txt = f"{txt}\nSPECIAL NOTICE: {resort['info']}"
        txt = f"{txt}\n******************"

    return txt


# This entry point is ran only in the morning for registered numbers
if __name__ == "__main__":
    fresh_snow = False
    registered_numbers = sql.query_registered_numbers()

    cache_resorts_list = cache.get()

    # pop out the non local resorts from the list
    cache_resorts_list = [
        resort for resort in cache_resorts_list if resort['local']
    ]

    for resort in cache_resorts_list:
        if resort['12'] and int(
                resort['12']) > 0:  # Mt Seymour doesnt have a 12h snow report
            fresh_snow = True

    if fresh_snow:
        txt = prettify_data(cache_resorts_list)
        for number in registered_numbers:
            notifications.send_sms(txt, number)
コード例 #6
0
    #sellabove  =  1000
    sellabove = vwap

    # if 1d kvo has flipped, flip positions
    if curr_hist_positive and not last_hist_positive:
        if last < buybelow:
            if shorts > longs:
                entryprice = mexorders.get_positions()[0]['avgCostPrice']
                breakEvenPrice = mexorders.get_positions()[0]['breakEvenPrice']
                if breakEvenPrice - last > 15:
                    mexorders.cancel_open_orders()
                    time.sleep(1)
                    #mexorders.smart_order('Buy', shorts+config.ordersize)
                    send_sms("%s %s %s %s %s" % (                                                    \
                                ("\nBuy signal!! KVO flipped positive and price is: " + str(last)),    \
                                (". VWAP is: " + str(vwap)),                                         \
                                (".\nCurrently net short with Average entry: "+ str(entryprice)),    \
                                (" and Breakeven at " + str(breakEvenPrice)),                        \
                                (".\nClosing short in profit and Going Long")))
                    #report_trade("Closing short and Going Long", shorts+config.ordersize, longs+config.ordersize, last)
                else:
                    send_sms("%s %s %s %s %s" % (                                                    \
                                ("\nBuy signal!! KVO flipped positive and price is: " + str(last)),    \
                                (". VWAP is: " + str(vwap)),                                         \
                                (".\nUnderwater short with Average entry: "+ str(entryprice)),       \
                                (" and Breakeven at " + str(breakEvenPrice)),                        \
                                (".\nSo not going long yet.")))
            else:
                mexorders.cancel_open_orders()
                time.sleep(1)
                #mexorders.smart_order('Buy', shorts+config.ordersize)
                if longs == 0:
コード例 #7
0
def update(to_num):
    result = check_snow()
    txt_message = pretify_data(result)
    notifications.send_sms(txt_message, to_num)
コード例 #8
0
def update(to_num):
    cache_resorts_list = cache.get()
    txt_message = prettify_data(cache_resorts_list)
    notifications.send_sms(txt_message, to_num)