Пример #1
0
def test_get_currency_v1(ticker):
    print(ticker)
    if ticker == "all":
        print(list(m.currencies.find({})))
        return jsonify(list(transform_cursor(m.currencies.find({}))))
    else:
        print(transform_cursor(m.currencies.find({"currency": ticker}))[0])
        return jsonify(transform_cursor(m.currencies.find({"currency": ticker}))[0])
Пример #2
0
def map_trade(ticker):
    signals = transform_cursor(
        s.find({
            "ticker": ticker[0],
            "interval": str(ticker[1])
        }))
    currencies = transform_cursor_dict(c.find_one({"currency":
                                                   ticker[0][:-3]}))
    btc = transform_cursor_dict(c.find_one({"currency": "BTC"}))
    obj = {
        'id': '',
        'symbol': '',
        'action': '',
        'timeframe': '',
        'date': '',
        'duration': '',
        'price': 0.00,
        'current_price': 0.00,
        'current_profit': 0.00,
        '1d': 0.00,
        '7d': 0.00,
        '30d': 0.00
    }
    if len(signals) > 0 and len(currencies) > 0:
        od = sorted(signals, key=lambda k: k['time'], reverse=True)
        x = od[0]
        obj['id'] = x['ticker'] + x['interval']
        symbol = x['ticker'].replace('XBT', 'BTC')
        if x['ticker'][-3:] == "BTC":
            currencies['price'] = float(currencies['price']) / float(
                btc['price'])
        obj['symbol'] = symbol
        obj['action'] = x['action']
        obj['timeframe'] = x['interval']
        obj['date'] = x["time"][:19].replace('T', ' ')
        date_now = parser.parse(datetime.now().isoformat()[:19].replace(
            'T', ' '))
        date_signal = parser.parse(x["time"][:19].replace('T', ' '))
        obj['duration'] = str(abs(date_now - date_signal))
        obj['price'] = float(x['price'])
        obj['current_price'] = float(currencies['price'])
        val = ((float(currencies['price']) - float(x['price'])) /
               float(x['price'])) * 100.00
        if x['action'] == "buy":
            obj['current_profit'] = float(val)
        else:
            obj['current_profit'] = float(val * -1)
        obj['1d'] = float(currencies['1d']["price_change_pct"]) * 100
        obj['7d'] = float(currencies['7d']["price_change_pct"]) * 100
        obj['30d'] = float(currencies['30d']["price_change_pct"]) * 100
        print(obj)
        t.update_one({"id": obj['id']}, {"$set": obj})
    return
Пример #3
0
async def run2():
    async for (symbol, ticker) in run_map_trade([["BTCUSD", 480],
                                                 ["BTCUSD",
                                                  720], ["BTCUSD", 1],
                                                 ["ETHUSD", 720],
                                                 ["ETHBTC", 720],
                                                 ["LINKUSD", 720],
                                                 ["LINKBTC", 720],
                                                 ["XRPUSD", 720],
                                                 ["LTCUSD", 720],
                                                 ["ADAUSD", 720]]):
        print(symbol, ticker)
    trades_latest = pd.DataFrame.from_dict(transform_cursor(t.find(
        {}))).sort_values(by="date", ascending=False).iloc[:5]
    # print(trades_latest)
    tl.delete_many({})
    tl.insert_many(json.loads(trades_latest.T.to_json()).values())
    trades_best = pd.DataFrame.from_dict(transform_cursor(t.find(
        {}))).sort_values(by="current_profit", ascending=False).iloc[:5]
    # print(trades_best)
    tb.delete_many({})
    tb.insert_many(json.loads(trades_best.T.to_json()).values())
Пример #4
0
def home():
    symbol = request.args.get('symbol')
    interval = request.args.get('interval')
    action = request.args.get('action')
    timespan = request.args.get('timespan')
    signal = []

    if symbol is None:
        symbol = "ETHUSD"
    if interval is None:
        interval = "720"
    if action is None:
        action = "buy_sell"
    if timespan is None:
        timespan = "0"

    if action == "buy_sell":
        signal = m.signals.find({"ticker": symbol, "interval": interval})
    else:
        signal = m.signals.find({"ticker": symbol, "interval": interval, "action": action})

    signal = transform_cursor(signal)

    if timespan != "0":
        date_now = parser.parse(datetime.now().isoformat()[:19].replace('T', ' '))
        new_signal = []
        for x in signal:
            if abs(date_now - parser.parse(x["time"][:19].replace('T', ' '))).days < int(timespan):
                new_signal.append(x)
        signal = new_signal

    print(transform_cursor_dict(
        m.performance.find_one({"index": symbol + "-" + interval + "-" + action + "-" + timespan})))

    return render_template('pages/placeholder.home.html',
                           args=request.args,
                           trades=m.trades.find(),
                           tl=m.trades_latest.find(),
                           tb=m.trades_best.find(),
                           signal=signal,
                           performance=transform_cursor_dict(m.performance.find_one(
                               {"index": symbol + "-" + interval + "-" + action + "-" + timespan})),
                           performance_sum=transform_cursor_dict(m.performance.find_one({"index": "summary"})),
                           currencies=map_currencies_to_dict(m.currencies.find()),
                           transform_interval=transform_interval)
Пример #5
0
def map_performance(ticker, results=results):
    date_now = parser.parse(datetime.now().isoformat()[:19].replace('T', ' '))

    # for b in ticker:
    ticker_val = str(ticker[0])
    timeframe_val = ticker[1]
    signals = transform_cursor(
        s.find({
            "ticker": ticker_val,
            "interval": str(timeframe_val)
        }))
    currencies = c.find_one({"currency": ticker_val[:-3]})
    signals_ordered = sorted(signals, key=lambda k: k['time'])
    for x in [365, 730, 1825, 0]:
        s_pd = pd.DataFrame.from_dict(signals_ordered)
        results.append(
            backtest(s_pd, currencies, ticker_val, timeframe_val, "buy_sell",
                     x, date_now))
        results.append(
            backtest(s_pd[s_pd.action == "buy"], currencies, ticker_val,
                     timeframe_val, "buy", x, date_now))
        results.append(
            backtest(s_pd[s_pd.action == "sell"], currencies, ticker_val,
                     timeframe_val, "sell", x, date_now))
Пример #6
0
def test_get_signal_v1(ticker):
    if ticker == "all":
        print(list(m.signals.find({})))
        return jsonify(m.signals.find({}))
    else:
        return jsonify(transform_cursor(m.signals.find({"ticker": ticker})))