Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
celltronic01 opened this issue Aug 17, 2021 · 1 comment

Comments

@celltronic01
Copy link

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
Copy link

`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')`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants