I want the code to get the last price and use it to divide the entered quantity (qty = "entered quantity" / "last price"). Finally, use the quantity to open a short or long order.I have a search bar and an input field for quantity. From the search bar, I can select all the USDT pairs available in Binance Futures. Currently #deneme field gets last price too but it's not working in the end.
from tkinter import *
from operator import truediv
import os
import tkinter
from pickle import TRUE
from tkinter import ttk
from tkinter import messagebox
from tkinter.messagebox import showinfo
from binance.client import Client
####API KEYS
api_key = os.environ.get('binance_api')
api_secret = os.environ.get('binance_secret')
client = Client(api_key, api_secret)
#Ekran
root= Tk()
root.geometry('300x300')
l = Label(root, text="MARKET ORDER")
l.config(font=("MARKET ORDER", 25))
l.pack()
#Bar
l = Label(root, text="Coin Girin")
l.config(font=("Coin Girin", 10))
l.pack()
lst = exchange_info = client.futures_exchange_info()
usdt_pairs = [s['symbol'] for s in exchange_info['symbols'] if 'USDT' in s['symbol']]
print(usdt_pairs)
def search(event):
value = event.widget.get()
if value == '':
combo_box['values'] = usdt_pairs
else:
data = []
for item in usdt_pairs:
if value.lower() in item.lower():
data.append(item)
combo_box['values'] = data
combo_box = ttk.Combobox(root,value=usdt_pairs)
combo_box.set('')
combo_box.pack()
combo_box.bind('<KeyRelease>', search)
#deneme
def show_ticker_info(event=None):
selected_symbol = combo_box.get()
ticker_info = client.futures_ticker(symbol=selected_symbol,timeframe='1m')
ticker_text.config(text=ticker_info['lastPrice'])
root.after(100, show_ticker_info) # update price every 100 milliseconds
ticker_text = Label(root, text="")
ticker_text.pack()
combo_box.bind("<<ComboboxSelected>>", show_ticker_info)
root.after(0, show_ticker_info) # start updating immediately
#qty girme
l = Label(root, text="Miktar Girin")
l.config(font=("Miktar Girin", 10))
l.pack()
qty_entry = Entry(root)
qty_entry.pack()
#Buton SAT
def buttonFunction():
qty = qty_entry.get()
selected_symbol = combo_box.get()
order = client.futures_create_order(symbol=selected_symbol,
side=Client.SIDE_SELL,
type=Client.ORDER_TYPE_MARKET,
leverage=20,
quantity=qty)
if order:
global pop
pop = Toplevel(root)
pop.title("SELL")
pop.geometry("250x150")
pop.config(bg="green")
pop_label = Label(pop, text="ORDER PLACED", bg="black", fg="white")
pop_label.pack(pady=10)
b = Button(root, text="SAT", bg="red", fg="white", command=buttonFunction)
b.config(font=("bas", 18))
b.pack(side=LEFT)
#Buton AL
def buttonFunction2():
selected_symbol = combo_box.get()
qty = qty_entry.get()
order = client.futures_create_order(symbol=selected_symbol,
side=Client.SIDE_BUY,
type=Client.ORDER_TYPE_MARKET,
leverage=20,
quantity=qty)
if order:
global pop
pop = Toplevel(root)
pop.title("BUY")
pop.geometry("250x150")
pop.config(bg="green")
pop_label = Label(pop, text="ORDER PLACED", bg="black", fg="white")
pop_label.pack(pady=10)
b2 = Button(root, text="AL", bg="green", fg="white", command=buttonFunction2,)
b2.config(font=("bas", 18))
b2.pack(side=RIGHT)
root.mainloop()
I cannot test your code. You can modify my example.
Snippet:
import locale
amount = 125000
# set locale to US
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
# format US currency value
US_dollar = locale.currency(amount, grouping=True)
print(US_dollar)
Result: $125,000.00
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.