def setUp(self): """ Define static instance variables and create redis/mysql objects as well as working test directory """ self.pairs = [pairs] self.startdate = startdate self.sum = xsum self.max = xmax self.min = xmin self.drawup = drawup self.drawdown = drawdown os.system("configstore package process_templates {} /etc".format( config_env)) config.create_config() # reload config self.days = days self.outputdir = "/tmp/test_data" self.intervals = [interval] self.logger = get_logger(__name__) self.logger.info("Setting up environment") self.redis = Redis(interval=self.intervals[0], test=True, test_data=True) self.dbase = Mysql(test=True, interval=self.intervals[0]) if not os.path.exists(self.outputdir): os.mkdir(self.outputdir)
def main(): """main function""" config.create_config() binance_auth() if len(sys.argv) > 1 and sys.argv[1] == '--help': print("Test binance authentication using config creds") sys.exit(0) try: binance.balances() print("Success") except ValueError: sys.exit("Auth Error")
def test_long_take_profit(self): """ Test stop loss for long trades """ config_env = 'unit/scalp' os.system("configstore package process_templates {} /etc".format(config_env)) config.create_config() redis = Redis(test=True, test_data=True) # current_high > addperc(profit_perc, open_price) 10% result = redis._Redis__get_take_profit(current_price=200, current_high=500, open_price=20) self.assertTrue(result) # current_high > addperc(profit_perc, open_price) 10% result = redis._Redis__get_take_profit(current_price=10, current_high=500, open_price=20) self.assertTrue(result) # current_high > addperc(profit_perc, open_price) 10% result = redis._Redis__get_take_profit(current_price=10, current_high=1, open_price=20) self.assertFalse(result) config_env = 'unit/scalp/alt' os.system("configstore package process_templates {} /etc".format(config_env)) config.create_config() redis = Redis(test=True, test_data=False) # turn off immediate take profit- changes check to current_price # current_price > addperc(profit_perc, open_price) 10% result = redis._Redis__get_take_profit(current_price=10, current_high=1, open_price=20) self.assertFalse(result) # current_price > addperc(profit_perc, open_price) 10% result = redis._Redis__get_take_profit(current_price=100, current_high=1, open_price=20) self.assertTrue(result)
def test_long_stop_loss(self): """ Test stop loss for long trades """ config_env = 'unit/scalp' os.system("configstore package process_templates {} /etc".format(config_env)) config.create_config() redis = Redis(test=True, test_data=True) # current_low < open_price - stop_perc 10% result = redis._Redis__get_stop_loss(current_price=100, current_low=100, open_price=400) self.assertTrue(result) # current_low < open_price - stop_perc 10% result = redis._Redis__get_stop_loss(current_price=359, current_low=500, open_price=400) self.assertFalse(result) config_env = 'unit/scalp/alt' redis = Redis(test=True, test_data=False) # turn off immediate stop - changes check to current_price # current_price < open_price - stop_perc 10% result = redis._Redis__get_stop_loss(current_price=364, current_low=500, open_price=400) self.assertFalse(result) # current_price < open_price - stop_perc 10% result = redis._Redis__get_stop_loss(current_price=200, current_low=500, open_price=400) self.assertTrue(result) # no open price - return False result = redis._Redis__get_stop_loss(current_price=200, current_low=500, open_price='') self.assertFalse(result)
#!/usr/bin/env python #pylint: disable=wrong-import-position,no-member """ Create OHLC graph using daily balance """ import sys import numpy import pandas from greencandle.lib import config config.create_config() from greencandle.lib.mysql import Mysql from greencandle.lib.graph import Graph def main(): """ Main function """ mysql = Mysql() if len(sys.argv) > 1 and sys.argv[1] == '--help': print("Create OHLC graph using daily balance") sys.exit(0) # temp table we will use to filter out incomplete balance records drop = "drop table if exists `temp_table`" # There needs to be 4 records for each date representing 3 exchanges clean = (
def test_long_trailing_stop_loss(self): """ Test trailing stop loss for long trades """ config_env = 'unit/scalp' os.system("configstore package process_templates {} /etc".format(config_env)) config.create_config() redis = Redis(test=True, test_data=True) # current_high <= subperc(trailing_perc, high_price) result = redis._Redis__get_trailing_stop(current_price=100, high_price=500, low_price=0, current_low=0, current_high=2, open_price=400) self.assertTrue(result) # current_price <= subperc(trailing_perc, high_price) result = redis._Redis__get_trailing_stop(current_price=1000, high_price=500, low_price=0, current_low=0, current_high=2000, open_price=4000) self.assertFalse(result) # current_price <= subperc(trailing_perc, high_price) result = redis._Redis__get_trailing_stop(current_price=90, high_price=500, low_price=0, current_low=0, current_high=2000, open_price=4000) self.assertTrue(result) # current_price <= subperc(trailing_perc, high_price) result = redis._Redis__get_trailing_stop(current_price=90, high_price='', low_price=0, current_low=0, current_high=2000, open_price=4000) print(result) # False self.assertFalse(result) redis = Redis(test=True, test_data=False) # current_price <= subperc(trailing_perc, high_price) # and current_price > addperc(trailing_perc, high_price) result = redis._Redis__get_trailing_stop(current_price=90, high_price=500, low_price=0, current_low=0, current_high=2000, open_price=4000) self.assertFalse(result) # current_price <= subperc(trailing_perc, high_price) # and current_price > addperc(trailing_perc, high_price) result = redis._Redis__get_trailing_stop(current_price=3000, high_price=500, low_price=0, current_low=0, current_high=2000, open_price=4000) self.assertFalse(result) # current_price <= subperc(trailing_perc, high_price) 498 <= (500-0.1%) ~499.5 # and current_price > addperc(trailing_start, open_price) result = redis._Redis__get_trailing_stop(current_price=498, high_price=500, low_price=0, current_low=0, current_high=4000, open_price=200) self.assertTrue(result) # current_price <= subperc(trailing_perc, high_price) 498 <= (500-0.1%) ~499.5 # and current_price > addperc(trailing_start, open_price) result = redis._Redis__get_trailing_stop(current_price=498, high_price=500, low_price=0, current_low=0, current_high=4000, open_price=300) self.assertTrue(result) config_env = 'unit/scalp/alt' os.system("configstore package process_templates {} /etc".format(config_env)) config.create_config() #changes check to current_high (from current_price) redis = Redis(test=True, test_data=True) # current_high <= subperc(trailing_perc, high_price) # and current_price > addperc(trailing_start, open_price) result = redis._Redis__get_trailing_stop(current_price=498, high_price=500, low_price=0, current_low=0, current_high=4000, open_price=300) self.assertFalse(result) # current_high <= subperc(trailing_perc, high_price) # and current_price > addperc(trailing_start, open_price) result = redis._Redis__get_trailing_stop(current_price=498, high_price=600, low_price=0, current_low=0, current_high=4000, open_price=300) self.assertFalse(result) ####### ####### # current_high <= subperc(trailing_perc, high_price) # and current_price > addperc(trailing_start, open_price) result = redis._Redis__get_trailing_stop(current_price=498, high_price=4000, low_price=0, current_low=0, current_high=600, open_price=300) self.assertTrue(result)