예제 #1
0
    def create_new_token_file(self):
        """
        Gets input from the user to get account ID and token and creates a new .txt file.

        :return: Account ID and token
        :rtype: Tuple containing 2 strings
        """
        # Creates routine for the user to input his data into a 'oanda_data.txt' file
        print('\nCreate an account at www.oanda.com\n')

        # User ID insertion routine
        print('Insert your account ID: (format: 123-201-9876541-321)')
        account_id = input()

        # API token insertion routine
        print('Insert your API token: (format: 29d8h4472037d91216602e85f3bf318f-06e90608d9852a3b94fc23fd1cw0889q)')
        token = input()

        # File creation Routine
        generate_folder(self.folder_path)
        text_file = open(self.file_path, 'w')
        text_file.write(account_id + '\n' + token)
        text_file.close()

        return account_id, token
예제 #2
0
def record_trade(df):
    generate_folder('data/trade_record/')
    if not os.path.exists('data/trade_record/live_trades.csv'):
        df.to_csv('data/trade_record/live_trades.csv')
    else:
        with open('data/trade_record/live_trades.csv', 'a') as f:
            df.to_csv(f, header=False)
예제 #3
0
    def instantiates_indicator_manager(self, asset_id):
        """
        Instantiates IndicatorManager, searches for a previous saved state to load.

        :param asset_id: Security that IndicatorManager will be instantiated on.
        :return: New or loaded (if available) IndicatorManager
        """

        # Initialize state folder (where IndicatorManager state is saved).
        folder = 'data/state/'

        # Creates folder if it doesn't exist
        generate_folder(folder)

        # Loads IndicatorManager saved state if there is any
        for the_file in os.listdir(folder):
            if asset_id + '.pkl' in the_file:
                with open(folder + asset_id + '.pkl', 'rb') as f:
                    indicator_manager = _pickle.load(f)
                    indicator_manager.hdm.is_san_n_store = True
                    return indicator_manager

        # Instantiates a new IndicatorManager in case it didn't return the function previously
        return IndicatorManager(self._broker_instance, asset_id, self.strategy,
                                self.start_date)
    def get_dict_of_file_columns(self, asset):
        """
        Creates a dictionary with keys as timestamp and values as column names.

        :param asset: (str) Asset Name

        :return: dictionary with keys as timestamp and values as column names
        :rtype: dict of sets
        """
        # Sets indicator output folder
        folder = self.indicator_output_folder
        generate_folder(folder)

        # Creates dict
        columns = {}

        # Gets list of assets
        for directory in os.listdir(folder):

            # Checks if there asset is on the list of all assets
            if asset in directory:

                # Creates path for desired asset
                currency_dir = '{}/{}'.format(folder, directory)

                # Iterates through list of files for given asset
                for the_file in os.listdir(currency_dir):
                    # Gets filepath for given file
                    filepath = '{}/{}'.format(currency_dir, the_file)

                    # Get column name for given file
                    columns[the_file] = self.get_columns(filepath)

        # Returns dictionary with keys as timestamp and values as column names
        return columns
예제 #5
0
    def __init__(self,
                 broker='test',
                 storage='pandas_hdf5',
                 list_of_asset_ids=ref.cur_ordered_by_spread[0:1],
                 strategy_=ExampleStrategy(),
                 is_clean=False,
                 start_dt=datetime.datetime(1971, 2, 1)):
        """
        Initializes GeneralManager, which is a class that has methods to download all Candles (historic and live) and
        run them through indicators, as well as to create exit points and an AI strategy.

        :param broker: (str) Broker Name (ex.: 'test, 'oanda', 'fxcm')
        :param storage: (str) Database Name (ex.: 'pandas_hdf5')
        :param list_of_asset_ids: (list of str) Asset ids to be processed
        :param strategy_: Strategy to be used
        :param is_clean: if True will reset all historical data
        :param start_dt: start date for historical simulations
        """

        # Instantiate broker_instance
        self._broker_instance = select_broker(broker, storage)
        self._list_of_asset_ids = list_of_asset_ids
        self._live_feed_status = True
        self._strategy = strategy_
        self._start_date = start_dt

        # Generates data folders if they are non-existent
        for folder in ref.data_folders:
            generate_folder(folder)

        # Cleans data in case it was set to reset stored simulations data
        if is_clean:
            self.clean_data()
예제 #6
0
    def get_stored_data_in_chunks(self, asset, chunksize):
        # Generates candles and asset name if folder don't exist
        generate_folder('{}/{}'.format(self.candles_folder, asset))

        # Gets DataFrame from disk
        return pd.read_hdf(self.get_candles_filename(asset),
                           chunksize=chunksize)
예제 #7
0
    def save_controls(self, asset, df):
        """
        Appends controls DataFrame into 'controls.h5'

        :param asset: Asset Name
        :param df: controls DataFrame
        """
        # Generates candles and asset name if folder don't exist
        generate_folder('{}/{}'.format(self.candles_folder, asset))

        # Save controls DataFrame into disk
        df.to_feather(self.get_candles_controls_filename(asset))
예제 #8
0
    def save_controls(self, asset, df):
        """
        Appends controls DataFrame into 'controls.h5'

        :param asset: Asset Name
        :param df: controls DataFrame
        """
        # Generates candles and asset name if folder don't exist
        generate_folder('{}/{}'.format(self.candles_folder, asset))

        # Save controls DataFrame into disk
        with pd.HDFStore(self.get_candles_controls_filename(asset)) as hdf:
            hdf.put(key='controls', value=df, format='table')
예제 #9
0
    def get_stored_data(self, asset):
        """
        Gets stored data for specific asset.

        :param asset: (str) Asset name

        :return: Candles for specified asset
        :rtype: pandas DataFrame
        """
        # Generates candles and asset name if folder don't exist
        generate_folder('{}/{}'.format(self.candles_folder, asset))

        # Gets DataFrame from disk
        return pd.read_feather(self.get_candles_filename(asset)).set_index('datetime')
예제 #10
0
    def get_stored_data(self, asset):
        """
        Gets stored data for specific asset.
        
        :param asset: (str) Asset name
        
        :return: Candles for specified asset 
        :rtype: pandas DataFrame
        """

        # Generates candles and asset name if folder don't exist
        generate_folder('{}/{}'.format(self.candles_folder, asset))

        # Gets DataFrame from disk
        with pd.HDFStore(self.get_candles_filename(asset)) as hdf:
            df = hdf.get(key='G01')
            return df
예제 #11
0
 def get_candles_controls_filename(self, finsec):
     generate_folder('{}/{}/'.format(self.candles_folder, finsec))
     return '{}/{}/controls{}'.format(self.candles_folder, finsec,
                                      self.extension)
예제 #12
0
 def get_indicator_filename(self, finsec, ts):
     generate_folder('{}/{}/'.format(self.indicator_output_folder, finsec))
     return '{}/{}/{}{}'.format(self.indicator_output_folder, finsec, ts,
                                self.extension)