Working and relatively glitch free. Classes implemented in python and javascript. UML class diagram. roughed in for both python and javascript.Bit of sequence uml. signals ready for implementation

This commit is contained in:
Rob 2022-05-17 02:29:49 -03:00
parent f6e1b848d2
commit 0a49a52383
7 changed files with 107 additions and 36 deletions

View File

@ -1,6 +1,8 @@
from binance.enums import * from binance.enums import *
import yaml import yaml
from indicators import Indicators
class Configuration: class Configuration:
def __init__(self): def __init__(self):
@ -19,8 +21,8 @@ class Configuration:
# The name of the file that stores saved_data # The name of the file that stores saved_data
self.config_FN = 'config.yml' self.config_FN = 'config.yml'
# A list of all the indicators available. This is injected later. # Call a static method from indicators that fills in a default list of indicators in config.
self.indicator_list = None self.indicator_list = Indicators.get_indicator_defaults()
# The data that will be saved and loaded from file . # The data that will be saved and loaded from file .
self.saved_data = None self.saved_data = None

View File

@ -23,7 +23,7 @@ class Candles:
self.latest_vol = [] self.latest_vol = []
# Set the instance variable of candlesticks, latest_close_values, high, low, closing, volume, and last_candle # Set the instance variable of candlesticks, latest_close_values, high, low, closing, volume, and last_candle
self.set_candle_history() self.set_candle_history(symbol=config.trading_pair, interval=config.chart_interval)
def set_new_candle(self, cdata): def set_new_candle(self, cdata):
self.last_candle = cdata self.last_candle = cdata
@ -92,12 +92,14 @@ class Candles:
max_data_loaded = self.max_data_loaded max_data_loaded = self.max_data_loaded
if not symbol: if not symbol:
symbol = self.config.trading_pair symbol = self.config.trading_pair
print(f'set_candle_history(): No symbol provided. Using{symbol}')
if not interval: if not interval:
interval = self.config.chart_interval interval = self.config.chart_interval
print(f'set_candle_history(): No interval provided. Using{interval}')
if self.candlesticks: if self.candlesticks:
print(f'set_candle_history(): Reloading candle data for :{interval}') print(f'set_candle_history(): Reloading {interval} candles.')
else: else:
print('set_candle_history(): Loading candle data') print(f'set_candle_history(): Loading {interval} candles.')
# Load candles from file # Load candles from file
cdata = self.load_candle_history(symbol, interval) cdata = self.load_candle_history(symbol, interval)
# Trim the beginning of the returned list to size of max_data_loaded of less # Trim the beginning of the returned list to size of max_data_loaded of less

78
config.yml Normal file
View File

@ -0,0 +1,78 @@
config:
chart_interval: 1d
trading_pair: BTCUSDT
indicator_list:
Bolenger:
color_1: '#5ad858'
color_2: '#f0f664'
color_3: '#5ad858'
devdn: 2
devup: 2
ma: 1
period: 20
type: BOLBands
value: 0
value1: '38691.58'
value2: '38552.36'
value3: '38413.14'
visible: 'True'
EMA 100:
color: '#286006'
period: 100
type: EMA
value: 0
visible: true
EMA 50:
color: '#fe534c'
period: 50
type: EMA
value: 0
visible: true
New Indicator4:
color_1: '#2f1bc6'
color_2: '#3e79cb'
fast_p: 12
hist: 0
macd: 0
signal: 0
signal_p: 9
slow_p: 26
type: MACD
value: 0
visible: true
RSI 14:
color: '#07120c'
period: 14
type: RSI
value: 0
visible: true
RSI 8:
color: '#4c4fe9'
period: 8
type: RSI
value: 0
visible: true
SMA 200:
color: '#cdc178'
period: 200
type: SMA
value: 0
visible: true
SMA 21:
color: '#2847ce'
period: 21
type: SMA
value: 0
visible: true
indicator 5:
color: '#13cbec'
nameww: valueww
period: 20
test222: 2222222
type: LREG
value: '30302.05'
visible: 'True'
vol:
type: Volume
value: 0
visible: true

14
data.py
View File

