コード例 #1
0
                        pair_name)

                # We receive balances from the exchange in the specified currencies
                balances = {
                    balance['asset']: float(balance['free'])
                    for balance in bot.account()['balances'] if
                    balance['asset'] in [pair_obj['base'], pair_obj['quote']]
                }
                log.debug("Balance {balance}".format(balance=[
                    "{k}: {bal: 0.8f}".format(k=k, bal=balances[k])
                    for k in balances
                ]))
                # If the balance allows you to trade - above the exchange limits and above the specified amount in the settings
                if balances[pair_obj['base']] >= pair_obj['spend_sum']:
                    # We receive information on offers from a glass, in the quantity specified in the settings
                    offers = bot.depth(symbol=pair_name,
                                       limit=pair_obj['offers_amount'])

                    # We take purchase prices(for sales prices, replace bids with asks)
                    prices = [float(bid[0]) for bid in offers['bids']]

                    try:
                        # Calculate the average price from the prices received
                        avg_price = sum(prices) / len(prices)
                        # We bring the average price to the requirements of the exchange for multiplicity
                        my_need_price = adjust_to_step(
                            avg_price, CURR_LIMITS['filters'][0]['tickSize'])
                        # We calculate the number that can be bought, and also bring it to a multiple value
                        my_amount = adjust_to_step(
                            pair_obj['spend_sum'] / my_need_price,
                            CURR_LIMITS['filters'][2]['stepSize'])
                        # If in the end the trading volume is less than the minimum allowed, then we swear and do not create an order
コード例 #2
0
multiplier = -1 if settings['strategy'] == "Long" else 1

print("Получаем настройки пар с биржи")
symbols = bot.exchangeInfo()['symbols']
step_sizes = {symbol['symbol']:symbol for symbol in symbols}
for symbol in symbols:
    for f in symbol['filters']:
        if f['filterType'] == 'LOT_SIZE':
            step_sizes[symbol['symbol']] = float(f['stepSize'])


while True:
    try:
        print('Проверяю пару {pair}, стратегия {strategy}'.format(pair=settings['symbol'], strategy=settings['strategy']))
        # Получаем текущие курсы по паре
        current_rates = bot.depth(symbol=settings['symbol'], limit=5)

        bid=float(current_rates['bids'][0][0])
        ask=float(current_rates['asks'][0][0])

        # Если играем на повышение, то ориентируемся на цены, по которым продают, иначе на цены, по которым покупают
        curr_rate = bid if settings['strategy'] == "Long" else ask
        
        if settings['stop_loss_fixed'] == 0:
           settings['stop_loss_fixed'] = (curr_rate/100) * (settings['stop_loss_perc']*multiplier+100)
 
        print("Текущие курсы bid {bid:0.8f}, ask {ask:0.8f}, выбрана {cr:0.8f} stop_loss {sl:0.8f}".format(
            bid=bid, ask=ask, cr=curr_rate, sl=settings['stop_loss_fixed']
        ))

        # Считаем, каким был бы stop-loss, если применить к нему %
コード例 #3
0
ファイル: bb0102_LOOM.py プロジェクト: urykama/Python
    print('Результат создания ордера', res)
    return res


def fLimits(sy):  # Получаем лимиты пары с биржи
    for elem in limits['symbols']:
        if elem['symbol'] == sy:
            CURR_LIMITS = elem
    return (float(CURR_LIMITS['filters'][0]['tickSize']),
            float(CURR_LIMITS['filters'][2]['stepSize']),
            float(CURR_LIMITS['filters'][3]['minNotional']))

    # Получаем текущие курсы по паре


current_rates = bot.depth(symbol=settings['symbol'], limit=5)
settings['stop_loss_fixed'] = 0.00000213  # float(current_rates['bids'][0][0])
bid0 = (1 + 0.01 * settings['stop_loss_perc']) * settings['stop_loss_fixed']
print('bid0 = = {sl:0.8f}'.format(sl=bid0))
print("settings['stop_loss_fixed'] = = {sl:0.8f}".format(
    sl=settings['stop_loss_fixed']))

i = 0
while i < 6000:
    i += 1
    try:

        if settings['strategy'] == "SELL":
            current_rates = bot.depth(
                symbol=settings['symbol'],
                limit=5)  # Получаем текущие курсы по паре