-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
64 lines (57 loc) · 1.91 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
Run monofeed.py to obtain some data locally. Then you can run main.py for basic tests.
"""
from querydb import CsvDBQuery
from db import csvDB
from schema import RangeQuery, Tick
import pandas as pd
if __name__ == "__main__":
query = RangeQuery()
dtTo1 = "12/13/23"
dtFrom1 = "12/13/22"
ex1 = "COINBASE"
sym1 = "ETH-USDT"
db = csvDB({
"path":"test_path/file.csv",
"type":Tick,
"fields":["exchange","symbol","bid","ask","timestamp","time_received"],
})
dbquery = CsvDBQuery(db)
# query 1
query.addFrom(dtFrom1)
query.addTo(dtFrom1)
query.addExchange(ex1)
query.addSymbol(sym1)
original_df = db.read()
df = dbquery.select(query)
original_df["timestamp"] = pd.to_datetime(original_df["timestamp"])
assert len(df[df[df.symbol != "ETH-USDT"]]) == 0
dftest1 = original_df[original_df["symbol"]== "ETH-USDT"]
dftest1 = dftest1[dftest1["exchange"] == "COINBASE"]
dftest1 = dftest1[dftest1["timestamp"].dt.date <= query["to"].date()]
dftest1 = dftest1[dftest1["timestamp"].dt.date >= query["from"].date()]
assert df.equals(dftest1)
# query 2
query.addSymbol("BTC-USDT")
df = dbquery.select(query)
assert len(df[df.symbol != "BTC-USDT"]) == 0
dftest2 = original_df[original_df["symbol"]== "ETH-USDT"]
dftest2 = dftest2[dftest2["exchange"] == "COINBASE"]
dftest2 = dftest2[dftest2["timestamp"].dt.date <= query["to"].date()]
dftest2 = dftest2[dftest2["timestamp"].dt.date >= query["from"].date()]
assert df.equals(dftest2)
# query 3
query.addSymbol("dummyval")
df = dbquery.select(query)
assert len(df) == 0
# query 4
del query["symbol"]
query.addTo("12/14/22")
df = dbquery.select(query)
assert len(df) == 0
# query 5
del query["to"]
query.addExchange("dummyval")
df = dbquery.select(query)
assert len(df) == 0
print("ALL TESTS PASSED!")