From 3996e4563d61638545b98e76c55db100fd6b9f3a Mon Sep 17 00:00:00 2001 From: Emerson Pedroso Date: Wed, 24 Feb 2021 21:19:27 -0300 Subject: [PATCH] upgrade 1.0.2 --- README.md | 45 +++++++++++++++---- ejtraderMT/api/platafrom.py | 37 ++++++++++----- setup.py | 2 +- test/MultipleDataframe.py | 2 +- test/ShortMultipleDataframe.py | 2 +- ...ltipleDataframe copy.py => dicthistory.py} | 6 +-- test/{main.py => live.py} | 4 +- 7 files changed, 71 insertions(+), 27 deletions(-) rename test/{MultipleDataframe copy.py => dicthistory.py} (50%) rename test/{main.py => live.py} (97%) diff --git a/README.md b/README.md index 90b2f38..cbb611c 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,9 @@ mt.cancel_all() mt.close_all() ``` -#### History fromDate toDate +# History Dataframe Ready + +#### History from Date to Date Dataframe ```python symbol = "EURUSD" @@ -141,7 +143,7 @@ timeframe = "M1" fromDate = "24/02/2021" toDate = "24/02/2021" -history = mt.history(symbol,timeframe,fromDate,toDate) +history = mt.historyDataframe(symbol,timeframe,fromDate,toDate) print(history) open high low close volume spread @@ -186,14 +188,14 @@ date ``` -#### Short History +#### Short History Dataframe ```python symbol = "EURUSD" timeframe = "M1" -history = mt.Shorthistory(symbol,timeframe,1) +history = mt.ShorthistoryDataframe(symbol,timeframe,10) print(history) open high low close volume spread @@ -238,7 +240,7 @@ date ``` -#### History multiple symbol merged DataFrame +# History multiple symbol merged DataFrame ```python from ejtraderMT import Metatrader @@ -251,7 +253,7 @@ timeframe = "M1" fromDate = "01/01/2021" toDate = "10/01/2021" -data = api.historyDataFrame(symbol,symbols,timeframe,fromDate,toDate) +data = api.historyMultiDataFrame(symbol,symbols,timeframe,fromDate,toDate) print(data) open high low close volume spread OPENGBPUSD HIGHGBPUSD LOWGBPUSD CLOSEGBPUSD VOLUMEGBPUSD SPREADGBPUSD OPENAUDUSD HIGHAUDUSD LOWAUDUSD CLOSEAUDUSD VOLUMEAUDUSD SPREADAUDUSD @@ -283,7 +285,7 @@ symbols = [symbol,"GBPUSD","AUDUSD"] timeframe = "M1" -data = api.ShorthistoryDataFrame(symbol,symbols,timeframe,10) +data = api.ShorthistoryMultiDataFrame(symbol,symbols,timeframe,10) print(data) @@ -304,7 +306,34 @@ date ``` -#### Live data and streaming events +# history dictionary "array" + +#### Short History from Date to Date dict + +```python +symbol = "EURUSD" +timeframe = "M1" + + +history = mt.Shorthistory(symbol,timeframe,10) +print(history) +``` + +#### History fromDate toDate dict + +```python +symbol = "EURUSD" +timeframe = "M1" +fromDate = "24/02/2021" +toDate = "24/02/2021" + +history = mt.history(symbol,timeframe,fromDate,toDate) +print(history) + + +``` + +# Live data and streaming events ```python from ejtraderMT import Metatrader diff --git a/ejtraderMT/api/platafrom.py b/ejtraderMT/api/platafrom.py index 27508f7..6547ac0 100755 --- a/ejtraderMT/api/platafrom.py +++ b/ejtraderMT/api/platafrom.py @@ -317,8 +317,31 @@ def positions(self): def orders(self): return json.loads(json.dumps(self.api.Command(action="ORDERS"))) + + def Shorthistory(self, symbol, chartTF, fromDate, toDate): + + if(chartTF == 'TICK'): + data = json.loads(json.dumps(self.api.Command(action="HISTORY", actionType="DATA", symbol=symbol, chartTF=chartTF, fromDate=datetime.utcnow().timestamp() - (fromDate * 60)))) + self.api.Command(action="RESET") + else: + data = json.loads(json.dumps(self.api.Command(action="HISTORY", actionType="DATA", symbol=symbol, chartTF=chartTF, fromDate=datetime.utcnow().timestamp() - (fromDate * (self.timeframe_to_sec(chartTF) * 60))))) + self.api.Command(action="RESET") + return data + + def history(self, symbol, chartTF, fromDate, toDate): + if(chartTF == 'TICK'): + data = json.loads(json.dumps(self.api.Command(action="HISTORY", actionType="DATA", symbol=symbol, chartTF=chartTF, fromDate=convertDate(fromDate), toDate=convertDate(toDate)))) + self.api.Command(action="RESET") + else: + data = json.loads(json.dumps(self.api.Command(action="HISTORY", actionType="DATA", symbol=symbol, chartTF=chartTF, fromDate=convertDate(fromDate), toDate=convertDate(toDate)))) + self.api.Command(action="RESET") + return data + + + def historyDataFrame(self, symbol, chartTF, fromDate, toDate): + if(chartTF == 'TICK'): data = json.loads(json.dumps(self.api.Command(action="HISTORY", actionType="DATA", symbol=symbol, chartTF=chartTF, fromDate=convertDate(fromDate), toDate=convertDate(toDate)))) data_frame = pd.DataFrame(data['data'], columns=['date', 'bid', 'ask']) @@ -347,7 +370,7 @@ def timeframe_to_sec(self, timeframe): return TIMECANDLE[timeframe] - def Shorthistory(self, symbol, chartTF, fromDate): + def ShorthistoryDataframe(self, symbol, chartTF, fromDate): if(chartTF == 'TICK'): data = json.loads(json.dumps(self.api.Command(action="HISTORY", actionType="DATA", symbol=symbol, chartTF=chartTF, fromDate=datetime.utcnow().timestamp() - (fromDate * 60)))) @@ -365,7 +388,7 @@ def Shorthistory(self, symbol, chartTF, fromDate): - def historyDataFrame(self, symbol, symbols, chartTF, fromDate, toDate): + def historyMultiDataFrame(self, symbol, symbols, chartTF, fromDate, toDate): actives = symbols main = pd.DataFrame() current = pd.DataFrame() @@ -405,7 +428,7 @@ def historyDataFrame(self, symbol, symbols, chartTF, fromDate, toDate): main = main.loc[~main.index.duplicated(keep = 'first')] return main - def ShorthistoryDataFrame(self, symbol, symbols, chartTF, fromDate): + def ShorthistoryMultiDataFrame(self, symbol, symbols, chartTF, fromDate): actives = symbols main = pd.DataFrame() current = pd.DataFrame() @@ -446,13 +469,7 @@ def ShorthistoryDataFrame(self, symbol, symbols, chartTF, fromDate): return main - def live(self,symbol, chartTF): - self.api.Command(action="RESET") - for active in symbol: - self.api.Command(action="CONFIG", symbol=active, chartTF=chartTF) - print(f'subscribed : {active}') - time.sleep(1) - + diff --git a/setup.py b/setup.py index f559a59..9e0c135 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ def requirements(filename): setup( name='ejtraderMT', - version='1.0.0', + version='1.0.2', packages=find_packages(), url='https://ejtrader_mt.readthedocs.io/', download_url='https://ejtrader.com', diff --git a/test/MultipleDataframe.py b/test/MultipleDataframe.py index 0b4d02a..6d1734a 100644 --- a/test/MultipleDataframe.py +++ b/test/MultipleDataframe.py @@ -11,7 +11,7 @@ data = api.historyDataFrame(symbol,symbols,timeframe,fromDate,toDate) -api. + print(data) diff --git a/test/ShortMultipleDataframe.py b/test/ShortMultipleDataframe.py index 8d23ff5..03acefe 100644 --- a/test/ShortMultipleDataframe.py +++ b/test/ShortMultipleDataframe.py @@ -9,7 +9,7 @@ timeframe = "M1" -data = api.ShorthistoryDataFrame(symbol,symbols,timeframe,10) +data = api.ShorthistoryDataFrame(symbol,symbols,timeframe,3) print(data) diff --git a/test/MultipleDataframe copy.py b/test/dicthistory.py similarity index 50% rename from test/MultipleDataframe copy.py rename to test/dicthistory.py index 996c13a..31ba88e 100644 --- a/test/MultipleDataframe copy.py +++ b/test/dicthistory.py @@ -1,16 +1,14 @@ from ejtraderMT import Metatrader - api = Metatrader() symbol = "EURUSD" -symbols = [symbol,"GBPUSD","AUDUSD"] timeframe = "M1" fromDate = "01/01/2021" -toDate = "10/01/2021" +toDate = "01/02/2021" -data = api.historyDataFrame(symbol,symbols,timeframe,fromDate,toDate) +data = api.history(symbol,timeframe,fromDate,toDate) print(data) diff --git a/test/main.py b/test/live.py similarity index 97% rename from test/main.py rename to test/live.py index 8dcc434..d5da28a 100644 --- a/test/main.py +++ b/test/live.py @@ -29,8 +29,8 @@ def event(): event = connect.recv_json() print(event) - - + + t = Thread(target=price, daemon=True) t.start()