This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import numpy as np | |
from deephaven import npy | |
import math | |
keras = tf.keras | |
def table_cache_gen(feature_table, label_table, cache_size=1_000_000, batch_size=32, dtype=tf.float32): | |
""" | |
Creates a generator to use a Deephaven table with Tensorflow for large data sets. | |
:param feature_table: Deephaven table storing the features or X values. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
train_gen = get_table_generator(x_train_table, y_train_table, cache_size=500_000, batch_size=16, dtype=tf.float32) | |
hist = model.fit(train_gen, epochs=10) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
from deephaven import npy | |
t = db.t(...) # Some table query | |
tensor = tf.constant(npy.numpy_slice(t, 0, t.size(), dtype=tf.float32.as_numpy_dtype)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from deephaven import npy | |
import numpy as np | |
import pandas as pd | |
t = db.t(...) # Some table query | |
df = pd.DataFrame( | |
data=npy.numpy_slice(t, 0, t.size(), dtype=np.float32), | |
columns=t.getDefinition().getColumnNamesArray() | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from deephaven import npy | |
import numpy as np | |
t = db.t(...) # Some table query | |
np_arr = npy.numpy_slice(t, 0, t.size(), dtype=np.float32) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OMS { | |
... | |
// Record the trade to our input table | |
async recordTrade(trade) { | |
console.log(`Recording trade for: ${trade.Symbol}`); | |
let inputTable = this.tradeTable; | |
try { | |
await inputTable.addRow({ | |
Symbol: trade.Symbol, | |
Timestamp: iris.DateWrapper.ofJsDate(new Date()).asNumber(), // Timestamp is used to uniquely identify. Should really use a tradeID |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OMS { | |
... | |
async placeOrder(e) { | |
const tradeColNames = this.orderTable.columns.map(c => c.name); | |
const rowData = e.detail.row.dataColumns; | |
let orderObj = {Exchange: 'NASDAQ'}; | |
for (let i = 0; i < tradeColNames.length; i++) { | |
orderObj[tradeColNames[i]] = rowData[i][e.detail.index]; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OMS { | |
... | |
// Returns Promise<boolean> if trade is accepted | |
fakeOMS(order) { | |
console.log(`Placing order for: ${order.Symbol}`); | |
return new Promise((resolve, reject) => { | |
setTimeout( | |
resolve, | |
Math.floor(Math.random() * 10000), // Wait between 0 and 10 seconds | |
Math.random() > 0.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OMS { | |
... | |
setupTradeListener() { | |
let table = this.orderTable; | |
this.lastKnownSize = table.size; | |
// Use sizechanged to see if there was more than 1 row added in the last second | |
table.addEventListener('sizechanged', e => { | |
table.setViewport(this.lastKnownSize, e.detail); | |
this.lastKnownSize = e.detail; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OMS { | |
constructor(client) { | |
const pqName = 'OMS Example'; | |
const orderTableName = 'orders'; | |
const tradeTableName = 'trades'; | |
this.client = client; | |
this.query = null; | |
this.orderTable = null; | |
this.tradeTable = null; | |
this.lastKnownSize = 0; |
NewerOlder