def market_order(trade): my_logger = pymt5.get_logger(loglevel=logging.DEBUG, path_to_logfile='./logfile.txt') with pymt5.connected( ensure_trade_enabled=True, enable_real_trading=True, ) as conn: symbol = MySymbol.get_symbol(trade.symbol) # alt constructor order = order_method(trade.direction)( volume=0.01, expiration=pymt5.ORDER_TIME.DAY, symbol=symbol.name, server='AAFX-DEMO', login=9015, password='******', logger=my_logger ) res = order.send() retcode = pymt5.TRADE_RETCODE(res.retcode) if retcode is pymt5.TRADE_RETCODE.DONE: print('done') return res.order else: print('trade error', pymt5.trade_retcode_description(retcode))
def my_handler(client, message): chatroom_name = message.chat.title if not chatroom_name or (SIGNAL_CHANNEL_PREFIX not in chatroom_name): # print(f"Message is not in {SIGNAL_CHANNEL_PREFIX}. Not parsing message.") return print(f"Relevant Message Received={message}") result = channel.olafemi.parse(message.text) print(f"Parse result={result}") with pymt5adapter.connected(enable_real_trading=True, debug_logging=True): trade = myMT5.myMT5() trade.both_pending_orders(result['action'], LOT_SIZE, result['symbol'], result['entry'], result['stoploss'], result['takeprofit'])
from pymt5adapter.symbol import Symbol import pymt5adapter class MySymbol(Symbol): pass with pymt5adapter.connected(enable_real_trading=True, debug_logging=True): symbol_str = 'AUDUSD' print(f"{symbol_str}") s = MySymbol(symbol_str) print("hi there") print(s, type(s))
o = Order.as_buy_stop(symbol=symbol, volume=LOT, price=entry, stoplimit=entry, sl=sl, tp=tp, deviation=deviation, type_filling=mt5.ORDER_FILLING_FOK) r = o.send() print(r) def buy_limit(): symbol_str = 'EURUSD' symbol = MySymbol(symbol_str) entry = symbol.ask - symbol.pips(50) print(f"Entry {entry}") sl = entry - symbol.pips(10) tp = entry + symbol.pips(10) deviation = 20 o = Order.as_buy_limit(symbol=symbol, volume=LOT, price=entry, stoplimit=entry, sl=sl, tp=tp, deviation=deviation, type_filling=mt5.ORDER_FILLING_FOK) r = o.send() print(r) if __name__ == '__main__': with pymt5adapter.connected(enable_real_trading=True): buy_stop() buy_limit()