@ -2,7 +2,7 @@ from binance.client import Client
import config import config
from candles import Candles from candles import Candles
from config_states import Configuration from Configuration import Configuration
from exchange_info import ExchangeInfo from exchange_info import ExchangeInfo
from indicators import Indicators from indicators import Indicators
@ -15,8 +15,7 @@ class BrighterData:
# Configuration and settings for the user interface and charts # Configuration and settings for the user interface and charts
self.config = Configuration() self.config = Configuration()
# Call a static method from indicators that fills in a default list of indicators in config.
self.config.set_indicator_list(Indicators.get_indicator_defaults())
# Load any saved data from file # Load any saved data from file
self.config.config_and_states('load') self.config.config_and_states('load')
@ -24,7 +23,7 @@ class BrighterData:
self.candles = Candles(self.config, self.client) self.candles = Candles(self.config, self.client)
# Object that interacts with and maintains data from available indicators # Object that interacts with and maintains data from available indicators
self.indicators = Indicators(self.candles) self.indicators = Indicators(self.candles, self.config)
# Object that maintains exchange and account data # Object that maintains exchange and account data
self.exchange_info = ExchangeInfo(self.client) self.exchange_info = ExchangeInfo(self.client)
@ -56,12 +55,11 @@ class BrighterData:
def received_cdata(self, cdata): def received_cdata(self, cdata):
# If this is the first candle received, # If this is the first candle received,
# then just set last_candle and return. # then set last_candle. Then set a new candle.
if not self.candles.last_candle: if not self.candles.last_candle:
self.candles.last_candle = cdata self.candles.last_candle = cdata
return
# If this candle is the same as last candle return nothing to do. # If this candle is the same as last candle return nothing to do.
if cdata['time']: elif cdata['time']:
if cdata['time'] == self.candles.last_candle['time']: if cdata['time'] == self.candles.last_candle['time']:
return return
@ -75,6 +73,6 @@ class BrighterData:
if 'sigName' not in data: if 'sigName' not in data:
return 'data.py:received_new_signal() - The new signal has no name. ' return 'data.py:received_new_signal() - The new signal has no name. '
print(data) print(data)
# TODO lets go!
app_data = BrighterData() app_data = BrighterData()

View File

@ -4,25 +4,20 @@ import talib
class Indicators: class Indicators:
def __init__(self, candles): def __init__(self, candles, config):
# Object containing Price and candle data. # Object containing Price and candle data.
self.candles = candles self.candles = candles
# List of all available indicator types # List of all available indicator types
self.indicator_types = {} # todo: get rid of this use inheritance in classes instead.
self.indicator_types = {'simple_indicators': ['RSI', 'SMA', 'EMA', 'LREG'],
'other': ['Volume', 'BOLBands', 'MACD', 'ATR']}
# List of all available indicators # List of all available indicators
self.indicator_list = None self.indicator_list = config.indicator_list
# Add default indicators and their default values to self.indicator_list
self.set_indicator_defaults()
# A list of values to use with bolenger bands # A list of values to use with bolenger bands
self.bb_ma_val = {'SMA': 0, 'EMA': 1, 'WMA': 2, 'DEMA': 3, 'TEMA': 4, 'TRIMA': 5, 'KAMA': 6, 'MAMA': 7, 'T3': 8} self.bb_ma_val = {'SMA': 0, 'EMA': 1, 'WMA': 2, 'DEMA': 3, 'TEMA': 4, 'TRIMA': 5, 'KAMA': 6, 'MAMA': 7, 'T3': 8}
def set_indicator_defaults(self):
self.indicator_list = self.get_indicator_defaults()
# todo: get rid of this they are not needed after utilizing ingheritance in classes instead.
self.indicator_types = {'simple_indicators': ['RSI', 'SMA', 'EMA', 'LREG'],
'other': ['Volume', 'BOLBands', 'MACD', 'ATR']}
@staticmethod @staticmethod
def get_indicator_defaults(): def get_indicator_defaults():
"""Set the default settings for each indicator""" """Set the default settings for each indicator"""

View File

@ -32,6 +32,7 @@ class Comms {
return id; return id;
} }
send_to_app(message_type, data){ send_to_app(message_type, data){
console.log( JSON.stringify({ message_type: message_type, data : data }));
this.app_con.send( JSON.stringify({ message_type: message_type, data : data })); this.app_con.send( JSON.stringify({ message_type: message_type, data : data }));
} }
set_app_con(){ set_app_con(){

View File

@ -153,23 +153,18 @@ class Signals {
var sigType = document.getElementById('select_s_type').value; // The type of signal value or indicator comparison. var sigType = document.getElementById('select_s_type').value; // The type of signal value or indicator comparison.
var value = document.getElementById('value').value; // The input value if it is a value comparison. var value = document.getElementById('value').value; // The input value if it is a value comparison.
var sigName = {sigName : sigName}; // Name_of_signal
var sigSource = {sigSource : sigSource}; // First_signal_indicator.
var sigProp = {sigProp : sigProp}; // First_signal_property.
var operator = {operator : operator}; // Operator.
if (sigType == 'Comparison'){ if (sigType == 'Comparison'){
var sig2Source = {sig2Source: sig2Source}; var sig2Source = sig2Source;
var sig2Prop = {sig2Prop : sig2Prop}; var sig2Prop = sig2Prop;
}else{ }else{
var sig2Source = {sig2Source: value}; var sig2Source = 'value';
var sig2Prop = {value: value}; var sig2Prop = value;
} }
if (operator == "'operator' : '+/-'" ){ if (operator == "+/-" ){
var range = {range : range}; var range = {range : range};
var data = [sigName, sigSource, sigProp, operator, sig2Source, sig2Prop, range]; var data = {sigName, sigSource, sigProp, operator, sig2Source, sig2Prop, range};
}else{ }else{
var data = [sigName, sigSource, sigProp, operator, sig2Source, sig2Prop]; var data = {sigName, sigSource, sigProp, operator, sig2Source, sig2Prop};
} }
/* It may be more maintainable to configure the connection inside the different classes /* It may be more maintainable to configure the connection inside the different classes
than passing functions, references and callbacks around. */ than passing functions, references and callbacks around. */