Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ticking_crypto_milliseconds byte casting #2113

Merged
merged 2 commits into from
Mar 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions Integrations/python/deephaven/tutorials/crypto_trades.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,28 @@ def ct_distributor(cnt):
if n <= 0:
return int(i)


def ticking_crypto_milliseconds(interval: int):
from deephaven.TableTools import timeTable
from deephaven.DateTimeUtils import currentTime, minus
t = timeTable(minus(currentTime(), 1800000000000), '00:00:00.' + str(interval * 1000).zfill(6)).update(
'Id=(int)random.randint(12000000,1100000000)', 'B=random.randint(0,1)', 'C=random.randint(0,50)',
'D= ((int) (random.randint(0,100))/100.0 - 0.5) * 20000.0', 'Instrument=ct_symbols[((int)ct_distributor(ct_x))-1]',
'Size=(((int) random.randint(1, 100)) / ((int) random.randint(1, 100)))',
'Price=(double)ct_pricer(Instrument, D)', 'Exchange = ct_exchanges[(int)C%ct_y]',
'D= ((int)(byte) (random.randint(0,100))/100.0 - 0.5) * 20000.0', 'Instrument=ct_symbols[((int)(byte)ct_distributor(ct_x))-1]',
'Size=(((int)(byte) random.randint(1, 100)) / ((int)(byte) random.randint(1, 100)))',
'Price=(double)ct_pricer(Instrument, D)', 'Exchange = ct_exchanges[(int)(byte)C%ct_y]',
'Date = formatDate(Timestamp, TZ_NY)') \
.dropColumns('B', 'C', 'D') \
.moveColumnsUp('Date', 'Timestamp', 'Id', 'Instrument', 'Exchange', 'Price', 'Size')
return t

def ticking_crypto_milliseconds_v2(interval: int):
from deephaven2 import time_table
from deephaven.DateTimeUtils import currentTime, minus
t = time_table('00:00:00.' + str(interval * 1000).zfill(6),minus(currentTime(), 1800000000000)).update(formulas = [
'Id=(int)random.randint(12000000,1100000000)', 'B=random.randint(0,1)', 'C=random.randint(0,50)',
'D= ((int)(byte) (random.randint(0,100))/100.0 - 0.5) * 20000.0', 'Instrument=ct_symbols[((int)(byte)ct_distributor(ct_x))-1]',
'Size=(((int)(byte) random.randint(1, 100)) / ((int)(byte) random.randint(1, 100)))',
'Price=(double)ct_pricer(Instrument, D)', 'Exchange = ct_exchanges[(int)(byte)C%ct_y]',
'Date = formatDate(Timestamp, TZ_NY)']) \
.drop_columns(cols = ['B', 'C', 'D']) \
.move_columns_up(cols = ['Date', 'Timestamp', 'Id', 'Instrument', 'Exchange', 'Price', 'Size'])
return t