コード例 #1
0
    def getData(formattedStartTime, formattedEndTime):
      """ Get data for specified window of time

      :param str formattedStartTime: Formatted timestamp representing the start
        of the request window
      :param str formattedEndTime: Formatted timestamp representing the end of
        the request window
      :returns: Response dict.  See xignite_stock_agent.getData()
      """
      return xignite_stock_agent.getData(
        symbol="AAPL",
        apitoken=os.environ.get("XIGNITE_API_TOKEN"),
        barlength=5,
        startTime=formattedStartTime,
        endTime=formattedEndTime,
        fields=["Outcome"])
コード例 #2
0
        def getData(formattedStartTime, formattedEndTime):
            """ Get data for specified window of time

      :param str formattedStartTime: Formatted timestamp representing the start
        of the request window
      :param str formattedEndTime: Formatted timestamp representing the end of
        the request window
      :returns: Response dict.  See xignite_stock_agent.getData()
      """
            return xignite_stock_agent.getData(
                symbol="AAPL",
                apitoken=os.environ.get("XIGNITE_API_TOKEN"),
                barlength=5,
                startTime=formattedStartTime,
                endTime=formattedEndTime,
                fields=["Outcome"])
  def testGetData(self, urllib2, metricDataBatchWriter):
    apiResponse = {
      "Outcome": "Success",
      "Message": None,
      "Identity": "Request",
      "Delay": 0.3652289,
      "Bars": [
          {
              "StartDate": "1/15/2015",
              "StartTime": "9:30:00 AM",
              "EndDate": "1/15/2015",
              "EndTime": "9:35:00 AM",
              "UTCOffset": -5,
              "Open": 46.225,
              "High": 46.38,
              "Low": 45.955,
              "Close": 45.96,
              "Volume": 504494,
              "Trades": 2414,
              "TWAP": 46.1765,
              "VWAP": 46.1756
          },
          {
              "StartDate": "1/15/2015",
              "StartTime": "9:35:00 AM",
              "EndDate": "1/15/2015",
              "EndTime": "9:40:00 AM",
              "UTCOffset": -5,
              "Open": 45.97,
              "High": 46.025,
              "Low": 45.64,
              "Close": 45.79,
              "Volume": 492621,
              "Trades": 2621,
              "TWAP": 45.8574,
              "VWAP": 45.8569
          }
      ],
      "Security": {
          "CIK": "0000789019",
          "CUSIP": None,
          "Symbol": "MSFT",
          "ISIN": None,
          "Valoren": "951692",
          "Name": "Microsoft Corp",
          "Market": "NASDAQ",
          "MarketIdentificationCode": "XNAS",
          "MostLiquidExchange": True,
          "CategoryOrIndustry": "InformationTechnologyServices"
      }
    }

    urllib2.urlopen.return_value = StringIO.StringIO(json.dumps(apiResponse))

    endTime = (datetime.datetime.now(pytz.timezone("UTC"))
                                .astimezone(pytz.timezone("US/Eastern")))

    startTime = endTime + datetime.timedelta(days=1)

    fields = ["Outcome",
              "Message",
              "Identity",
              "Delay",
              "Security",
              "Security.CIK",
              "Security.CUSIP",
              "Security.Symbol",
              "Security.ISIN",
              "Security.Valoren",
              "Security.Name",
              "Security.Market",
              "Security.MarketIdentificationCode",
              "Security.MostLiquidExchange",
              "Security.CategoryOrIndustry",
              "Bars",
              "Bars.StartDate",
              "Bars.StartTime",
              "Bars.EndDate",
              "Bars.EndTime",
              "Bars.UTCOffset",
              "Bars.Open",
              "Bars.High",
              "Bars.Low",
              "Bars.Trades"]

    result = xignite_stock_agent.getData(
      "foo",
      "bar",
      5,
      startTime.strftime(xignite_stock_agent.DATE_FMT),
      endTime.strftime(xignite_stock_agent.DATE_FMT),
      fields)

    self.assertDictEqual(result, apiResponse)

    self.assertTrue(urllib2.urlopen.called)
    args, _ = urllib2.urlopen.call_args_list[0]
    parseResult = urlparse.urlparse(args[0])
    query = urlparse.parse_qs(parseResult.query)
    self.assertSequenceEqual(query["_fields"][0].split(","), fields)
    self.assertEqual(
      startTime.replace(tzinfo=None, microsecond=0),
      datetime.datetime.strptime(query["StartTime"][0],
                                 xignite_stock_agent.DATE_FMT))
    self.assertEqual(
      endTime.replace(tzinfo=None, microsecond=0),
      datetime.datetime.strptime(query["EndTime"][0],
                                 xignite_stock_agent.DATE_FMT))
    self.assertEqual(query["Identifier"][0], "foo")
    self.assertEqual(query["_Token"][0], "bar")
    self.assertEqual(query["Period"][0], "5")