コード例 #1
0
def start():
    """
    Returns the data of the market based on the strategy that is chosen.
    This function initializes the bot

    :rtype: dict
    :return: the ask price of market and the high and low band percentages
    """
    first_currency = request.form.get('first_currency')
    second_currency = request.form.get('second_currency')
    buy_strategy =  request.form.get('buy_strat')
    sell_strategy = request.form.get('sell_strat')
    amount = request.form.get('amount')
    buy_level = request.form.get('buy_level')
    sell_level = request.form.get('sell_level')

    current_balance = get_wallet_currency_balance(first_currency)


    if first_currency == 'USD':
        first_currency = 'USDT'

    if second_currency == 'USD':
        second_currency = 'USDT'


    market = first_currency + '-' + second_currency
    ticker = bit.get_ticker(market)

    if buy_strategy == 'Bollinger Bands':
        band_limit = bollinger_bands(market,request.form.get('high_band'),request.form.get('low_band'))
        json = {'band_limit': band_limit,'ask': ticker['result']['Ask'], 'last_bid': ticker['result']['Bid']}
    if buy_strategy == 'Percent Gain':
        percents = percent_change(market, request.form.get('gain_buy_level'), request.form.get('gain_sell_level'))
        json = {'percents': percents, 'ask': ticker['result']['Ask'], 'last_bid': ticker['result']['Bid']}


    if sell_strategy == 'Bollinger Bands':
        band_limit = bollinger_bands(market,request.form.get('high_band'),request.form.get('low_band'))
        json = {'band_limit': band_limit,'ask': ticker['result']['Ask'], 'last_bid': ticker['result']['Bid']}
    if sell_strategy == 'Percent Gain':
        percents = percent_change(market, request.form.get('gain_buy_level'), request.form.get('gain_sell_level'))
        json = {'percents': percents, 'ask': ticker['result']['Ask'], 'last_bid': ticker['result']['Bid']}





    #TODO: Perform check for values
    # if  json['ask'] >= json['band_limit']['high']:
    #     return 'sell'
    # elif json['ask'] <= json['band_limit']['low']:
    #     return 'buy'
    # else:
    #     return 'keep running bot'

    return jsonify(json)
コード例 #2
0
def get_current_price():
    market = request.args.get('market')
    if market == 'USDT':
        return Response('Not Valid'),404
    else:
        # Get last price
        result = bit.get_ticker('USDT-' + request.args.get('market'))
        latest_price = format(result['result']['Last'],'.2f')
        return Response(latest_price)
コード例 #3
0
def start():
    """
    Returns the data of the market based on the strategy that is chosen.
    This function initializes the bot

    :rtype: dict
    :return: the ask price of market and the high and low band percentages
    """
    first_currency = request.form.get('first_currency')
    second_currency = request.form.get('second_currency')
    buy_strategy = request.form.get('buy_strat')
    sell_strategy = request.form.get('sell_strat')

    if first_currency == 'USD':
        first_currency = 'USDT'

    if second_currency == 'USD':
        second_currency = 'USDT'

    market = first_currency + '-' + second_currency

    if buy_strategy == 'Bollinger Bands':
        band_limit = bollinger_bands(market, request.form.get('high_band'),
                                     request.form.get('low_band'))

    ticker = bit.get_ticker('USDT-BTC')

    json = {'band_limit': band_limit, 'ask': ticker['result']['Ask']}

    #TODO: Perform check for values
    # if  json['ask'] >= json['band_limit']['high']:
    #     return 'sell'
    # elif json['ask'] <= json['band_limit']['low']:
    #     return 'buy'
    # else:
    #     return 'keep running bot'

    return jsonify(json)
