Ejemplo n.º 1
0
def numOrders():  #returns the number of active orders
    result = mt5.orders_total()
    if result == None:
        setLastError("Error on getting orders total")
        return -1
    else:
        return result
Ejemplo n.º 2
0
 def get_pending(self):
     threading.Timer(3.0, self.get_pending).start()
     Trader.no_orders = mt5.orders_total()
     if Trader.no_orders >= 1:
         self._view.pendingOrdersCombo.setEnabled(True)
         new_tickets = Trader.get_pending_tickets()
         current_tickets = [
             self._view.pendingOrdersCombo.itemText(i)
             for i in range(self._view.pendingOrdersCombo.count())
         ]
         if new_tickets != current_tickets:
             difference = list(set(new_tickets) - set(current_tickets))
             if len(current_tickets) < len(new_tickets):
                 for item in sorted(difference):
                     # add item
                     self._view.pendingOrdersCombo.addItem(str(item))
                 Trader.no_orders += len(difference)
             elif len(new_tickets) < len(current_tickets):
                 difference = list(set(current_tickets) - set(new_tickets))
                 for item in difference:
                     # find index
                     index = self._view.pendingOrdersCombo.findText(item)
                     # remove item
                     self._view.pendingOrdersCombo.removeItem(index)
                 Trader.no_orders -= len(difference)
     elif Trader.no_orders == 0:
         current_tickets = [
             self._view.pendingOrdersCombo.itemText(i)
             for i in range(self._view.pendingOrdersCombo.count())
         ]
         for i in range(len(current_tickets)):
             self._view.pendingOrdersCombo.removeItem(i)
         self._view.pendingOrdersCombo.setEnabled(False)
Ejemplo n.º 3
0
 def __init__(self, magic, symbol):
     mt5.initialize()
     self.magic = magic
     self.symbol = symbol
     self.no_orders = mt5.orders_total()
     self.no_positions = mt5.positions_total()
     self.balance = mt5.account_info()._asdict()['balance']
     self.leverage = mt5.account_info()._asdict()['leverage']
     self.order_time = mt5.ORDER_TIME_GTC
     self.order_tt = None
Ejemplo n.º 4
0
def numOrders():  #returns the number of active orders
    if not connected:
        print(
            "In order to use this function, you must be connected to B3. Use function connect()"
        )
        return
    result = mt5.orders_total()
    if result == None:
        setLastError("Error on getting orders total")
        return -1
    else:
        return result
Ejemplo n.º 5
0
def numOrders():
    if not connected:
        print(
            "In order to use this function, you must be connected to the Stock Exchange. Use function connect()"
        )
        return
    result = mt5.orders_total()
    if result is None:
        setLastError("Error on getting orders total")
        return -1
    else:
        return result
Ejemplo n.º 6
0
import MetaTrader5 as mt5
import datetime as dt
import pytz

#____________Initializing Metatrader5____________#
mt5.initialize()
print(f"Module Author: {mt5.__author__}")
print(f"MetaTrader5 module version: {mt5.__version__}")
print(f"MT5 Terminal Build: {mt5.terminal_info().build}")


#__________Pending Order operations_____________#
# Returns total number of pending orders as int
no_of_orders = mt5.orders_total()
print('no of pending orders: {0}'.format(no_of_orders))

# Returns information of passed pending order as a tuple of named tuples, returns all orders if nothing passed.
order = mt5.orders_get()
print('\nOrder info: {0}'.format(order))


#_______Making and viewing an ordered dictionary_______#
if order == None:
    print(f"No Orders, error code={mt5.last_error()}")
else:
    for i in range(len(order)):
        # Converting a namedtuple to an ordered dictionary.
        #._asdict() works with named tuple and not a ordinary tuple.
        k = order[i]._asdict()
        print('\n')
        for j in k:
Ejemplo n.º 7
0
    df_symbol_rates = pd.DataFrame(symbol_rates)
    df_symbol_rates['time'] = pd.to_datetime(df_symbol_rates['time'], unit='s')
    my_symbols_etf_rates[symbol] = df_symbol_rates

# get ticks from - what are TICKS and how this data can be used?
my_symbols_etf_ticks = {}
for symbol in my_symbols_etf:
    symbol_ticks = mt5.copy_ticks_from(symbol, datetime(2020, 5, 18, 0), 100,
                                       mt5.COPY_TICKS_TRADE)
    df_symbol_ticks = pd.DataFrame(symbol_ticks)
    df_symbol_ticks['time'] = pd.to_datetime(df_symbol_ticks['time'], unit='s')
    my_symbols_etf_ticks[symbol] = df_symbol_ticks

# copy ticks range function
timezone = pytz.timezone("Etc/UTC")
my_symbols_etf_ticks = {}
for symbol in my_symbols_etf:
    symbol_ticks = mt5.copy_ticks_range(
        symbol, datetime(2020, 7, 14, 0, tzinfo=timezone),
        datetime(2020, 7, 17, 23, tzinfo=timezone), mt5.COPY_TICKS_ALL)
    df_symbol_ticks = pd.DataFrame(symbol_ticks)
    df_symbol_ticks['time'] = pd.to_datetime(df_symbol_ticks['time'], unit='s')
    my_symbols_etf_ticks[symbol] = df_symbol_ticks

# get total number of active orders
orders = mt5.orders_total()

# get total number of open positions
positions = mt5.positions_total()

mt5.shutdown()
Ejemplo n.º 8
0
import MetaTrader5 as mt5
import datetime as dt
import pytz

#____________Initializing Metatrader5____________#
mt5.initialize()
print(f"Module Author: {mt5.__author__}")
print(f"MetaTrader5 module version: {mt5.__version__}")
print(f"MT5 Terminal Build: {mt5.terminal_info().build}")

#__________Pending Order operations_____________#
no_of_orders = mt5.orders_total(
)  #changed                        #returns total number of pending orders
print('no of pending orders: {0}'.format(no_of_orders))

order = mt5.orders_get(
)  #returns information of passed pending order, returns all if nothing passed
print('\nOrder info: {0}'.format(order))

#_______Making and viewing an orders dictionary_______#
if order == None:
    print(f"No Orders, error code={mt5.last_error()}")
else:
    for i in range(len(order)):
        k = order[i]._asdict(
        )  #._asdict() works with named tuple and not a tuple.
        print('\n')
        for j in k:
            print(f"{j}: {k[j]}")

#____________Calculating required Margin_________________#
Ejemplo n.º 9
0
    "stoplimit":price + 200 * point,
    "deviation": deviation,
    "comment": "python script open",
    "type_time": mt5.ORDER_TIME_GTC,
    "type_filling": mt5.ORDER_FILLING_FOK,
}

# 发送交易请求
result = mt5.order_send(request)
# # 检查执行结果
print("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))


order_total = mt5.orders_total()
print("当前的下单总量 = ",order_total)

 
# display data on the MetaTrader 5 package
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)
 
# establish connection to MetaTrader 5 terminal
if not mt5.initialize():
    print("initialize() failed, error code =",mt5.last_error())
    quit()
 
# check the presence of active orders
orders=mt5.positions_total()
t_orders = mt5.orders_get()