本文整理汇总了Python中pytz.FixedOffset方法的典型用法代码示例。如果您正苦于以下问题:Python pytz.FixedOffset方法的具体用法?Python pytz.FixedOffset怎么用?Python pytz.FixedOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pytz
的用法示例。
在下文中一共展示了pytz.FixedOffset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fetch_bar
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import FixedOffset [as 别名]
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
示例2: fetch_bar2
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import FixedOffset [as 别名]
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()
示例3: update_position
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import FixedOffset [as 别名]
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'])})
示例4: start
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import FixedOffset [as 别名]
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)
示例5: update_equity
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import FixedOffset [as 别名]
def update_equity(self):
today, trading = await is_trading_day(datetime.datetime.today().replace(tzinfo=pytz.FixedOffset(480)))
if trading:
logger.info('更新资金净值 %s %s', today, trading)
dividend = Performance.objects.filter(
broker=self.__broker, day__lt=today.date()).aggregate(Sum('dividend'))['dividend__sum']
if dividend is None:
dividend = Decimal(0)
perform = Performance.objects.filter(
broker=self.__broker, day__lt=today.date()).order_by('-day').first()
if perform is None:
unit = Decimal(1000000)
else:
unit = perform.unit_count
nav = self.__current / unit
accumulated = (self.__current - dividend) / (unit - dividend)
Performance.objects.update_or_create(broker=self.__broker, day=today.date(), defaults={
'used_margin': self.__margin,
'capital': self.__current, 'unit_count': unit, 'NAV': nav, 'accumulated': accumulated})
示例6: test_parse_timezone
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import FixedOffset [as 别名]
def test_parse_timezone(all_parsers):
# see gh-22256
parser = all_parsers
data = """dt,val
2018-01-04 09:01:00+09:00,23350
2018-01-04 09:02:00+09:00,23400
2018-01-04 09:03:00+09:00,23400
2018-01-04 09:04:00+09:00,23400
2018-01-04 09:05:00+09:00,23400"""
result = parser.read_csv(StringIO(data), parse_dates=["dt"])
dti = pd.date_range(start="2018-01-04 09:01:00",
end="2018-01-04 09:05:00", freq="1min",
tz=pytz.FixedOffset(540))
expected_data = {"dt": dti, "val": [23350, 23400, 23400, 23400, 23400]}
expected = DataFrame(expected_data)
tm.assert_frame_equal(result, expected)
示例7: __init__
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import FixedOffset [as 别名]
def __init__(self, latitude, longitude, tz='UTC', altitude=0,
name=None, **kwargs):
self.latitude = latitude
self.longitude = longitude
if isinstance(tz, str):
self.tz = tz
self.pytz = pytz.timezone(tz)
elif isinstance(tz, datetime.timezone):
self.tz = 'UTC'
self.pytz = pytz.UTC
elif isinstance(tz, datetime.tzinfo):
self.tz = tz.zone
self.pytz = tz
elif isinstance(tz, (int, float)):
self.tz = tz
self.pytz = pytz.FixedOffset(tz*60)
else:
raise TypeError('Invalid tz specification')
self.altitude = altitude
self.name = name
示例8: test_query_cond_greater_than
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import FixedOffset [as 别名]
def test_query_cond_greater_than(self):
# Make sure type checking works
q1 = Field("test")
self.assertRaises(QueryTypeError, q1.gt, "a")
# Make sure a valid operation works
q2 = Field("test").gt(1)
self.assertEqual(str(q2), "test>1")
# Make sure naive dates are assumed as UTC
q3 = Field("test").gt(dt(2016, 2, 1))
self.assertEqual(str(q3), 'test>javascript:gs.dateGenerate("2016-02-01 00:00:00")')
# Make sure tz-aware dates are converted to UTC (UTC+1)
q4 = (
Field("test")
.gt(dt(2016, 2, 1, 3, tzinfo=pytz.FixedOffset(60)))
)
self.assertEqual(str(q4), 'test>javascript:gs.dateGenerate("2016-02-01 02:00:00")')
示例9: test_query_cond_less_than
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import FixedOffset [as 别名]
def test_query_cond_less_than(self):
# Make sure type checking works
q1 = Field("test")
self.assertRaises(QueryTypeError, q1.lt, "a")
# Make sure a valid operation works
q2 = Field("test").lt(1)
self.assertEqual(str(q2), "test<1")
# Make sure naive dates are assumed as UTC
q3 = Field("test").lt(dt(2016, 2, 1))
self.assertEqual(str(q3), 'test<javascript:gs.dateGenerate("2016-02-01 00:00:00")')
# Make sure tz-aware dates are converted to UTC (UTC+1)
q3 = (
Field("test")
.lt(dt(2016, 2, 1, 3, tzinfo=pytz.FixedOffset(60)))
)
self.assertEqual(str(q3), 'test<javascript:gs.dateGenerate("2016-02-01 02:00:00")')
示例10: test_query_cond_greater_than_or_equal
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import FixedOffset [as 别名]
def test_query_cond_greater_than_or_equal(self):
# Make sure type checking works
q1 = Field("test")
self.assertRaises(QueryTypeError, q1.gte, "a")
# Make sure a valid operation works
q2 = Field("test").gte(1)
self.assertEqual(str(q2), "test>=1")
# Make sure naive dates are assumed as UTC
q3 = Field("test").gte(dt(2016, 2, 1))
self.assertEqual(str(q3), 'test>=javascript:gs.dateGenerate("2016-02-01 00:00:00")')
# Make sure tz-aware dates are converted to UTC (UTC+1)
q4 = (
Field("test")
.gte(dt(2016, 2, 1, 3, tzinfo=pytz.FixedOffset(60)))
)
self.assertEqual(str(q4), 'test>=javascript:gs.dateGenerate("2016-02-01 02:00:00")')
示例11: test_query_cond_less_than_or_equal
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import FixedOffset [as 别名]
def test_query_cond_less_than_or_equal(self):
# Make sure type checking works
q1 = Field("test")
self.assertRaises(QueryTypeError, q1.lte, "a")
# Make sure a valid operation works
q2 = Field("test").lte(1)
self.assertEqual(str(q2), "test<=1")
# Make sure naive dates are assumed as UTC
q3 = Field("test").lte(dt(2016, 2, 1))
self.assertEqual(str(q3), 'test<=javascript:gs.dateGenerate("2016-02-01 00:00:00")')
# Make sure tz-aware dates are converted to UTC (UTC+1)
q3 = (
Field("test")
.lte(dt(2016, 2, 1, 3, tzinfo=pytz.FixedOffset(60)))
)
self.assertEqual(str(q3), 'test<=javascript:gs.dateGenerate("2016-02-01 02:00:00")')
示例12: test_query_cond_greater_than
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import FixedOffset [as 别名]
def test_query_cond_greater_than(self):
# Make sure type checking works
q1 = pysnow.QueryBuilder().field("test")
self.assertRaises(QueryTypeError, q1.greater_than, "a")
# Make sure a valid operation works
q2 = pysnow.QueryBuilder().field("test").greater_than(1)
self.assertEqual(str(q2), "test>1")
# Make sure naive dates are assumed as UTC
q3 = pysnow.QueryBuilder().field("test").greater_than(dt(2016, 2, 1))
self.assertEqual(str(q3), "test>2016-02-01 00:00:00")
# Make sure tz-aware dates are converted to UTC (UTC+1)
q4 = (
pysnow.QueryBuilder()
.field("test")
.greater_than(dt(2016, 2, 1, 3, tzinfo=pytz.FixedOffset(60)))
)
self.assertEqual(str(q4), "test>2016-02-01 02:00:00")
示例13: test_query_cond_less_than
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import FixedOffset [as 别名]
def test_query_cond_less_than(self):
# Make sure type checking works
q1 = pysnow.QueryBuilder().field("test")
self.assertRaises(QueryTypeError, q1.less_than, "a")
# Make sure a valid operation works
q2 = pysnow.QueryBuilder().field("test").less_than(1)
self.assertEqual(str(q2), "test<1")
# Make sure naive dates are assumed as UTC
q3 = pysnow.QueryBuilder().field("test").less_than(dt(2016, 2, 1))
self.assertEqual(str(q3), "test<2016-02-01 00:00:00")
# Make sure tz-aware dates are converted to UTC (UTC+1)
q3 = (
pysnow.QueryBuilder()
.field("test")
.less_than(dt(2016, 2, 1, 3, tzinfo=pytz.FixedOffset(60)))
)
self.assertEqual(str(q3), "test<2016-02-01 02:00:00")
示例14: test_query_cond_less_than_or_equal
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import FixedOffset [as 别名]
def test_query_cond_less_than_or_equal(self):
# Make sure type checking works
q1 = pysnow.QueryBuilder().field("test")
self.assertRaises(QueryTypeError, q1.less_than_or_equal, "a")
# Make sure a valid operation works
q2 = pysnow.QueryBuilder().field("test").less_than_or_equal(1)
self.assertEqual(str(q2), "test<=1")
# Make sure naive dates are assumed as UTC
q3 = pysnow.QueryBuilder().field("test").less_than_or_equal(dt(2016, 2, 1))
self.assertEqual(str(q3), "test<=2016-02-01 00:00:00")
# Make sure tz-aware dates are converted to UTC (UTC+1)
q3 = (
pysnow.QueryBuilder()
.field("test")
.less_than_or_equal(dt(2016, 2, 1, 3, tzinfo=pytz.FixedOffset(60)))
)
self.assertEqual(str(q3), "test<=2016-02-01 02:00:00")
示例15: asn1_generalizedtime_to_dt
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import FixedOffset [as 别名]
def asn1_generalizedtime_to_dt(timestamp):
"""Convert ASN.1 GENERALIZEDTIME to datetime.
Useful for deserialization of `OpenSSL.crypto.X509.get_notAfter` and
`OpenSSL.crypto.X509.get_notAfter` outputs.
TODO: Implement remaining two formats: *+hhmm, *-hhmm.
>>> asn1_generalizedtime_to_dt('201511150803Z')
datetime.datetime(2015, 11, 15, 8, 0, 3, tzinfo=<UTC>)
>>> asn1_generalizedtime_to_dt('201511150803+1512')
datetime.datetime(2015, 11, 15, 8, 0, 3, tzinfo=pytz.FixedOffset(912))
>>> asn1_generalizedtime_to_dt('201511150803-1512')
datetime.datetime(2015, 11, 15, 8, 0, 3, tzinfo=pytz.FixedOffset(-912))
"""
dt = datetime.datetime.strptime( # pylint: disable=invalid-name
timestamp[:12], '%Y%m%d%H%M%S')
# tzinfo, pylint bug | pylint: disable=redefined-variable-type
if timestamp.endswith('Z'):
tzinfo = pytz.utc
else:
sign = -1 if timestamp[-5] == '-' else 1
tzinfo = pytz.FixedOffset(
sign * (int(timestamp[-4:-2]) * 60 + int(timestamp[-2:])))
return tzinfo.localize(dt)