-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestWriteDataAndDeleteBidAsk.py
108 lines (88 loc) · 2.74 KB
/
TestWriteDataAndDeleteBidAsk.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from datetime import datetime
import Artesian
from Artesian import Query
from dateutil import tz
from Artesian import MarketData
from Artesian.Granularity import Granularity
cfg = Artesian.ArtesianConfig("https://arkive.artesian.cloud/tenantName/", "APIKey")
mkdservice = Artesian.MarketData.MarketDataService(cfg)
bidAsk = Artesian.MarketData.MarketDataEntityInput(
"PythonSDK",
"TestBidAskWriteAndDelete",
Granularity.Hour,
MarketData.MarketDataType.BidAsk,
"CET",
tags={"TestSDKPython": ["PythonValue2"]},
)
registered = mkdservice.readMarketDataRegistryByName(
bidAsk.providerName, bidAsk.marketDataName
)
if registered is None:
registered = mkdservice.registerMarketData(bidAsk)
bidAskData = {
datetime(2020, 1, 1, h): {
"Feb-20": MarketData.BidAskValue(bestBidPrice=15.0, lastQuantity=14.0),
"Mar-20": MarketData.BidAskValue(bestBidPrice=25.0, lastQuantity=24.0),
}
for h in range(0, 23)
}
bidAsk = MarketData.UpsertData(
Artesian.MarketData.MarketDataIdentifier(
bidAsk.providerName, bidAsk.marketDataName
),
"UTC",
bidAsk=bidAskData,
downloadedAt=datetime(2020, 1, 3).replace(tzinfo=tz.UTC),
)
mkdservice.upsertData(bidAsk)
query = Query.QueryService(cfg)
res = (
query.createBidAsk()
.forMarketData([registered.marketDataId])
.inAbsoluteDateRange("2020-01-01", "2020-01-02")
.forProducts(["Feb-20", "Mar-20"])
.inTimeZone("CET")
.execute()
)
print(res)
# Delete data between 2020-01-01 6am and 2020-01-01 6pm for product Feb-18
deleteData = Artesian.MarketData.DeleteData(
ID=Artesian.MarketData.MarketDataIdentifier(
registered.providerName, registered.marketDataName
),
timezone="CET",
rangeStart=datetime(2020, 1, 1, 6),
rangeEnd=datetime(2020, 1, 1, 18),
product=["Feb-20"],
)
mkdservice.deleteData(deleteData)
res = (
query.createBidAsk()
.forMarketData([registered.marketDataId])
.inAbsoluteDateRange("2020-01-01", "2020-01-31")
.forProducts(["Feb-20", "Mar-20"])
.inTimeZone("CET")
.execute()
)
print(res)
# Delete data between 2020-01-01 6am and 2020-01-01 6pm for product Feb-18 without Timezone
deleteData = Artesian.MarketData.DeleteData(
ID=Artesian.MarketData.MarketDataIdentifier(
registered.providerName, registered.marketDataName
),
rangeStart=datetime(2020, 1, 1, 6),
rangeEnd=datetime(2020, 1, 1, 18),
product=["Feb-20"],
)
mkdservice.deleteData(deleteData)
res = (
query.createBidAsk()
.forMarketData([registered.marketDataId])
.inAbsoluteDateRange("2020-01-01", "2020-01-31")
.forProducts(["Feb-20", "Mar-20"])
.inTimeZone("CET")
.execute()
)
print(res)
# Delete the curve completely
mkdservice.deleteMarketData(registered.marketDataId)