CyberPunkMetalHead / Binance-volatility-trading-bot

This is a fully functioning Binance trading bot that measures the volatility of every coin on Binance and places trades with the highest gaining coins If you like this project consider donating though the Brave browser to allow me to continuously improve the script.
MIT License
3.39k stars 774 forks source link

Coin Price Recorded doesn't match Actual Price of Coin Purchased at after Order Execution by Binance #209

Open celltronic01 opened 3 years ago

celltronic01 commented 3 years ago

Hi, I have an issue or 2. Please, if someone could look into this for me. Not a Python Savvy here.

  1. Trades.txt is recording everything twice
  2. When an order is sent, it records the buy/sell price at the price the order is sent but by the time the order is executed by binance, the price is different. for example: lets take SOL. The bot sends the order for 2 SOL for 65.476 and records the coin buy with bouth at price in coins.json and trades.txt at 65.476. However, by the time the trade was received and executed by binance, it was actually purchased at 66.774 which actually is a problem because bot is thinking it was bought at 65.476 and calculates the take profit percentage at recorded price which is not the actual price at which the order was actually exacuted
bassdeth1 commented 4 months ago

`def update_portfolio(orders): for coin in orders: if orders[coin]['status'] == 'FILLED' and float(orders[coin]['executedQty']) > 0: buy_price = float(orders[coin]['cummulativeQuoteQty']) / float(orders[coin]['executedQty']) else: buy_price = 0 # En caso de que no se ejecute ninguna parte de la orden

    volume = float(orders[coin]['executedQty'])
    coins_bought[coin] = {
        'symbol': orders[coin]['symbol'],
        'orderid': orders[coin]['orderId'],
        'timestamp': orders[coin]['time'],
        'bought_at': buy_price,
        'volume': volume,
        'stop_loss': -STOP_LOSS,
        'take_profit': TAKE_PROFIT,
        'buy_price': buy_price,
    }
    with open(coins_bought_file_path, 'w') as file:
        json.dump(coins_bought, file, indent=4)
    print(f'Orden con id {orders[coin]["orderId"]} actualizada y guardada en el archivo')`