# prepare the buy request structuresymbol = "EURUSD"symbol_info = mt5.symbol_info(symbol)if symbol_info is None: print(symbol, "not found, can not call order_check()") mt5.shutdown() quit()# if the symbol is unavailable in MarketWatch, add itif not symbol_info.visible: print(symbol, "is not visible, trying to switch on") if not mt5.symbol_select(symbol,True): print("symbol_select({}}) failed, exit",symbol) mt5.shutdown() quit()lot = 0.1point = mt5.symbol_info(symbol).pointprice = mt5.symbol_info_tick(symbol).askdeviation = 20request = { "action": mt5.TRADE_ACTION_DEAL, "symbol": symbol, "volume": lot, "type": mt5.ORDER_TYPE_BUY, "price": price, "sl": price - 100 * point, "tp": price + 100 * point, "deviation": deviation, "magic": 234000, "comment": "python script open", "type_time": mt5.ORDER_TIME_GTC, "type_filling": mt5.ORDER_FILLING_RETURN,}# send a trading requestresult = mt5.order_send(request)# check the execution resultprint("1. order_send(): by {} {} lots at {} with deviation={} points".format(symbol,lot,price,deviation));if result.retcode != mt5.TRADE_RETCODE_DONE: print("2. order_send failed, retcode={}".format(result.retcode)) # request the result as a dictionary and display it element by element result_dict=result._asdict() for field in result_dict.keys(): print(" {}={}".format(field,result_dict[field])) # if this is a trading request structure, display it element by element as well if field=="request": traderequest_dict=result_dict[field]._asdict() for tradereq_filed in traderequest_dict: print(" traderequest: {}={}".format(tradereq_filed,traderequest_dict[tradereq_filed])) print("shutdown() and quit") mt5.shutdown() quit()print("2. order_send done, ", result)print(" opened position with POSITION_TICKET={}".format(result.order))print(" sleep 2 seconds before closing position #{}".format(result.order))time.sleep(2)
อ้างจาก: iRuler ที่ 15, กรกฎาคม 2021, 01:44:08 PMขอโทษครับ พอดีไม่ถนัด python เลยครับพอดีไม่เห็นว่าโบร้กเกอร์อะไร อาจเป็นไปได้ว่า ชื่อคู่เงินของโบร้กนี้ไม่ได้ชื่อ EURUSD หรือเปล่าอาจจะเป็น แบบ EURUSDf, EURUSDm อะไรงี้