MetaTrader 5 Python User Group - как использовать Python в Метатрейдере - страница 61

 
Vladimir Perervenko :

Failed to install

Win10, Py3.6.10  and WinPy3.7.7.

Try it again. I had to refactor it to work with Python < 3.8

 
nicholi shen:

Try it again. I had to refactor it to work with Python < 3.8

Ok

Successfully built pymt5adapter
Installing collected packages: pymt5adapter
Successfully installed pymt5adapter-0.2.1
----- Установка "pymt5adapter" выполнена. -

Что нового в релизе?

Удачи

 
Vladimir Perervenko:

Ok

What's new in the release?

Good luck

calendar_events https://github.com/nicholishen/pymt5adapter/blob/master/pymt5adapter/calendar.py

from datetime import datetime
from datetime import timedelta

import pymt5adapter as mt5
from pymt5adapter.calendar import calendar_events
from pymt5adapter.calendar import Currency
from pymt5adapter.calendar import Importance


def forex_symbol(s):
    modes = [mt5.SYMBOL_CALC_MODE_FOREX, mt5.SYMBOL_CALC_MODE_FOREX_NO_LEVERAGE]
    return s.trade_calc_mode in modes


def main():
    symbol = mt5.symbols_get(function=forex_symbol)[0]
    one_week = timedelta(weeks=1)
    now = datetime.now()
    default_one_week_ahead_all_events = calendar_events()
    filtered_by_callback = calendar_events(function=lambda e: 'fed' in e['event_name'].lower())
    filtered_by_flags = calendar_events(importance=Importance.MEDIUM | Importance.HIGH,
                                        currencies=Currency.USD | Currency.JPY)
    filtered_by_strings = calendar_events(importance='medium high',
                                          currencies='usdjpy')
    filtered_by_iterables = calendar_events(importance=('medium', ' high'),
                                            currencies=('usd', 'jpy'))
    filtered_by_specific_times = calendar_events(time_from=now, time_to=now + one_week)
    filtered_by_timedeltas = calendar_events(time_from=(-one_week), time_to=one_week)
    filtered_by_timedelta_lookback = calendar_events(-one_week)
    calendar_events_in_russian = calendar_events(language='ru')

    employment_events_next_month = calendar_events(
        currencies=Currency.USD,
        importance=Importance.HIGH
        function=lambda e: 'employment' in (name:=e['event_name'].lower()) or 'payroll' in name
    )

    next_event = employment_events_next_month[0]

    for k, v in next_event.items():
        print(k, v)


if __name__ == '__main__':
    with mt5.connected():
        main()
nicholishen/pymt5adapter
nicholishen/pymt5adapter
  • nicholishen
  • github.com
A drop-in pythonic adapter for the MetaTrader5 package to enhance usability. - nicholishen/pymt5adapter
 

Добрый день! Как работать с TRADE_ACTION_CLOSE_BY ??? или кто и как закрывает все открытые позиции?

 
9805244:

Добрый день! Как работать с TRADE_ACTION_CLOSE_BY ??? или кто и как закрывает все открытые позиции?

С использованием Python? 

 

Эту строку VS2019(WinPy3.7.7) ругает (подчеркнуто):

"unexpected token 'function' "

unexpected token ':"

unexpected token '='

invalid syntax 

employment_events_next_month = calendar_events(
        currencies=Currency.USD,
        importance=Importance.HIGH
        
function=lambda e: 'employment' in (name
:=e['event_name'].lower()) 
or 'payroll' in name
    )
 
Vladimir Perervenko:

Эту строку VS2019(WinPy3.7.7) ругает (подчеркнуто):

"unexpected token 'function' "

unexpected token ':"

unexpected token '='

invalid syntax 

That's the new assignment expression for python >=3.8, and they're awesome. I had to remove all those from the library to make it work with your version, but I think you can refactor that example script to make it work. You should consider upgrading your python interpreter to the latest version.  :)

https://www.python.org/dev/peps/pep-0572/

PEP 572 -- Assignment Expressions
PEP 572 -- Assignment Expressions
  • www.python.org
PEP: Title: Author: Status: Type: Created: Python-Version: Post-History: Resolution:
 
nicholi shen:

That's the new assignment expression for python >=3.8, and they're awesome. I had to remove all those from the library to make it work with your version, but I think you can refactor that example script to make it work. You should consider upgrading your python interpreter to the latest version.  :)

https://www.python.org/dev/peps/pep-0572/

Не могу. Слишком много пакетов завязаны на 3.7.7 и 3.6.10. 

Просто подскажите чем или как заменить, если возможно. Если нет, не проблема.

Я не знаток Питона. Мой язык R/ 

Удачи.

 
Vladimir Perervenko:

I can not. Too many packages are tied to 3.7.7 and 3.6.10. 

Just tell me what or how to replace, if possible. If not, no problem.

I'm not a Python expert. My language is R / 

Good luck.

def employment_event(e):
    event_name = e['event_name'].lower()
    return 'payroll' in event_name or 'employment' in event_name


employment_events_next_month = calendar_events(
    currencies=Currency.USD,
    importance=Importance.HIGH,
    function=employment_event
)
 
Vladimir Perervenko:

С использованием Python? 

да