Неправильный символ Binance Api

Я пытаюсь создать простого торгового бота для торговли на Binance.

Когда бот пытается разместить заказ, он не проходит, и я получаю следующую ошибку: BinanceAPIException: APIError(code=-1121): Invalid symbol.

Насколько я могу судить, у меня правильный тикер для Ethereum и USDT. Я пытался найти ответ в течение нескольких часов, но не могу найти ничего, что помогло бы.

Заранее спасибо за помощь,

Пожалуйста, смотрите код ниже.

import websocket, json, pprint, talib, numpy
import config
import smtplib, ssl
from binance.client import Client
from binance.enums import *


# pip uninstall numpy

#comparing chosen coin with tether
SOCKET = "wss://stream.binance.com:9443/ws/ethusdt@kline_1m"
#RSI candle period
RSI_PERIOD = 14
#Overbought indicator
RSI_OVERBOUGHT = 70
#Oversold indicator
RSI_OVERSOLD = 30
#Trade symbol
TRADE_SYMBOL = 'ETHUSD'
#Amount to buy 
TRADE_QUANTITY = 0.00813
#Closes will be collected in a list
closes = []
#Don't own currency
in_position = False
#Client data
client = Client(config.API_KEY, config.API_SECRET, tld='us')
#Make an order
def order(side, quantity, symbol,order_type=ORDER_TYPE_MARKET):
    try:
        #Sending order to binance
        print("Sending order....")
        #order data
        order = client.create_order(symbol=symbol, side=side, type=order_type, quantity=quantity)
        #print order made
        print("Order completed!!!!")
        print(order)
    #Failed payment
    except Exception as e:
        print("an exception has occured - {}".format(e))
        return False

    return True

#Connection opened   
def on_open(ws):
    print('Opened connection')
#Connection closed   
def on_close(ws):
    print('Closed connection')
    
#Message recieved
def on_message(ws, message):
    global closes, in_position
    
    print('Incoming Message')
    json_message = json.loads(message)
    #Print in readable format
    pprint.pprint(json_message)

    candle = json_message['k']
    #Candle closed
    is_candle_closed = candle['x']
    close = candle['c']

    if is_candle_closed:
        #Print out candle closing data
        print("Candle closed at {}".format(close))
        closes.append(float(close))
        print("Closes: ")
        print(closes)
        #if number of closes is greater than the RSI period
        if len(closes) > RSI_PERIOD:
            #Get array of 14 closes
            np_closes = numpy.array(closes)
            rsi = talib.RSI(np_closes, RSI_PERIOD)
            print("RSI'S calculted so far: ")
            print(rsi)
            #Get the previous RSI DATA
            last_rsi = rsi[-1]
            print("The current RSI: {}".format(last_rsi))
            #if the previous RSI is greater than the overbought limit
            if last_rsi > RSI_OVERBOUGHT:
                if in_position:
                    print("{TRADE_SYMBOL} is OVERBOUGHT, SELLING!!!!!!!")
                    # TRIGGER SELL ORDER
                    order_succeeded = order(SIDE_SELL, TRADE_QUANTITY, TRADE_SYMBOL)
                    #IF SUCCESFULL
                    if order_succeeded:
                        in_position = False
                else:
                    print("NO {TRADE_SYMBOL} owned. DOING NOTHING!!!! ")
             #if the previous RSI is LESS than the oversold limit
            if last_rsi < RSI_OVERSOLD:
                if in_position:
                    print("{TRADE_SYMBOL} is OVERSOLD, but you already own this curreny. DOING NOTHING!!!!!.")
                else:
                    print("{TRADE_SYMBOL} is OVERSOLD, BUYING {TRADE_SYMBOL} !!!!!!!!!")
                    # buy logic
                    order_succeeded = order(SIDE_BUY, TRADE_QUANTITY, TRADE_SYMBOL)
                    #if buy successful
                    if order_succeeded:
                        in_position = True

#Web socket
ws = websocket.WebSocketApp(SOCKET, on_open=on_open, on_close=on_close, on_message=on_message)
#KEEP RUNNING
ws.run_forever()


person KeithNolo    schedule 15.02.2021    source источник


Ответы (1)


Ошибка в этой строке TRADE_SYMBOL = 'ETHUSD'. Вам нужно изменить его на ETHUSDT

person Mike Malyi    schedule 16.02.2021
comment
Это не сработало, спасибо за помощь. - person KeithNolo; 16.02.2021
comment
Ошибка связана с символом заказа. Ваш торговый символ ETHUSD. Если ETHUSDT не помогает, не могли бы вы поместить в свою функцию order следующую строку и показать ее здесь?print(symbol, side, type, quantity) - person Mike Malyi; 17.02.2021
comment
Это сработало, спасибо миллион. Это не работало, пока я не перезагрузил приложение. - person KeithNolo; 18.02.2021