CFDs are complex instruments and come with a high risk of losing money rapidly due to leverage. 66 % of retail investor accounts lose money when trading CFDs with this provider. You should consider whether you understand how CFDs work and whether you can afford to take the high risk of losing your money.

Ra trades information structure?

Hi!

So I managed to obtain the information for Risk Adjustment IA, but for some reason, I’m struggling to understand the structure of trades information.

item[0] -> (long) Millis item[1] -> (double) D-Periods item[2][0] -> (double) Leverage target of day (deprecated) item[2][1] -> (double) VaR of day item[2][$position][0] -> (long) Open time of position item[2][$position][1] -> (long) Duration of position item[2][$position][2] -> (double) D-Leverage of position item[2][$position][3] -> (double) VaR adjustment of position item[2][$position][4] -> (integer) Number of open trades item[2][$position][5] -> (double) Return of position item[2][$position][6] -> (double) Leverage target of position

for item[2] I see a list of rows such as for example:
15.643229 0.139179 [[1519301008000, 19000, 13.3370734994832, 0.0,... 9.764229 0.241560 [[1529604051000, 54755999, 3.137995494210046, ... NaN NaN NaN 9.266590 0.230258 [[1530127247000, 41000, 3.2132923750775437, 0....

First two values being deprecated leverage, and VaR of day.

Just in case, this is the code to obtain the matrix I’m talking about:
def get_h_ra(self, name=None): # get historical Ra values url = self.base_url + "/products/{}/history/riskadjustment".format(name) resp = json.loads(requests.get(url, headers=self.base_headers).text) # obtain API response df = pd.DataFrame(resp) # convert to pandas Dataframe aux1 = df.iloc[:, 2].apply(pd.Series) # Get historical positions print(aux1) return aux1

Could you let me know what the list of positions represents? Are there positions for one day?

Also, if anyone could help me out on how to transform this info into a matrix it would be much appreciated. (Not a developer myself, sorry)

Well, it seems I reached a quite inefficient solution.

First, each row are positions for a day, good API documentation :sweat_smile:.

The whole Python method would be something like this:

def get_h_ra(self, name=None):
    if name is None:
        name = self.name
    url = self.base_url + "/products/{}/history/riskadjustment".format(name)
    resp = json.loads(requests.get(url, headers=self.base_headers).text)
    df = pd.DataFrame(resp)
    aux = df.iloc[:, 2].values
    out = []  # below lies the "magic"
    for x in aux:
        if x:  # each row. Avoid null values
            for y in x[2]:  # third value is the list of trades
                if y:  # Avoid null values again
                    out.append(y)
    df = pd.DataFrame(out,
                      columns=["OpenDate", "Duration (ms)", "D-Leverage",
                                "VaR Adjust", "No. trades", "Return",
                                "Leverage tgt"])
    df["OpenDate"] = pd.to_datetime(df["OpenDate"], unit="ms")
    df.set_index("OpenDate", inplace=True)
    return df