示例#1
0
 def get_initial_data(self):
     try:
         self.price.append(get_live_price(self.ticker))
         self.logger.debug("Successfully fetched live price")
     except SysCallError:
         Notify.warn(
             f"[Trader #{self.number} {self.ticker}]: Encountered SysCallError while initialising parameters, trying recursion"
         )
         self.logger.warning("Encountered SysCallError, trying recursion")
         self.get_initial_data()
     except Exception as e:
         Notify.warn(
             f"[Trader #{self.number} {self.ticker}]: Exception in getting initial data, trying recursion"
         )
         self.logger.error("Trying recursion due to uncommon Exception : ",
                           e)
         self.get_initial_data()
示例#2
0
 def update_price(self):
     try:
         new_price = get_live_price(self.ticker)
         self.price.append(new_price)
         self.logger.info(
             "Successfully fetched price, local database updated")
     except SysCallError:
         Notify.warn(
             f"[Trader #{self.number} {self.ticker}] : Encountered SysCallError in updating price, trying recursion"
         )
         self.logger.warning(
             "Encountered SysCallError while fetching live price, trying recursion"
         )
         self.update_price()
     except Exception as e:
         Notify.warn(
             f"[Trader #{self.number} {self.ticker}] : Exception in updating price, trying recursion"
         )
         self.logger.error(
             "Trying recursion, encountered uncommon exception : ", e)
         self.update_price()
示例#3
0
    else:
        IDLE_DELAY = 0
        master_logger.warning("[  MODE  ]  Zero delay")
else:
    IDLE_DELAY = args.delay
    master_logger.info(f"Idle delay set to {IDLE_DELAY}")

if args.np:
    PERIOD_INTERVAL = 0
    master_logger.warning("[  MODE  ]  Zero period interval")

if args.t:
    IDLE_DELAY = 1
    PERIOD_INTERVAL = 0
    Notify.warn(
        "Running in Test Mode, meant for debugging and demonstration purposes only."
    )
    master_logger.warning("[  MODE  ]  TEST")
    print("")

# developer mode
DEV_MODE = args.nd and args.np
if DEV_MODE:
    PENNY_STOCK_THRESHOLD = 0
    master_logger.warning("[  MODE  ]  DEVELOPER")

##############################################################


def is_open():
    """
示例#4
0
def main():
    """
        Main Function
    """
    # make sure that market is open
    if not DEV_MODE:
        if args.t:
            Notify.for_input("Check Market? (y/n) : ")
            confirm = input().strip().lower()
            print("")
        else:
            confirm = "y"
        if is_open() or confirm == "n":
            pass
        else:
            Notify.fatal("Market is closed at the moment, aborting.")
            print("")
            quit(0)
    else:
        Notify.warn("You are in developer mode, if not intended, please quit.")
        Notify.info("Press ENTER to continue, Ctrl+C to quit")
        input()

    # allow market to settle to launch Ichimoku strategy
    if IDLE_DELAY == 0:
        Notify.info("Skipped Idle phase")
    else:
        Notify.info(
            f"Entered Idle phase at {datetime.datetime.now(TZ).strftime('%H:%M:%S')}"
        )
        ml.info(f"Entered Idle phase")
        Notify.info(f"\tExpected release : after {IDLE_DELAY // 60} minutes")
        print("")
        sleep(IDLE_DELAY)

    ml.info("Idle phase complete")
    # find relevant stocks to focus on
    Notify.info("Finding stocks to focus on .....")
    try:
        stocks_to_focus = fetch_stocks()
    except:
        stocks_to_focus = []
        Notify.fatal(
            "Could not fetch relevant stocks. Verify Network connection and check logs for details."
        )
        ml.critical(
            "Could not fetch relevant stocks, Most possibly due to network error"
        )
        quit(0)
    Notify.info("\tStatus : Complete")
    ml.info("Successfully found relevant stocks")
    print("")

    # setup traders and begin trade
    master = Master()
    master.validate_repo()
    master.lineup_traders(stocks_to_focus)
    master.init_traders(args.t)
    master.start_trading(args.t)

    # trading in over by this point
    Notify.info("Trading complete")
    ml.info("Trading complete")

    # initiate packup
    del master
    quit(0)