sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
5.98k stars 2.2k forks source link

APIError(code=-1100): Illegal characters found in parameter 'quantity' ! could you help ,please? #1173

Open RamiAlyazedi opened 2 years ago

RamiAlyazedi commented 2 years ago

I wrote a code that buy from Binance Market but i got an issue that i tried to solve it many time but i did not .

this is my code :

import binance.client from binance.client import Client import bot_ram

API keys from bot_ram file

x = bot_ram.Pkey y = bot_ram.Skey

client = Client(api_key=x , api_secret=y)

def positionsize(coin,stop,pair):

#call a coin from binance
asset = coin
balance = client.get_asset_balance(asset=asset)

free = float(balance["free"])
locked = float(balance["locked"])
balance = round(free , 2)

#giving values to bot
Risk_reward = 2
Risk_pct = 1.5
Stop_price = stop
pair = pair_
Entry_price = client.get_avg_price(symbol=pair.upper())
Entry_price = round(float(Entry_price["price"]),5)
#count loss,profit,take_frofit
loss = round((Entry_price - Stop_price),2)
profit = round((loss * Risk_reward),2)
Take_frofit = round((Entry_price + profit),2)

pct_stop_loss = round((((Stop_price / Entry_price)-1)*100),2)
pct_take_profit = round((((Take_frofit/Entry_price)-1)*100),2)

#percentage %
amount_at_risk = (Risk_pct * balance )/ 100
amount_at_risk = round((amount_at_risk),2)

balance_at_risk = round(((amount_at_risk * 100)/ pct_stop_loss),2)

print(" ******************************** ")
print()
print("My balance is :", str(balance))
print("Entry price :", str(Entry_price))
print("Stop loss : ", str(Stop_price))
print("Take profit : ", str(Take_frofit))
print("Balance to Risk :", str(balance_at_risk))
print()
print("************************************")

return balance_at_risk , Entry_price

def buy_market(coin , balance_to_buy , _entry_price): qty = round(balance_to_buy/_entry_price,2) detail = client.order_limit_buy(symbol = coin , quantity= qty)

return detail["origQty"] , detail["cummulativeQuoteQty"] , detail["status"]

coin = input("Enter coin name (enter 'quit' to stop program) :") if (coin != "quit"): if coin.upper() in coin_list :

    avg_price = client.get_avg_price(symbol = coin.upper())
    avg_price = round(float(avg_price["price"]),5)
    print("average price is : ", str(avg_price))
    Stop_loss = input("Enter your stop loss :")
    Stop_loss = float(Stop_loss)
else :
     print()
     print("**************************")
     print("** invalid coin **")
     print("**************************")    

while(coin != "quit"): if coin.upper() in coin_list: cal = position_size(coin = "usdt", stop = Stoploss, pair = coin) balance = cal[0] price = cal[1] decision = input("Do you want to buy ? (Y/N)") if decision == "Y": order_detail = buy_market(coin=coin.upper(), balance_to_buy=balance, _entry_price=price)

         print("Order placed successfully!")
         print()
         print("--------------------------")
         print("Quantity :", order_detail[0])
         print("Amount :", order_detail[1])
         print("Status :", order_detail[2])
         print("--------------------------")
     else:
         print("Order cancelled!")

coin = input("Enter coin name (enter 'quit' to stop program) :")
if (coin != "quit"):
    if coin.upper() in coin_list :

        avg_price = client.get_avg_price(symbol = coin.upper())
        avg_price = round(float(avg_price["price"]),5)
        print("average price is : ", str(avg_price))
        Stop_loss = input("Enter your stop loss :")
        Stop_loss = float(Stop_loss)
    else :
        print()
        print("**************************")
        print("** invalid coin **")
        print("**************************")

and this is the error 👍 File "C:\Users\Rami_Alyazedi\AppData\Local\Programs\Python\Python310\lib\site-packages\binance\client.py", line 324, in _handle_response raise BinanceAPIException(response, response.status_code, response.text) binance.exceptions.BinanceAPIException: APIError(code=-1100): Illegal characters found in parameter 'quantity'; legal range is '^([0-9]{1,20})(.[0-9]{1,20})?$'.