2018-02-13 03:45:59 +00:00
|
|
|
"""
|
|
|
|
This module contains class to manage RPC communications (Telegram, Slack, ...)
|
|
|
|
"""
|
2018-05-31 19:08:11 +00:00
|
|
|
from typing import Any, List
|
2018-03-25 19:37:14 +00:00
|
|
|
import logging
|
Added Local RPC client
- added only "Daily" call so far, submitting for early review/feedback
This depends on zerorpc as a requirement.
simple examples here:
http://www.zerorpc.io/
Installed with pip3 install zerorpc
localRCP is enabled/disabled from within config.json
e.g
"localrpc": {
"enabled": true
},
The server is enabled from within existing rpc manager
and makes use of the existing superclass (RPC)
Though making use of the existing hardwork done in rpc.py
It *should be easy to add the other Telegram calls into local_rpy_server.py
The server is wrapped in a thread to be non-blocking
The server and client accept serialised calls or not, used in daily to return json
The client can be used from command line or in a python script
As example, from cmdline for last 3 days Daily
/Users/creslin/PycharmProjects/freqtrade_new/.env/bin/zerorpc tcp://127.0.0.1:4242 daily 3
connecting to "tcp://127.0.0.1:4242"
False
('[\n'
' [\n'
' "2018-06-08",\n'
' "0.00000000 BTC",\n'
' "0.000 USDT",\n'
' "0 trade"\n'
' ],\n'
' [\n'
' "2018-06-07",\n'
' "0.00000000 BTC",\n'
' "0.000 USDT",\n'
' "0 trade"\n'
' ],\n'
' [\n'
' "2018-06-06",\n'
' "0.00000000 BTC",\n'
' "0.000 USDT",\n'
' "0 trade"\n'
' ]\n'
']')
Programitcally this would be:
import zerorpc
c = zerorpc.Client()
c.connect("tcp://127.0.0.1:4242")
for item in c.daily(3):
print item
2018-06-08 18:35:01 +00:00
|
|
|
import time
|
2018-02-13 03:45:59 +00:00
|
|
|
|
|
|
|
from freqtrade.rpc.telegram import Telegram
|
Added Local RPC client
- added only "Daily" call so far, submitting for early review/feedback
This depends on zerorpc as a requirement.
simple examples here:
http://www.zerorpc.io/
Installed with pip3 install zerorpc
localRCP is enabled/disabled from within config.json
e.g
"localrpc": {
"enabled": true
},
The server is enabled from within existing rpc manager
and makes use of the existing superclass (RPC)
Though making use of the existing hardwork done in rpc.py
It *should be easy to add the other Telegram calls into local_rpy_server.py
The server is wrapped in a thread to be non-blocking
The server and client accept serialised calls or not, used in daily to return json
The client can be used from command line or in a python script
As example, from cmdline for last 3 days Daily
/Users/creslin/PycharmProjects/freqtrade_new/.env/bin/zerorpc tcp://127.0.0.1:4242 daily 3
connecting to "tcp://127.0.0.1:4242"
False
('[\n'
' [\n'
' "2018-06-08",\n'
' "0.00000000 BTC",\n'
' "0.000 USDT",\n'
' "0 trade"\n'
' ],\n'
' [\n'
' "2018-06-07",\n'
' "0.00000000 BTC",\n'
' "0.000 USDT",\n'
' "0 trade"\n'
' ],\n'
' [\n'
' "2018-06-06",\n'
' "0.00000000 BTC",\n'
' "0.000 USDT",\n'
' "0 trade"\n'
' ]\n'
']')
Programitcally this would be:
import zerorpc
c = zerorpc.Client()
c.connect("tcp://127.0.0.1:4242")
for item in c.daily(3):
print item
2018-06-08 18:35:01 +00:00
|
|
|
from freqtrade.rpc.local_rpc_server import LocalRPCSuperWrap
|
2018-02-13 03:45:59 +00:00
|
|
|
|
|
|
|
|
2018-03-25 19:37:14 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2018-02-13 03:45:59 +00:00
|
|
|
class RPCManager(object):
|
|
|
|
"""
|
|
|
|
Class to manage RPC objects (Telegram, Slack, ...)
|
|
|
|
"""
|
|
|
|
def __init__(self, freqtrade) -> None:
|
|
|
|
"""
|
|
|
|
Initializes all enabled rpc modules
|
|
|
|
:param config: config to use
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
self.freqtrade = freqtrade
|
|
|
|
|
2018-05-31 18:55:26 +00:00
|
|
|
self.registered_modules: List[str] = []
|
|
|
|
self.telegram: Any = None
|
2018-02-13 03:45:59 +00:00
|
|
|
self._init()
|
|
|
|
|
2018-03-17 22:30:31 +00:00
|
|
|
def _init(self) -> None:
|
2018-02-13 03:45:59 +00:00
|
|
|
"""
|
|
|
|
Init RPC modules
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
if self.freqtrade.config['telegram'].get('enabled', False):
|
2018-03-25 19:37:14 +00:00
|
|
|
logger.info('Enabling rpc.telegram ...')
|
2018-02-13 03:45:59 +00:00
|
|
|
self.registered_modules.append('telegram')
|
|
|
|
self.telegram = Telegram(self.freqtrade)
|
|
|
|
|
Added Local RPC client
- added only "Daily" call so far, submitting for early review/feedback
This depends on zerorpc as a requirement.
simple examples here:
http://www.zerorpc.io/
Installed with pip3 install zerorpc
localRCP is enabled/disabled from within config.json
e.g
"localrpc": {
"enabled": true
},
The server is enabled from within existing rpc manager
and makes use of the existing superclass (RPC)
Though making use of the existing hardwork done in rpc.py
It *should be easy to add the other Telegram calls into local_rpy_server.py
The server is wrapped in a thread to be non-blocking
The server and client accept serialised calls or not, used in daily to return json
The client can be used from command line or in a python script
As example, from cmdline for last 3 days Daily
/Users/creslin/PycharmProjects/freqtrade_new/.env/bin/zerorpc tcp://127.0.0.1:4242 daily 3
connecting to "tcp://127.0.0.1:4242"
False
('[\n'
' [\n'
' "2018-06-08",\n'
' "0.00000000 BTC",\n'
' "0.000 USDT",\n'
' "0 trade"\n'
' ],\n'
' [\n'
' "2018-06-07",\n'
' "0.00000000 BTC",\n'
' "0.000 USDT",\n'
' "0 trade"\n'
' ],\n'
' [\n'
' "2018-06-06",\n'
' "0.00000000 BTC",\n'
' "0.000 USDT",\n'
' "0 trade"\n'
' ]\n'
']')
Programitcally this would be:
import zerorpc
c = zerorpc.Client()
c.connect("tcp://127.0.0.1:4242")
for item in c.daily(3):
print item
2018-06-08 18:35:01 +00:00
|
|
|
# Added another RPC client - for cmdline local client.
|
|
|
|
# Uses existing superclass RPC build for Telegram
|
|
|
|
if self.freqtrade.config['localrpc'].get('enabled', False):
|
|
|
|
self.localRPC = LocalRPCSuperWrap(self.freqtrade)
|
|
|
|
time.sleep(1)
|
|
|
|
|
2018-02-13 03:45:59 +00:00
|
|
|
def cleanup(self) -> None:
|
|
|
|
"""
|
|
|
|
Stops all enabled rpc modules
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
if 'telegram' in self.registered_modules:
|
2018-03-25 19:37:14 +00:00
|
|
|
logger.info('Cleaning up rpc.telegram ...')
|
2018-02-13 03:45:59 +00:00
|
|
|
self.registered_modules.remove('telegram')
|
|
|
|
self.telegram.cleanup()
|
|
|
|
|
|
|
|
def send_msg(self, msg: str) -> None:
|
|
|
|
"""
|
|
|
|
Send given markdown message to all registered rpc modules
|
|
|
|
:param msg: message
|
|
|
|
:return: None
|
|
|
|
"""
|
2018-03-25 19:37:14 +00:00
|
|
|
logger.info(msg)
|
2018-02-13 03:45:59 +00:00
|
|
|
if 'telegram' in self.registered_modules:
|
|
|
|
self.telegram.send_msg(msg)
|