コード例 #1
0
        def reset_balance_notifier(self):
            """
            Used to reset the balance notifier pause time
            """
            self.app_data["pauseTime"]["balance"] = time.time()

            write_json_to_file(self.app_data_file_string, self.app_data)
コード例 #2
0
        def store_initial_buy(self, coin_pair, buy_order_uuid):
            """
            Used to place an initial trade in the database

            :param coin_pair: String literal for the market (ex: BTC-LTC)
            :type coin_pair: str
            :param buy_order_uuid: The buy order's UUID
            :type buy_order_uuid: str
            """
            if coin_pair in self.trades["trackedCoinPairs"]:
                return logger.warning(
                    "Trying to buy on the {} market which is already tracked.".
                    format(coin_pair))

            new_buy_object = {
                "coinPair": coin_pair,
                "quantity": 0,
                "buy": {
                    "orderUuid": buy_order_uuid
                }
            }

            self.trades["trackedCoinPairs"].append(coin_pair)
            self.trades["trades"].append(new_buy_object)

            write_json_to_file(self.trades_file_string, self.trades)
コード例 #3
0
ファイル: bittrex.py プロジェクト: ilya0/Crypto-Trading-Bot
def encrypt(api_key, api_secret, export=True, export_fn="../database/secrets.json"):
    cipher = AES.new(getpass.getpass("Input encryption password (string will not show)"))
    api_key_n = cipher.encrypt(api_key)
    api_secret_n = cipher.encrypt(api_secret)
    api = {"key": str(api_key_n), "secret": str(api_secret_n)}
    if export:
        write_json_to_file(export_fn, api)
    return api
コード例 #4
0
        def pause_buy(self, coin_pair):
            """
            Used to pause buy tracking on the coin pair

            :param coin_pair: String literal for the market (ex: BTC-LTC)
            :type coin_pair: str
            """
            self.app_data["coinPairs"].remove(coin_pair)

            write_json_to_file(self.app_data_file_string, self.app_data)
コード例 #5
0
        def resume_sells(self):
            """
            Used to resume all paused sells and reset the sell pause time
            """
            if len(self.app_data["pausedTrackedCoinPairs"]) < 1:
                return

            self.app_data["pausedTrackedCoinPairs"] = []
            self.app_data["pauseTime"]["sell"] = None

            write_json_to_file(self.app_data_file_string, self.app_data)
コード例 #6
0
        def store_coin_pairs(self, btc_coin_pairs):
            """
            Used to store the latest Bittrex available markets and update the buy pause time

            :param btc_coin_pairs: String list of market pairs
            :type btc_coin_pairs: list
            """
            self.app_data["coinPairs"] = btc_coin_pairs
            self.app_data["pauseTime"]["buy"] = time.time()

            write_json_to_file(self.app_data_file_string, self.app_data)
コード例 #7
0
        def reset_balance_notifier(self, current_balance=None):
            """
            Used to reset the balance notifier pause time

            :param current_balance: The current total balance's BTC value
            :type current_balance: float
            """
            if current_balance is not None:
                self.app_data["previousBalance"] = current_balance
            self.app_data["pauseTime"]["balance"] = time.time()

            write_json_to_file(self.app_data_file_string, self.app_data)
コード例 #8
0
def encrypt(api_key,
            api_secret,
            export=True,
            export_fn="../database/secrets.json"):
    cipher = AES.new(
        getpass.getpass("Input encryption password (string will not show)"))
    api_key_n = cipher.encrypt(api_key)
    api_secret_n = cipher.encrypt(api_secret)
    api = {"key": str(api_key_n), "secret": str(api_secret_n)}
    if export:
        write_json_to_file(export_fn, api)
    return api
コード例 #9
0
        def pause_sell(self, coin_pair):
            """
            Used to pause sell tracking on the coin pair and set the sell pause time

            :param coin_pair: String literal for the market (ex: BTC-LTC)
            :type coin_pair: str
            """
            if coin_pair in self.app_data["pausedTrackedCoinPairs"]:
                return
            self.app_data["pausedTrackedCoinPairs"].append(coin_pair)
            if self.app_data["pauseTime"]["sell"] is None:
                self.app_data["pauseTime"]["sell"] = time.time()

            write_json_to_file(self.app_data_file_string, self.app_data)
