python类FixedOffset()的实例源码

test_construct.py 文件源码 项目:pendulum 作者: sdispater 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_instance_timezone_aware_datetime_pytz_offset(self):
        # Impossible timezone of +21 (won't accidentally match the local offset)
        fixed_offset = pytz.FixedOffset(21 * 60)

        now = Pendulum.instance(
            datetime.now(fixed_offset)
        )
        self.assertEqual(21, now.offset_hours)

        now = Pendulum.instance(
            datetime.now(), fixed_offset
        )
        self.assertEqual(21, now.offset_hours)

        now = Pendulum.instance(
            datetime.now(fixed_offset), pytz.timezone('Europe/Paris')
        )
        self.assertEqual(21, now.offset_hours)
brother2.py 文件源码 项目:trader 作者: BigBrotherTrade 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def update_position(self):
        for _, pos in self.__shares.items():
            inst = Instrument.objects.filter(
                exchange=pos['ExchangeID'],
                product_code=re.findall('[A-Za-z]+', pos['InstrumentID'])[0]).first()
            tick = json.loads(self.redis_client.get(pos['InstrumentID']))
            if pos['Direction'] == ApiStruct.D_Buy:
                profit = Decimal(tick['LastPrice']) - Decimal(pos['OpenPrice'])
            else:
                profit = Decimal(pos['OpenPrice']) - Decimal(tick['LastPrice'])
            profit = profit * Decimal(pos['Volume']) * inst.volume_multiple
            Trade.objects.update_or_create(
                broker=self.__broker, strategy=self.__strategy, instrument=inst,
                code=pos['InstrumentID'],
                direction=DirectionType.LONG if pos['Direction'] == ApiStruct.D_Buy else DirectionType.SHORT,
                close_time__isnull=True,
                defaults={
                    'open_time': datetime.datetime.strptime(
                        pos['OpenDate']+'09', '%Y%m%d%H').replace(tzinfo=pytz.FixedOffset(480)),
                    'shares': pos['Volume'], 'filled_shares': pos['Volume'],
                    'avg_entry_price': Decimal(pos['OpenPrice']),
                    'cost': pos['Volume'] * Decimal(pos['OpenPrice']) * inst.fee_money *
                    inst.volume_multiple + pos['Volume'] * inst.fee_volume,
                    'profit': profit, 'frozen_margin': Decimal(pos['Margin'])})
brother2.py 文件源码 项目:trader 作者: BigBrotherTrade 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def start(self):
        self.redis_client.set('HEARTBEAT:TRADER', 1, ex=61)
        await self.query('TradingAccount')
        self.__shares.clear()
        await self.query('InvestorPositionDetail')
        # await self.collect_tick_stop()
        # await self.collect_quote()
        # day = datetime.datetime.strptime('20161031', '%Y%m%d').replace(tzinfo=pytz.FixedOffset(480))
        # for inst in self.__strategy.instruments.all():
        #     # self.calc_signal(inst, day)
        #     self.process_signal(inst)
        # order_list = await self.query('Order')
        # if order_list:
        #     for order in order_list:
        #         if order['OrderStatus'] == ApiStruct.OST_NotTouched and \
        #                         order['OrderSubmitStatus'] == ApiStruct.OSS_InsertSubmitted:
        #             self.__activeOrders[order['OrderRef']] = order
        #     logger.info("?????: %s", self.__activeOrders)
        # inst_set = list()
        # for inst in Instrument.objects.all():
        #     inst_set += inst.all_inst.split(',')
        # await self.SubscribeMarketData(inst_set)
fetch_data.py 文件源码 项目:trader 作者: BigBrotherTrade 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def fetch_bar():
    day = datetime.datetime.strptime('20100416', '%Y%m%d').replace(tzinfo=pytz.FixedOffset(480))
    end = datetime.datetime.strptime('20160118', '%Y%m%d').replace(tzinfo=pytz.FixedOffset(480))
    tasks = []
    while day <= end:
        tasks.append(is_trading_day(day))
        day += datetime.timedelta(days=1)
    trading_days = []
    for f in tqdm(asyncio.as_completed(tasks), total=len(tasks)):
        rst = await f
        trading_days.append(rst)
    tasks.clear()
    for day, trading in trading_days:
        if trading:
            tasks += [
                asyncio.ensure_future(update_from_shfe(day)),
                asyncio.ensure_future(update_from_dce(day)),
                asyncio.ensure_future(update_from_czce(day)),
                asyncio.ensure_future(update_from_cffex(day)),
            ]
    print('task len=', len(tasks))
    for f in tqdm(asyncio.as_completed(tasks), total=len(tasks)):
        await f
fetch_data.py 文件源码 项目:trader 作者: BigBrotherTrade 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def fetch_bar2():
    day = datetime.datetime.strptime('20160114', '%Y%m%d').replace(tzinfo=pytz.FixedOffset(480))
    end = datetime.datetime.strptime('20160914', '%Y%m%d').replace(tzinfo=pytz.FixedOffset(480))
    while day <= end:
        day, trading = await is_trading_day(day)
        if trading:
            print('process ', day)
            tasks = [
                asyncio.ensure_future(update_from_shfe(day)),
                asyncio.ensure_future(update_from_dce(day)),
                asyncio.ensure_future(update_from_czce(day)),
                asyncio.ensure_future(update_from_cffex(day)),
            ]
            await asyncio.wait(tasks)
        day += datetime.timedelta(days=1)
    print('all done!')


