错误 "symbol" 币安 Api
Wrong "symbol" Binance Api
我正在尝试制作一个简单的交易机器人来在 Binance 上进行交易。
当机器人尝试下订单时,它没有通过,我收到以下错误:
“BinanceAPIException:APIError(代码=-1121):无效符号。”
据我所知,我有正确的以太坊和 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()
错误在这一行 TRADE_SYMBOL = 'ETHUSD'
。您需要将其更改为 ETHUSDT
我正在尝试制作一个简单的交易机器人来在 Binance 上进行交易。
当机器人尝试下订单时,它没有通过,我收到以下错误: “BinanceAPIException:APIError(代码=-1121):无效符号。”
据我所知,我有正确的以太坊和 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()
错误在这一行 TRADE_SYMBOL = 'ETHUSD'
。您需要将其更改为 ETHUSDT