コード例 #10
0
        def store_sell(self, bittrex_order, stats):
            """
            Used to place a sell trade in the database

            :param bittrex_order: Bittrex sell order object
            :type bittrex_order: dict
            :param stats: The sell stats to store
            :type stats: dict
            """
            if bittrex_order["Exchange"] not in self.trades["trackedCoinPairs"]:
                return logger.warning(
                    "Trying to sell on the {} market which is not tracked.".format(bittrex_order["Exchange"])
                )

            order = self.convert_bittrex_order_object(bittrex_order, stats)

            trade = self.get_open_trade(bittrex_order["Exchange"])
            trade["sell"] = order
            self.trades["trackedCoinPairs"].remove(bittrex_order["Exchange"])

            write_json_to_file(self.trades_file_string, self.trades)
コード例 #11
0
        def store_buy(self, bittrex_order, stats):
            """
            Used to place a buy trade in the database

            :param bittrex_order: Bittrex buy order object
            :type bittrex_order: dict
            :param stats: The buy stats to store
            :type stats: dict
            """
            if bittrex_order["Exchange"] not in self.trades["trackedCoinPairs"]:
                return logger.warning(
                    "Trying to buy on the {} market without an initial buy object.".format(bittrex_order["Exchange"])
                )

            order = self.convert_bittrex_order_object(bittrex_order, stats)

            trade = self.get_open_trade(bittrex_order["Exchange"])
            trade["quantity"] = round(bittrex_order["Quantity"] - bittrex_order["QuantityRemaining"], 8)
            trade["buy"] = order

            write_json_to_file(self.trades_file_string, self.trades)
コード例 #12
0
from pydash import py_

from directory_utilities import get_json_from_file, write_json_to_file

trades_file_directory = "../database/trades.json"
trades = get_json_from_file(trades_file_directory)

archived_trades_file_directory = "../database/archive/archived-trades.json"
archived_trades = get_json_from_file(archived_trades_file_directory, [])

new_archived_trades = py_.filter_(
    trades["trades"],
    lambda trade: "sell" in trade and trade not in archived_trades)
if len(new_archived_trades) > 0:
    archived_trades += new_archived_trades
    write_json_to_file(archived_trades_file_directory, archived_trades)
    print("Archived {} closed trades.".format(len(new_archived_trades)))
else:
    print("No closed trades to archive.")

num_of_initial_trades = len(trades["trades"])
trades["trades"] = py_.filter_(trades["trades"],
                               lambda trade: "sell" not in trade)

if len(trades["trades"]) < num_of_initial_trades:
    write_json_to_file(trades_file_directory, trades)
    print("Removed {} closed trades from active trades.".format(
        num_of_initial_trades - len(trades["trades"])))
else:
    print("No closed trades to remove from active trades.")
コード例 #13
0
from pydash import py_

from directory_utilities import get_json_from_file, write_json_to_file

trades_file_directory = "../database/trades.json"
trades = get_json_from_file(trades_file_directory)

archived_trades_file_directory = "../database/archive/archived-trades.json"
archived_trades = get_json_from_file(archived_trades_file_directory, [])

new_archived_trades = py_.filter_(trades["trades"], lambda trade: "sell" in trade and trade not in archived_trades)
if len(new_archived_trades) > 0:
    archived_trades += new_archived_trades
    write_json_to_file(archived_trades_file_directory, archived_trades)
    print("Archived {} closed trades.".format(len(new_archived_trades)))
else:
    print("No closed trades to archive.")

num_of_initial_trades = len(trades["trades"])
trades["trades"] = py_.filter_(trades["trades"], lambda trade: "sell" not in trade)

if len(trades["trades"]) < num_of_initial_trades:
    write_json_to_file(trades_file_directory, trades)
    print("Removed {} closed trades from active trades.".format(num_of_initial_trades - len(trades["trades"])))
else:
    print("No closed trades to remove from active trades.")