コード例 #4
0
def percent_change(market, buy_level, sell_level):

    cashInWallet = current_user.wallet.usd_balance
    bitcoin = current_user.wallet.btc_balance

    # Risk (high 90 %, med 40 %, low 10 %)
    risk = .9

    buy_level = int(buy_level)/100
    sell_level = int(sell_level)/100


    # Create crypto currency wallet to store in json
    print('Wallet contains: NAME-', current_user.name, 'CASH-', cashInWallet, 'Bitcoin-', bitcoin)
    print()


    # Get current U.S. Dollar value for bitcoin

    result = bit.get_ticker(market)
    latest_price = format(result['result']['Last'], '.2f')
    initialUSPrice = round(float(latest_price), 2)

    print("Initial Bitcoin Price: ", initialUSPrice)


    cashInWallet = current_user.wallet.usd_balance
    bitcoin = current_user.wallet.btc_balance



    # Grab current BTC US dollar price to see if it's changed
    result = bit.get_ticker(market)
    latest_price = format(result['result']['Last'], '.2f')
    btc_price_json = get_current_price('USD')
    btc_price = btc_price_json['bpi']['USD']['rate_float']
    btc_price = round(btc_price, 2)
    print('Current bitcoin price is:', btc_price)

    # Get Ask Price. Lowest price a trader is will to sell for at the moment
    btc_ask_price = get_ticker('USDT-BTC')
    btc_ask_price = btc_ask_price['result']['Ask']
    print('ask price:', btc_ask_price)

    # Get Bid Price. Highest price a trader is willing to pay for the moment
    btc_bid_price = get_ticker('USDT-BTC')
    btc_bid_price = btc_bid_price['result']['Bid']
    print('bid price:', btc_bid_price)

    # Set sell and buy price
    sellPrice = round(initialUSPrice + (buy_level * initialUSPrice), 2)
    buyPrice = round(initialUSPrice - (buy_level * initialUSPrice), 2)
    print("bot buy price:", buyPrice)
    print("bot sell price", sellPrice)
    print()

    # Price is up by the set percent, but you have no bitcoins to sell...
    if btc_price >= sellPrice and current_user.wallet.btc_balance == 0:
        print("There are", current_user.wallet.btc_balance, "bitcoins in your wallet for sale. Coins will be purchased at",
              buyPrice)

    # Price is up by the set percent and We have bitcoins to sell!!!!
    elif btc_price >= sellPrice and current_user.wallet.btc_balance > 0:
        coins2DollarsAmount = btc2usd(current_user.wallet.btc_balance, btc_bid_price)
        print('We can trade', current_user.wallet.btc_balance, 'bitcoins for', coins2DollarsAmount, 'dollars')

        # Update Wallet with new amount
        current_user.wallet.usd_balance += coins2DollarsAmount
        current_user.wallet.btc_balance = 0

        # Set new Initial price value for U.S. Dollar value for bitcoin
        initialUSPrice_json = get_current_price('USD')
        initialUSPrice = initialUSPrice_json['bpi']['USD']['rate_float']
        initialUSPrice = round(initialUSPrice, 2)
        print('New wallet amount:', 'CASH-', cashInWallet, 'Bitcoin', current_user.wallet.btc_balance)
        print()

    # Price is down by set percent but we have no cash to buy
    elif btc_price <= buyPrice and cashInWallet == 0:
        coins2DollarsAmount = btc2usd(current_user.wallet.btc_balance, btc_bid_price)
        print("There are", cashInWallet,
              "dollars in your wallet for a purchase. If coins are sold at current")
        print("rate you can make", coins2DollarsAmount)
        print()

    # Price is down by set percent and we have cash to buy!!!!
    elif btc_price <= buyPrice and cashInWallet > 0:

        # See how much we would get for our bitcoins at the current rate
        bitcoinAmount = usd2btc(cashInWallet, btc_ask_price)
        print('We can trade', cashInWallet / 4, 'dollars for', bitcoinAmount / 4, 'bitcoins')

        # Update Wallet with new amount
        current_user.wallet.usd_balance = 0
        current_user.wallet.btc_balance += bitcoinAmount

        # Set new Initial price value for U.S. Dollar value for bitcoin
        initialUSPrice_json = get_current_price('USD')
        initialUSPrice = initialUSPrice_json['bpi']['USD']['rate_float']
        initialUSPrice = round(initialUSPrice, 2)
        print('New wallet amount:', 'CASH-', cashInWallet, 'Bitcoin', current_user.wallet.btc_balance)
        print()

    return {'Cash': cashInWallet, 'BTC': bitcoin}