Skip to content

Commit

Permalink
Update code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jamespeterschinner committed Dec 21, 2017
1 parent 9cb7887 commit 2579172
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions doc/source/datetimes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,72 +19,72 @@ of serializing to the correct JSON format OANDA expects.

.. code-block:: python
from async_v20 import DateTime
unix_example = '1502463871.639182000'
rfc3339_example = '2017-08-11T15:04:31.639182000Z'
dt = DateTime(unix_example)
dt
>>> from async_v20 import DateTime
>>> unix_example = '1502463871.639182000'
>>> rfc3339_example = '2017-08-11T15:04:31.639182000Z'
>>> dt = DateTime(unix_example)
>>> dt
Timestamp('2017-08-11 15:04:31.639182+0000', tz='UTC')
dt.json('RFC3339')
>>> dt.json('RFC3339')
'2017-08-11T15:04:31.639182000Z'
dt.json('UNIX')
>>> dt.json('UNIX')
'1502463871.639182000'
dt.json('UNIX') == unix_example
>>> dt.json('UNIX') == unix_example
True
dt = DateTime(rfc3339_example)
dt.json('UNIX')
>>> dt = DateTime(rfc3339_example)
>>> dt.json('UNIX')
'1502463871.639182000'
dt.json('UNIX') == unix_example
>>> dt.json('UNIX') == unix_example
True
**Creating from time.time()**

.. code-block:: python
from async_v20 import DateTime
from time import time
dt = DateTime(time())
dt
>>> from async_v20 import DateTime
>>> from time import time
>>> dt = DateTime(time())
>>> dt
Timestamp('2017-12-21 01:22:37.762530+0000', tz='UTC')
dt.json('UNIX')
>>> dt.json('UNIX')
'1513819357.762530000'
dt.json('RFC3339')
>>> dt.json('RFC3339')
'2017-12-21T01:22:37.762530000Z'
**Creating from datetime.datetime.now()**

.. code-block:: python
from async_v20 import DateTime
from datetime import datetime
dt = DateTime(datetime.now())
dt
>>> from async_v20 import DateTime
>>> from datetime import datetime
>>> dt = DateTime(datetime.now())
>>> dt
Timestamp('2017-12-21 12:31:03.982327')
**DataFrame**

.. code-block:: python
from async_v20 import OandaClient
import asyncio
loop = asyncio.get_event_loop()
run = loop.run_until_complete
client = OandaClient()
rsp = run(client.get_candles('EUR_USD'))
df = rsp.candles.dataframe()
df.time[0]
Timestamp('2017-12-20 23:30:40+0000', tz='UTC')
df = rsp.candles.dataframe(datetime_format='RFC3339')
df.time[0]
>>> from async_v20 import OandaClient
>>> import asyncio
>>> loop = asyncio.get_event_loop()
>>> run = loop.run_until_complete
>>> client = OandaClient()
>>> rsp = run(client.get_candles('EUR_USD'))
>>> df = rsp.candles.dataframe()
>>> df.time[0]
... Timestamp('2017-12-20 23:30:40+0000', tz='UTC')
>>> df = rsp.candles.dataframe(datetime_format='RFC3339')
>>> df.time[0]
'2017-12-20T23:30:40.000000000Z'
df = rsp.candles.dataframe(datetime_format='UNIX')
df.time[0]
>>> df = rsp.candles.dataframe(datetime_format='UNIX')
>>> df.time[0]
1513812640000000000
type(df.time[0])
>>> type(df.time[0])
# <class 'numpy.int64'>
df = rsp.candles.dataframe(json=True, datetime_format='UNIX')
df.time[0]
>>> df = rsp.candles.dataframe(json=True, datetime_format='UNIX')
>>> df.time[0]
'1513812640.000000000'
type(df.time[0])
>>> type(df.time[0])
# <class 'str'>

0 comments on commit 2579172

Please sign in to comment.