Forums

Binance Package error

I installed binance but they say binance is not a package

import requests
from binance.client import Client
import json

# Binance API credentials
api_key = "Nxpf7HhdxXCcoqsIu6FWjS6H6CCajmP3S862Fx63V9vj6NscLVoNrGsGg8TQ"
api_secret = "Nxpf7HJEM7hdxXCcoqsIu6FWjS6H6CCajmP3S862Fx63VoNrGsGg8TQ"

# Telegram bot credentials
bot_token = "524488488:AAEvZRT9PgPrf5kMrFlBNkk7HV9rFUIUsE"
chat_id = "522019312"

# Initialize Binance client
client = Client(api_key, api_secret)

# Function to send message to Telegram
def send_telegram_message(message):
    url = f"https://api.telegram.org/bot{bot_token}/sendMessage"
    data = {"chat_id": chat_id, "text": message}
    requests.post(url, data=data)

# Load previous loss amount
try:
    with open("previous_loss.json", "r") as file:
        data = json.load(file)
        previous_loss = data["previous_loss"]
except FileNotFoundError:
    previous_loss = 0

# Fetch closed trades
trades = client.get_my_trades()

# Calculate profit/loss for closed trades
profit_trades = [trade for trade in trades if trade["isBuyer"] == False]
profit = sum([float(trade["qty"]) * float(trade["price"]) for trade in profit_trades])

# Calculate current loss
current_loss = sum([float(trade["qty"]) * (float(trade["price"]) - float(trade["commission"])) for trade in trades if trade["isBuyer"]])

# Send notification for trades closed in profit
if profit_trades:
    send_telegram_message(f"Trades closed in profit. Total profit: ${profit:.2f}")

# Check if the loss exceeds $3 or changes by $3
loss_change = abs(current_loss - previous_loss)
if loss_change >= 3:
    send_telegram_message(f"Current loss: ${current_loss:.2f}")
    previous_loss = current_loss

# Save the current loss for the next check
with open("previous_loss.json", "w") as file:
    json.dump({"previous_loss": previous_loss}, file)

Do you have any directories or files called "binance"?

Tengo el mismo error

If you've installed into a virtualenv, make sure that you have activated it in the command.

eg: workon vnenv && python ./path/to/script.py