?
@Leon0402 sagte in Wie python-binance API (richtig) verwenden?:
Geht halt nicht genau auf,
Das ist nicht schlimm. Ich hab es jetzt hinbekommen:
from binance.helpers import round_step_size
from binance.enums import *
from binance import Client
def getStepSize(einfo, symbol):
for s in einfo["symbols"]:
if s["symbol"] == symbol:
for f in s["filters"]:
if f["filterType"] == "LOT_SIZE":
return float(f["stepSize"])
raise Exception("Symbol on einfo not found.")
client = Client(
"",
"")
info = client.get_account()
einfo = client.get_exchange_info()
balances = info["balances"]
prices = client.get_all_tickers()
assets = []
for b in balances:
f = float(b["free"])
if f != 0:
n = b["asset"]
if n == "NFT" or n == "ETHW":
continue
busd = 1.0 if n == "USDT" else float(
next(p for p in prices if p["symbol"] == n+"BUSD")["price"])
sum1 = f + float(b["locked"])
sum2 = round(busd * sum1, 2)
assets.append({
"name": n,
"busd": busd,
"sum1": sum1,
"sum2": sum2
})
assets = sorted(assets, key=lambda d: d["sum2"], reverse=True)
sum3 = sum(d["sum2"] for d in assets)
sum4 = round(sum3 / 6, 2)
print(sum3, sum4)
print(*assets, sep="\n")
assets = list(filter(lambda d: d["name"] != "USDT" and d["sum2"] > 10 and abs(sum4 - d["sum2"]) > 10, assets))
for d in assets:
symbol = d["name"]+"USDT"
if d["sum2"] >= sum4:
print(d)
print(d["name"]+" -> USDT (Sell): " + str(d["sum2"] - sum4) + " $")
amount = (d["sum2"] - sum4) / d["busd"]
amount = round_step_size(amount, getStepSize(einfo, symbol))
print(client.create_test_order(
symbol=symbol,
side=SIDE_SELL,
type=ORDER_TYPE_MARKET,
quantity=amount))
# to avoid negative balance:
sum3 -= 5
sum4 = round(sum3 / 6, 2)
print(sum3, sum4)
for d in assets:
symbol = d["name"]+"USDT"
if d["sum2"] < sum4:
print(d)
print("USDT -> "+d["name"]+" (Buy): " + str(sum4 - d["sum2"]) + " $")
amount = (sum4 - d["sum2"]) / d["busd"]
amount = round_step_size(amount, getStepSize(einfo, symbol))
print(client.create_test_order(
symbol=symbol,
side=SIDE_BUY,
type=ORDER_TYPE_MARKET,
quantity=amount))
Bei create_test_order kann man _test weglassen, dann ist das Ganze scharfgestellt...
War halt "blödes" rechnen mit der step_size...
Danke nochmals