Answer the question
In order to leave comments, you need to log in
Are the buying and selling functions of the BINANCE API correct?
This piece of code provides a function with commands to sell and buy cryptocurrency.
Do not look at the algorithm of actions) I am interested in whether the sell and buy commands are written correctly.
It seems that I wrote everything according to the dock, the first argument is a trading pair, the second is the number of crypt units for EUR.
It's scary to check the code, because it's not a test one) Knowledgeable people explain what's what? Maybe there is a good guide for these commands.
# Рынок
ASSET = 'DOGEEUR'
# Торгуемая валюта
CURRENCY = 'EUR'
# Торгуемая криптовалюта
CRYPTOCURRENCY = 'DOGE'
SIGNAL = 1
''' П о к у п к а '''
def order_market_buy(quantity):
order = client.order_market_buy(symbol=ASSET, quantity=quantity)
''' П р о д а ж а '''
def order_market_sell(quantity):
order = client.order_market_sell(symbol=ASSET, quantity=quantity)
def stocks(FIRST_PRICE):
# Функция обрезает число до n кол-во символов(Нужна чтобы при покупки и продажи не возникло ошибки)
def toFixed(f: float, n=0):
a, b = str(f).split('.')
return '{}.{}{}'.format(a, b[:n], '0'*(n-len(b)))
global SIGNAL
if SIGNAL == 1:
#ПОКУПКА КРИПТОВАЛЮТЫ
order_market_buy("DOGEEUR", toFixed(float(balance(CURRENCY)['free']) / price(ASSET)))
SIGNAL = 0
elif SIGNAL == 0
#ПРОДАЖА КРИПТОВАЛЮТЫ
order_market_sell("DOGEEUR", toFixed(float(balance(CRYPTOCURRENCY)['free'])))
SIGNAL = 1
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question