Ejemplo n.º 1
0
    def test_getLatestDate(self):

        latestDate = getLatestDate()
        self.assertEqual(latestDate, "2015-07-01 00:00:00")
Ejemplo n.º 2
0
def askHorse(argv):
    """
    "Ask Horse" i.e. Check the Active Strategies against the most recent data...

    :param argv: Command Line Parameters.

    -n = Name

    Example:

    python -m pyswing.AskHorse -n asx
    """

    Logger.log(logging.INFO, "Log Script Call", {"scope":__name__, "arguments":" ".join(argv)})
    Logger.pushLogData("script", __name__)

    marketName = ""

    try:
        shortOptions = "n:dh"
        longOptions = ["marketName=", "debug", "help"]
        opts, __ = getopt.getopt(argv, shortOptions, longOptions)
    except getopt.GetoptError as e:
        Logger.log(logging.ERROR, "Error Reading Options", {"scope": __name__, "exception": str(e)})
        usage()
        sys.exit(2)

    for opt, arg in opts:
        if opt in ("-d", "--debug"):
            Logger().setLevel(logging.DEBUG)
        elif opt in ("-h", "--help"):
            print("?")
            usage()
            sys.exit()
        elif opt in ("-n", "--marketName"):
            marketName = arg

    if marketName != "":

        pyswing.database.initialiseDatabase(marketName)

        latestDate = getLatestDate()

        Logger.log(logging.INFO, "Ask Horse", {"scope":__name__, "market":marketName, "latestDate":latestDate})

        strategies = getActiveStrategies()

        tradeDetails = []
        for strategy in strategies:
            rulesDetail = ("Rules: '%s', '%s' and '%s'") % (strategy._rule1, strategy._rule2, strategy._rule3)
            Logger.log(logging.INFO, "Checking Strategy", {"scope":__name__, "strategy":rulesDetail})
            if strategy.askHorse(latestDate):
                tradeDetails.extend(strategy.tradeDetails)

        sendEmail(tradeDetails)

        if len(tradeDetails) > 0:
            TeamCity.setBuildResultText("Horse Says Trade! (x%s)" % len(tradeDetails))
        else:
            TeamCity.setBuildResultText("Horse Says Go Back To Bed!")

    else:
        Logger.log(logging.ERROR, "Missing Options", {"scope": __name__, "options": str(argv)})
        usage()
        sys.exit(2)
Ejemplo n.º 3
0
    def test_getLatestDate(self):

        latestDate = getLatestDate()
        self.assertEqual(latestDate, "2015-07-01 00:00:00")