示例#1
0
def detect_exchange(market):
    sql_string = "SELECT exchange FROM exchange WHERE market = '{}'".format(
        market)
    rows = query(sql_string)
    try:
        exchange = rows[0][0]  # first result
    except:
        exchange = 'bittrex'
    return exchange
示例#2
0
def telegram_sell(wf_id = None): 
    global platform_run, cmd_init, chat

    chat.send('Specify the parameters: simulation (s/r/sns/rns/rnts) exchange basic_curr altcoin entry_price TP SL [limit_of_amount_to_sell] [sell_portion] \nExample: s btrx BTC LTC 0.0017 0.0021 0.0019 100')
    # Wait for a response
    msg_text = chat.get_response()

    # Starting a new process with a new task 
    msg_text_split = msg_text.split()
    # Processing params - should all be entered
    try: 
        run_simulation_param = msg_text_split[0].lower()
        run_exchange = msg_text_split[1].lower()   
        run_trade = msg_text_split[2].upper()
        run_currency = msg_text_split[3].upper()
        run_price_curr = msg_text_split[4]
        run_tp = msg_text_split[5]
        run_sl = msg_text_split[6]

        if float(run_tp) < float(run_sl): 
            chat.send('TP trigger less then the SL trigger - reversing these variables') # yes, this happened once
            tmp_targ = run_tp
            run_tp = run_sl
            run_sl = tmp_targ
        
        try:
            run_limit_sell_amount = msg_text_split[7]
        except: 
            run_limit_sell_amount = ''
        try:
            run_sell_portion = msg_text_split[8]
        except: 
            run_sell_portion = ''

        # Run depending on the platform
        if platform_run == 'Windows': 
            cmd_str = cmd_init + ' '.join([run_simulation_param, run_exchange, run_trade, run_currency, run_price_curr, run_tp, run_sl, run_limit_sell_amount, run_sell_portion])
        else: 
            # Nix
            cmd_str = cmd_init + ' '.join([run_simulation_param, run_exchange, run_trade, run_currency, run_price_curr, run_tp, run_sl, run_limit_sell_amount, run_sell_portion]) + '"'
        os.system(cmd_str)
        
        # Check if launched fine  
        chat.send('Launching, hold on...')
        time.sleep(30)
        sql_string = "SELECT job_id FROM jobs WHERE market = '{}-{}'".format(run_trade.upper(), run_currency.upper())
        rows = query(sql_string)

        try: 
            launched_confirmation = rows[0][0]   # first result if existing 
            print '>>> Started a new job on the market {}-{}. Simulation mode: {}'.format(run_trade.upper(), run_currency.upper(), run_simulation_param)
            chat.send('Launched a new bot with these parameters')
        except:
            chat.send('The job was not launched')

    except: 
        chat.send('Not all the mandatory parameters are specified')
示例#3
0
def check_cancel_flag():
    global db, cur, job_id

    keep_running = True
    sql_string = "SELECT abort_flag FROM buys WHERE job_id = '{}'".format(
        job_id)
    rows = query(sql_string)

    try:
        flag_terminate = rows[0][0]  # first result
    except:
        flag_terminate = 0
    if (flag_terminate == 1):
        keep_running = False
    return keep_running
示例#4
0
import sqlite3 as lite
import sys

from sqltools import query_lastrow_id, query  # proper requests to sqlite db

request = "SELECT * FROM user_info"
rows = query(request)
for elem in rows:
    print(elem)
示例#5
0
# New logger
logger = logfile(market, 'buy')


### Lprint ####
def lprint(arr):
    msg = ' '.join(map(lambda x: '' + str(x), arr))
    logger.write(msg)
    print msg


########### Check if this is a part of workflow ######################################
sql_string = "SELECT wf_id, run_mode FROM workflow WHERE market = '{}'".format(
    market)
rows = query(sql_string)
try:
    wf_id = rows[0][0]  # first result if existing
    wf_run_mode = rows[0][1]
    lprint(["Workflow:", wf_id, wf_run_mode])
except:
    wf_id = None
    wf_run_mode = None

#############################################################################


def check_cancel_flag():
    global db, cur, job_id

    keep_running = True
import argparse
from sqltools import query_lastrow_id, query        # proper requests to sqlite db

# Parse custom params if there are any
parser = argparse.ArgumentParser()
parser.add_argument('--userid', type=int, help="User id (telegram")
parser.add_argument('--name', type=str, help="User name")
args, unknown = parser.parse_known_args()
user_id = getattr(args, 'userid')
name = getattr(args, 'name')

# Add the user
sql_string = "INSERT INTO user_info(userid, name) VALUES ({}, '{}')".format(user_id, name)
query(sql_string)

sql_string = "INSERT INTO user_params(userid, param_name, param_val) VALUES ({}, '{}', {})".format(user_id, 'margin', 5)
query(sql_string)

print 'Added'
示例#7
0
import sqlite3 as lite
import sys

from sqltools import query_lastrow_id, query  # proper requests to sqlite db

print("\n\n\n\n")

for elem in ['workflow', 'bback', 'buys', 'jobs']:
    request = "DELETE FROM {}".format(elem)
    print(request)
    query(request)

print("Done")
示例#8
0
            exit(0)
        
        ####### Status 
        elif msg_text.find('status') >= 0: 
            no_profit_tasks = False 
            no_buy_tasks = False 
            no_longs = False 
            no_bb_tasks = False
            
            reply_string = '' 
            # Info from the DB - profit jobs
            # DB: id, market, tp, sl, simulation, mooning, selling, price_curr, percent_of, abort_flag
            reply_string_profit = '>> SELL\n' 
            
            sql_string = "SELECT * FROM jobs"
            rows = query(sql_string)

            if rows == []: 
                no_profit_tasks = True
                #chat.send('No active tasks')
            else:
                for row in rows:
                    re_market = row[1]
                    re_tp = row[2]
                    re_sl = row[3]
                    re_simulation = row[4]
                    stop_loss = row[10]
                    if bool(re_simulation) == True: 
                        if bool(stop_loss) == True: 
                            re_simulation = '(Simulation, SL)'
                        else: