-
Notifications
You must be signed in to change notification settings - Fork 4
connection
Jo Shinonome edited this page Aug 17, 2024
·
1 revision
from kola import Q| parameter | default | note |
|---|---|---|
| host | hostname or ip | |
| port | port number | |
| user | OS Username | |
| passwd | "" | |
| enable_tls | False | |
| retries | 0 times | exponential back off retry, 1s, 2s, 4s ... |
| timeout | 0 second | timeout error, "Resource temporarily unavailable" |
import kola
# disable retries and timeout
q = kola.Q('localhost', 1800)
# with retries for IO Errors, 1s, 2s, 4s
q = kola.Q('localhost', 1800, retries=3)
# with read timeout 2s, "Resource temporarily unavailable"
q = kola.Q('localhost', 1800, retries=3, timeout=2)Automatically connect when querying q process
q.connect()Automatically disconnect if any IO error
q.disconnect()q.sync("select from trade where date=last date")When the first string starts with { and ends with }, it is treated as a lambda.
d = {"a": 1, "b": 2}
q.sync("{key x}", d)For functional query, kola supports Python Basic Data Type, pl.Series, pl.DataFrame and Python Dictionary with string keys and Python Basic Data Type and pl.Series values.
from datetime import date, time
q.sync(
".gw.query",
"table",
{
"date": date(2023, 11, 21),
"syms": pl.Series("", ["sym0", "sym1"], pl.Categorical),
# 09:00
"startTime": time(9),
# 11:30
"endTime": time(11, 30),
},
)# pl_df is a Polars DataFrame
q.sync("upsert", "table", pl_df)# pd_df is a Pandas DataFrame, use pl.DateFrame to cast Pandas DataFrame
q.sync("upsert", "table", pl.DataFrame(pd_df))# pl_df is a Polars DataFrame
q.asyn("upsert", "table", pl_df)from kola import QType
q.sync(".u.sub", pl.Series("", ["table1", "table2"], QType.Symbol), "")
# specify symbol filter
q.sync(
".u.sub",
pl.Series("", ["table1", "table2"], QType.Symbol),
pl.Series("", ["sym1", "sym2"], QType.Symbol),
)
while true:
# sample return, ("upd", "table", pl.Dataframe)
upd = self.q.receive()
print(upd)