# asyncio.get_event_loop().run_until_complete(fetch_bar2())
# create_main_all()
# fetch_from_quandl_all()
# clean_dailybar()
# load_kt_data()
__init__.py 文件源码 项目:trader 作者: BigBrotherTrade 项目源码 文件源码 阅读 60 收藏 0 点赞 0 评论 0
def clean_daily_bar():
    day = datetime.datetime.strptime('20100416', '%Y%m%d').replace(tzinfo=pytz.FixedOffset(480))
    end = datetime.datetime.strptime('20160118', '%Y%m%d').replace(tzinfo=pytz.FixedOffset(480))
    tasks = []
    while day <= end:
        tasks.append(is_trading_day(day))
        day += datetime.timedelta(days=1)
    trading_days = []
    for f in tqdm(asyncio.as_completed(tasks), total=len(tasks)):
        rst = await f
        trading_days.append(rst)
    tasks.clear()
    for day, trading in trading_days:
        if not trading:
            DailyBar.objects.filter(time=day.date()).delete()
    print('done!')
mailnotify.py 文件源码 项目:sndlatr 作者: Schibum 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _get_localtime(send_job):
    timezone = pytz.FixedOffset(-send_job.utc_offset)
    time = pytz.utc.localize(send_job.scheduled_at)
    localtime = time.astimezone(timezone)
    return localtime
__init__.py 文件源码 项目:sndlatr 作者: Schibum 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __reduce__(self):
        return FixedOffset, (self._minutes, )
__init__.py 文件源码 项目:sndlatr 作者: Schibum 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __repr__(self):
        return 'pytz.FixedOffset(%d)' % self._minutes
__init__.py 文件源码 项目:Texty 作者: sarthfrey 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __reduce__(self):
        return FixedOffset, (self._minutes, )
__init__.py 文件源码 项目:Texty 作者: sarthfrey 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __repr__(self):
        return 'pytz.FixedOffset(%d)' % self._minutes
__init__.py 文件源码 项目:true_review 作者: lucadealfaro 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __reduce__(self):
        return FixedOffset, (self._minutes, )
__init__.py 文件源码 项目:true_review 作者: lucadealfaro 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __repr__(self):
        return 'pytz.FixedOffset(%d)' % self._minutes
__init__.py 文件源码 项目:aws-ops-automator 作者: awslabs 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __reduce__(self):
        return FixedOffset, (self._minutes,)
__init__.py 文件源码 项目:aws-ops-automator 作者: awslabs 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __repr__(self):
        return 'pytz.FixedOffset(%d)' % self._minutes
__init__.py 文件源码 项目:epg-dk.bundle 作者: ukdtom 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __reduce__(self):
        return FixedOffset, (self._minutes, )
__init__.py 文件源码 项目:epg-dk.bundle 作者: ukdtom 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __repr__(self):
        return 'pytz.FixedOffset(%d)' % self._minutes
__init__.py 文件源码 项目:respeaker_virtualenv 作者: respeaker 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __reduce__(self):
        return FixedOffset, (self._minutes, )
__init__.py 文件源码 项目:respeaker_virtualenv 作者: respeaker 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __repr__(self):
        return 'pytz.FixedOffset(%d)' % self._minutes
__init__.py 文件源码 项目:userbase-sns-lambda 作者: fartashh 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __reduce__(self):
        return FixedOffset, (self._minutes, )
__init__.py 文件源码 项目:userbase-sns-lambda 作者: fartashh 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __repr__(self):
        return 'pytz.FixedOffset(%d)' % self._minutes
__init__.py 文件源码 项目:chalktalk_docs 作者: loremIpsum1771 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __reduce__(self):
        return FixedOffset, (self._minutes, )
__init__.py 文件源码 项目:chalktalk_docs 作者: loremIpsum1771 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __repr__(self):
        return 'pytz.FixedOffset(%d)' % self._minutes
__init__.py 文件源码 项目:Callandtext 作者: iaora 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __reduce__(self):
        return FixedOffset, (self._minutes, )
__init__.py 文件源码 项目:Callandtext 作者: iaora 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __repr__(self):
        return 'pytz.FixedOffset(%d)' % self._minutes
__init__.py 文件源码 项目:script.tvguide.fullscreen 作者: primaeval 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __reduce__(self):
        return FixedOffset, (self._minutes, )
__init__.py 文件源码 项目:script.tvguide.fullscreen 作者: primaeval 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __repr__(self):
        return 'pytz.FixedOffset(%d)' % self._minutes
__init__.py 文件源码 项目:start 作者: argeweb 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __reduce__(self):
        return FixedOffset, (self._minutes, )
__init__.py 文件源码 项目:start 作者: argeweb 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __repr__(self):
        return 'pytz.FixedOffset(%d)' % self._minutes
__init__.py 文件源码 项目:alexa-apple-calendar 作者: zanderxyz 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __reduce__(self):
        return FixedOffset, (self._minutes, )


问题


面经


文章

微信
公众号

扫码关注公众号