BINANCE:BTCUSDT   Bitcoin / TetherUS
import MetaTrader5 as mt5

# เชื่อมต่อกับเซิร์ฟเวอร์ MetaTrader 4
if not mt5.initialize():
print("initialize() failed")
mt5.shutdown()

# ดึงราคาปัจจุบันของ EURUSD
symbol = "EURUSD"
rates = mt5.copy_rates_from_pos(symbol, mt5.TIMEFRAME_M1, 0, 1)
if rates is None:
print("copy_rates_from_pos() failed")
mt5.shutdown()

current_price = rates
print("Current price of", symbol, ":", current_price)

# ส่งคำสั่งซื้อ Buy หรือ Sell
action = mt5.ORDER_BUY
lot = 0.1
price = current_price
request = {
"action": action,
"symbol": symbol,
"volume": lot,
"price": price,
"type": mt5.ORDER_TYPE_MARKET,
"deviation": 20,
"magic": 234000,
"comment": "Python bot order",
"type_time": mt5.ORDER_TIME_GTC,
"type_filling": mt5.ORDER_FILLING_FOK
}
result = mt5.order_send(request)
if result.retcode != mt5.TRADE_RETCODE_DONE:
print("order_send() failed with retcode:", result.retcode)
mt5.shutdown()

mt5.shutdown()
Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.