Ejemplo n.º 1
0
def create_trader():
    try:
        data = request.form.to_dict()
        Log.info(data)
        trader_name = data.pop('trader')
        interval = is_positive_number(int(data.pop('interval')))
        balance = is_positive_number(int(data.pop('balance')))
        currency = data.pop('currency')
        trader_parm = data
    except Exception as e:
        Log.info(e)
        return redirect(url_for('.show_create_trader_page'))

    trader_no = dao.query(
        Trader.trader_no).filter(Trader.name == trader_name).all()[0][0]

    # run_no: auto_increment
    dao.add(
        SimulTraderRunHist(trader_no=trader_no,
                           currency=currency,
                           time_interval=interval,
                           init_balance=balance,
                           trader_parm=trader_parm))
    dao.commit()

    return redirect(url_for('.show_traders'))
Ejemplo n.º 2
0
def stop_trader():
    data = request.json
    Log.info(data)
    end_dt = strftime('%Y/%m/%d %H:%M:%S', localtime())

    g = RUNNING_TRADER.pop(data['run_no'])
    g.kill()

    # update
    dao.query(SimulTraderRunHist.end_dt)\
        .filter(SimulTraderRunHist.run_no == data['run_no'])\
        .update({SimulTraderRunHist.end_dt: end_dt})
    dao.commit()

    return json.dumps({'status': 'OK', 'end_dt': end_dt})
Ejemplo n.º 3
0
def run_trader():
    data = request.json
    Log.info(data)
    # start trader
    start_dt = strftime('%Y/%m/%d %H:%M:%S', localtime())
    Log.debug(start_dt)

    interval = dao.query(SimulTraderRunHist.time_interval).filter(
        SimulTraderRunHist.run_no == data['run_no']).first()[0]

    g = eventlet.spawn(enrollment_trader, rsi_trader_alarm, data['run_no'],
                       interval)
    RUNNING_TRADER[data['run_no']] = g

    # update
    dao.query(SimulTraderRunHist.start_dt) \
        .filter(SimulTraderRunHist.run_no == data['run_no']) \
        .update({SimulTraderRunHist.start_dt: start_dt})
    dao.commit()

    return json.dumps({'status': 'OK', 'start_dt': start_dt})
Ejemplo n.º 4
0
#
#     def __init__(self, trader_no, init_balance, invoke_interval):
#         self.trader_no = trader_no
#         self.cur_balance = init_balance
#         self.init_balance = init_balance
#         self.invoke_interval = invoke_interval
#
#         self.num_of_order = 0
#         self.revenue_rate = 0
#
#         self.create_dt = strftime('%Y/%m/%d %H:%M:%S', localtime())
#         self.update_dt = self.create_dt

if __name__ == '__main__':
    from coincast.database import DBManager

    db_url = 'mysql://*****:*****@49.142.50.199/CC_REAL?charset=utf8'
    DBManager.init(db_url)
    DBManager.init_db()

    from coincast.database import dao

    queries = dao.query(SimulTraderRunHist)
    entries = [
        dict(trader_no=q.trader_no, run_no=q.run_no, interval=q.time_interval)
        for q in queries
    ]
    dao.commit()

    print(entries[:10])