• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python dt.datetime_to_timestamp函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyalgotrade.utils.dt.datetime_to_timestamp函数的典型用法代码示例。如果您正苦于以下问题:Python datetime_to_timestamp函数的具体用法?Python datetime_to_timestamp怎么用?Python datetime_to_timestamp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了datetime_to_timestamp函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: getBars

    def getBars(self, instrument, frequency, timezone=None, fromDateTime=None, toDateTime=None):
        instrument = normalize_instrument(instrument)
        sql = "select bar.timestamp, bar.open, bar.high, bar.low, bar.close, bar.volume, bar.adj_close, bar.frequency" \
            " from bar join instrument on (bar.instrument_id = instrument.instrument_id)" \
            " where instrument.name = ? and bar.frequency = ?"
        args = [instrument, frequency]

        if fromDateTime is not None:
            sql += " and bar.timestamp >= ?"
            args.append(dt.datetime_to_timestamp(fromDateTime))
        if toDateTime is not None:
            sql += " and bar.timestamp <= ?"
            args.append(dt.datetime_to_timestamp(toDateTime))

        sql += " order by bar.timestamp asc"
        cursor = self.__connection.cursor()
        cursor.execute(sql, args)
        ret = []
        for row in cursor:
            dateTime = dt.timestamp_to_datetime(row[0])
            if timezone:
                dateTime = dt.localize(dateTime, timezone)
            ret.append(bar.BasicBar(dateTime, row[1], row[2], row[3], row[4], row[5], row[6], row[7]))
        cursor.close()
        return ret
开发者ID:363158858,项目名称:pyalgotrade-cn,代码行数:25,代码来源:sqlitefeed.py


示例2: onNewValue

 def onNewValue(self, dateTime, value):
     technical.EventWindow.onNewValue(self, dateTime, value)
     if value is not None:
         timestamp = dt.datetime_to_timestamp(dateTime)
         if len(self.__timestamps):
             assert(timestamp > self.__timestamps[-1])
         self.__timestamps.append(timestamp)
开发者ID:Chin-I,项目名称:pyalgotrade,代码行数:7,代码来源:linreg.py


示例3: get_slot_datetime

def get_slot_datetime(dateTime, frequency):
	ts = dt.datetime_to_timestamp(dateTime)
	slot = ts / frequency
	slotTs = (slot + 1) * frequency - 1
	ret = dt.timestamp_to_datetime(slotTs, False)
	if not dt.datetime_is_naive(dateTime):
		ret = dt.localize(ret, dateTime.tzinfo)
	return ret
开发者ID:imoran21,项目名称:Pyalgo-Django,代码行数:8,代码来源:resampled.py


示例4: __init__

    def __init__(self, dateTime, frequency):
        assert isinstance(frequency, int)
        assert frequency > 1
        assert frequency < bar.Frequency.DAY

        ts = int(dt.datetime_to_timestamp(dateTime))
        slot = int(ts / frequency)
        slotTs = slot * frequency
        self.__begin = dt.timestamp_to_datetime(slotTs, not dt.datetime_is_naive(dateTime))
        if not dt.datetime_is_naive(dateTime):
            self.__begin = dt.localize(self.__begin, dateTime.tzinfo)
        self.__end = self.__begin + datetime.timedelta(seconds=frequency)
开发者ID:363158858,项目名称:pyalgotrade-cn,代码行数:12,代码来源:resamplebase.py


示例5: addBar

    def addBar(self, instrument, bar, frequency):
        instrument = normalize_instrument(instrument)
        instrumentId = self.__getOrCreateInstrument(instrument)
        timeStamp = dt.datetime_to_timestamp(bar.getDateTime())

        try:
            sql = "insert into bar (instrument_id, frequency, timestamp, open, high, low, close, volume, adj_close) values (?, ?, ?, ?, ?, ?, ?, ?, ?)"
            params = [instrumentId, frequency, timeStamp, bar.getOpen(), bar.getHigh(), bar.getLow(), bar.getClose(), bar.getVolume(), bar.getAdjClose()]
            self.__connection.execute(sql, params)
        except sqlite3.IntegrityError:
            sql = "update bar set open = ?, high = ?, low = ?, close = ?, volume = ?, adj_close = ?" \
                " where instrument_id = ? and frequency = ? and timestamp = ?"
            params = [bar.getOpen(), bar.getHigh(), bar.getLow(), bar.getClose(), bar.getVolume(), bar.getAdjClose(), instrumentId, frequency, timeStamp]
            self.__connection.execute(sql, params)
开发者ID:363158858,项目名称:pyalgotrade-cn,代码行数:14,代码来源:sqlitefeed.py


示例6: testTimeStampConversionsWithMicroseconds

    def testTimeStampConversionsWithMicroseconds(self):
        dateTime = datetime.datetime(2000, 1, 1, 1, 1, 1, microsecond=10)
        self.assertEqual(dt.timestamp_to_datetime(dt.datetime_to_timestamp(dateTime), False), dateTime)

        dateTime = dt.as_utc(datetime.datetime(2000, 1, 1, 1, 1, 1, microsecond=10))
        self.assertEqual(dt.timestamp_to_datetime(dt.datetime_to_timestamp(dateTime), True), dateTime)
开发者ID:gansaihua,项目名称:pyalgotrade,代码行数:6,代码来源:utils_test.py


示例7: testTimeStampConversions

    def testTimeStampConversions(self):
        dateTime = datetime.datetime(2000, 1, 1)
        self.assertEqual(dt.timestamp_to_datetime(dt.datetime_to_timestamp(dateTime), False), dateTime)

        dateTime = dt.as_utc(datetime.datetime(2000, 1, 1, 1, 1))
        self.assertEqual(dt.timestamp_to_datetime(dt.datetime_to_timestamp(dateTime), True), dateTime)
开发者ID:gansaihua,项目名称:pyalgotrade,代码行数:6,代码来源:utils_test.py


示例8: datetime_to_tid

def datetime_to_tid(dateTime):
    unixTime = dt.datetime_to_timestamp(dt.as_utc(dateTime))
    return timestamp_to_tid(unixTime)
开发者ID:stephenagyeman,项目名称:pyalgotrade,代码行数:3,代码来源:base.py


示例9: getValueAt

 def getValueAt(self, dateTime):
     return self.__getValueAtImpl(dt.datetime_to_timestamp(dateTime))
开发者ID:Chin-I,项目名称:pyalgotrade,代码行数:2,代码来源:linreg.py



注:本文中的pyalgotrade.utils.dt.datetime_to_timestamp函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python dt.localize函数代码示例发布时间:2022-05-25
下一篇:
Python dt.datetime_is_naive函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap