An easy step by step tutorial about how to write an Actual Time Serie in Python SDK.

Artesian gives you straightforward access to the data history to perform an analysis and produce a plan in the most compatible way possible.

Let’s see step by step how to proceed.

The goal

Write our data in an Actual Time Series Market Data.

The reference data is fictitious, created exclusively for this case. With Artesian, it is possible to write any data attributable to a TimeSeries, making it suitable for saving your data production.

Let’s see how to proceed step by step.

Import of Artesian libraries and configuration

To write the Time Series in Python, first install the Artesian SDK in the python environment used, using the command “pip install artesian-SDK”, then importing the necessary dependencies with the command “from Artesian import ArtesianConfig, Granularity, MarketData”, and “from Artesian.MarketData import AggregationRule”.

To write the Time Series annd use the TimeZone, we need to import “datetime” from the datetime library and “tz” from the dateutil library.

First, import the necessary libraries, and then we can configure Artesian by entering the essential link and API key.

To extract these two essential pieces of data, you can refer to the tutorial How to Configure Artesian Python SDK“. 

Once the Artesian configuration is complete, we can configure the MarketData Service.

 

				
					from Artesian import ArtesianConfig, Granularity, MerketData
from Artesian.MarketData import AggregationRule
from Artesian import datetime
from dateutil import tz

cfg = ArtesianConfig("https://arkive.artesian.cloud/{tenantName}/", "{api-key}")
mkservice = MarketData.MarketDataService(cfg)
				
			

The Market Data Identifier and the data required to write the Versioned TimeSeries

Once Artesian and the Market Data Service have been configured, we can define the MarketData Identifier; that is, we can give a name to our MarketData.

In this case, the Provider’s name will be “PythonSDK”, while the name of the Market Data will be “ActualWrite”. The definition of these two fields is necessary for two reasons:

  1. The Provider and Market Data’s names represent the unique identifier of our curve on Artesian. The value combination is then translated into the MarketDataID.
  2. The Provider and Market Data’s names are necessary to find the data within the portal through the free text or category filter.

Once the market data and provider names are defined, we can decide on the essential characteristics of our Time Series, such as the type of granularity, the type of the Time Series, the Time Zone, any Aggregation Rule and the Tags.

Artesian can support different granularities such as 10min, 15min, 30min, Hour, Day, Week, Month, Quarter, Season and Year.

When we decide the type of granularity of our market data: we must write it accordingly, indicating the values. For example, in the case of Granularity Day, the data will correspond to a specific day of a certain month in a particular year. In the case of Granularity Hour, the data will correspond to a specific hour (minute and second) of a certain day in a particular month and year.

The TimeZones: must be enhanced with the one corresponding to the data we are saving; this will help the system to apply the necessary conversions to the data in the case of extractions in a TimeZone different from the original.

The Type of the Time Series: in this case is Actual, but it could also be Versioned, MarketAssessment, BidAsk or Auction. See the other tutorials.

The Aggregation Rule: in Artesian, the Aggregation Rule is the operation when data is extracted in a different granularity from the original one. You can choose whether to set it to “Undefined”, “SumAndDivide”, or “AverageAndReplicate”. In the example code, we report the Aggregation Rule SumAndDivide.

The Tags: these are not mandatory but can help categorize the data and allow us to locate them faster by scrolling through the portal menu. In our specific case, we will set the tags as “TutorialSDKPython” with “PythonValue1” inside for our market data.

				
					mkdir = MarketData.MarketDataIdentifier("PythonSDK","ActualWrite")

mkd = MarketData.MarketDataEntityInput(
    providerName=mkdir.provider,
    marketDataName=mkdir.name,
    originalGranularity=Granularity.Day,
    type=MarketData.MarketDataType.ActualTimeSerie,
    originalTimezone="UTC",
    aggregationRule=AggregationRule.AverageAndReplicate,
    tags=
    {
        "TutorialSDKPython": ["PythonValue1"]
    }
)
				
			


Control and registration of the Market Data

First, set the MarketData base; you must check if this Time Series already exists. To do this, we need to insert the Provider’s name, the market data, and unique identifiers to see if there is a match in Artesian. The data already exists if there is a match and can not be overwritten. On the other hand, if there is no response, the data is saved on Artesian through the command “registerMarketData“.

				
					registered = mkservice.readMarketDataRegistryByName(mkdir.provider, mkdir.name)
if(registered is None):
    registered = mkservice.registerMarketData(mkd)
				
			


Writing the MarketData values

The last part of our codde consists of the configuration of our write to Artesian.

The required parameters for this step are:

The MarketData identifier that we define at the beginning of our code

The reference TimeZone of the data we are writing: this must be “UTC” in the case of data with hourly or lower granularity (with adequate data conversion is necessary). It must correspond to the Original TimeZone in the case of daily granularity data or higher. This data conversion in the case of hourly or lower granularity is necessary for Artesian to correctly manage the data sent (e.g.: change of Winter/Summer time)

The Actual rows: are an array of data dictionaries in which the “key” “value” is structured as follows:

  • “key” the reference DateTime of the data
  • “value” the number we want to enter for that instant of time
 

Below there are examples of a code for writing daily or hourly data:

  • Daily data has values for January 1st and 2nd
  • Hourly data has values for January 1st, at 5,6,7,8AM
 

Artesian does not support writing values in two different granularities; these were done only as an example!

Another mandatory field to write is the DownloadedAt, a metadata type information that represents when the data was written in Artesian.

Once the previous steps have been completed, we can load the Actual Time Series into the system, using the “upsertData” command.

				
					actual = MarketData.UpsertData(mkdir, "CET",
    rows=
    {
        # Granularity.Day
        datetime(2021,1,1):42.0,
        datetime(2021,1,2):43.0,
        ...
        # Granularity.Hour
        datetime(2021,1,1,5,0,0):42.0,
        datetime(2021,1,1,6,0,0):43.0,
        datetime(2021,1,1,7,0,0):45.0,
        datetime(2021,1,1,8,0,0):44,0,
        ...
    }
    downloadedAt = datetime(2021,1,3).replace(tzinfo=tz.UTC)
    )
    mkservice.upsertData(actual)
				
			


Visualization of the new MarketData on the Artesian portal

Unless there are errors to report, nothing will appear in the terminal. However, returning to the Artesian portal, we can verify that our TimeSeries appears under the ProviderName category with the previously given name “PythonSDK”. Scrolling through the menu, we can also notice the item “TutorialSDKPython”, which is nothing more than our tag.

 

It is sufficient to employ just once and then have it entirely reproducible and automated in our workflow.

Not only does it save you time, but it allows you to minimize human errors caused by repeated operations on substantial amounts of data or different Excel files.

An undeniable advantage that allows us to focus on data analysis instead of its management and optimization.