Postman Visualizer Example with Stock Trading Data

Hi everyone!

I made a Postman Visualizer tutorial and breakdown that I thought would be helpful. I based it on an existing template they had, and created one with financial data from worldtradingdata.com, showing stock performance over the day.

How to Visualize Data in Postman

Hope this is helpful!

Thanks,
Orest

6 Likes

:trophy: Nicely done @odanylewycz !

1 Like

Thank you @joyce! :smile:

Great video… but I’m really struggling with how to get to data in more complex arrays. Where would you suggest I start to learn how to acccess these? For example - I may have an array of 'portfolio’s - each with an array of securities and values, followed by an array of totals. I tried your object.keys and object.values but can’t get to where I need to … any hints on where to go to learn apprediated.

1 Like

Hi @thomas.zdon!

Thanks for watching my video! :slight_smile:

Now as for accessing those values, and getting them back in an array, you can use lodash to do that.

For example, you have an array of porfolios, each with an array of securities.

To first get access to it, I assume we have a an object named results

To get your porfolios array, we can do:

var portfolios = results.porfolios

Now to get all the securities values, we can do this:

var securities = _.map(Object.values(porfolios), 'securities')

That should get you the values of all the securities in an array.

If you needed to go even deeper, just start with a deeper nested object, and then use lodash to put them together. Assuming totals is under securities…

var totals = _.map(Object.values(results.porfolios.securities), 'totals')

This should get you an array of all the totals.

I did not explicitly test this code out, but it should work.

If you have an example to provide, I can gladly test it out against it to validate that this works :slight_smile:

In terms of finding places to learn this more, I would start with Lodash.

https://lodash.com

Hope it helps!

Regards,
Orest

Thank you - I will definately try out lodash. Here is my json:

{
    "report": {
        "title": "Test Adhoc Report",
        "periodInclusionTime": "2018-08-09T12:00:00Z",
        "reportGenerationStarted": "2019-11-18T13:38:32.220381Z",
        "reportGenerationCompleted": "2019-11-18T13:38:32.377346Z",
        "metadata": {
            "columnTypes": {
                "assetType": "STRING",
                "strategy": "STRING",
                "financialAccount": "STRING",
                "manager": "STRING",
                "basket": "STRING",
                "symbol": "STRING",
                "quantity": "DOUBLE",
                "nativeCost": "DOUBLE",
                "bookMarketValuePercent": "DOUBLE",
                "reportMarketValuePercent": "DOUBLE"
            },
            "columnTotalMethods": {
                "assetType": "NONE",
                "strategy": "NONE",
                "financialAccount": "NONE",
                "manager": "NONE",
                "basket": "NONE",
                "symbol": "NONE",
                "quantity": "SUM",
                "nativeCost": "SUM",
                "bookMarketValuePercent": "SUM",
                "reportMarketValuePercent": "SUM"
            }
        },
        "portfolios": [
            {
                "portfolioName": "Control",
                "groups": [
                    {
                        "groupName": "United States of America",
                        "data": [
                            {
                                "assetType": "EQUITY",
                                "strategy": "Unicorn LS",
                                "financialAccount": "On Hand",
                                "manager": "SUID12Z34V3QWKL45",
                                "basket": "Basket001",
                                "symbol": "A",
                                "quantity": 2100,
                                "nativeCost": 141800.23,
                                "bookMarketValuePercent": 0.6637931034482759,
                                "reportMarketValuePercent": 0.6637931034482759
                            },
                            {
                                "assetType": "EQUITY",
                                "strategy": "Unicorn LS",
                                "financialAccount": "On Hand",
                                "manager": "SUID12Z34V3QWKL45",
                                "basket": "Basket001",
                                "symbol": "AABA",
                                "quantity": 750,
                                "nativeCost": 1000,
                                "bookMarketValuePercent": 0.33620689655172414,
                                "reportMarketValuePercent": 0.33620689655172414
                            },
                            {
                                "assetType": "EQUITY",
                                "strategy": "Asia Growth",
                                "financialAccount": "On Hand",
                                "manager": "SUID13Z34V3QWKL12",
                                "basket": "Basket002",
                                "symbol": "AA",
                                "quantity": 0,
                                "nativeCost": 0,
                                "bookMarketValuePercent": 0,
                                "reportMarketValuePercent": 0
                            }
                        ],
                        "total": {
                            "quantity": 2850,
                            "nativeCost": 142800.23,
                            "bookMarketValuePercent": 1,
                            "reportMarketValuePercent": 1
                        }
                    }
                ],
                "total": {
                    "quantity": 2850,
                    "nativeCost": 142800.23,
                    "bookMarketValuePercent": 1,
                    "reportMarketValuePercent": 1
                }
            }
        ]
    },
    "request": {
        "tenantId": 6,
        "knowledgeTime": "2018-08-09T23:59:59Z",
        "reportTime": "2018-08-09T12:00:00Z",
        "portfolioIds": [
            2
        ],
        "currencyId": 148,
        "priceSourceGroupId": 0,
        "fxPriceSourceGroupId": 3,
        "validationRuleCollectionId": 1,
        "bookId": 0,
        "adhocReport": {
            "title": "Test Adhoc Report",
            "columns": [
                {
                    "columnType": "ASSET_TYPE"
                },
                {
                    "columnType": "SYMBOL"
                },
                {
                    "columnType": "FINANCIAL_ACCOUNT"
                },
                {
                    "columnType": "MANAGER"
                },
                {
                    "columnType": "STRATEGY"
                },
                {
                    "columnType": "BASKET"
                },
                {
                    "columnType": "QUANTITY"
                },
                {
                    "columnType": "NATIVE_COST"
                },
                {
                    "columnType": "BOOK_MARKET_VALUE_PERCENT"
                },
                {
                    "columnType": "REPORT_MARKET_VALUE_PERCENT"
                }
            ],
            "groups": [
                {
                    "groupType": "NATION"
                }
            ],
            "filters": [
                {
                    "filterType": "ASSET_TYPE",
                    "value": 0
                }
            ]
        }
    }
}

This was an easy one - the one that I need to get working ahs multiple countries - with each country having multiple securities with %'s that are then totaled. And what I am trying to map out is the bars should be the %'s by country.

Hi @thomas.zdon,

Thanks for the clarification!

Given the json you provided, its a little more complicated than what I had mentioned earlier.

I was grinding away at the json and I came up with this javascript that I believe should be what you need. However, if its not, please be a little more clear, such as providing the kind of json you want to create from the one you provided.

var obj = JSON.parse(jsonProvided)

var portfolios = obj.report.portfolios

var result = _.flatMap(portfolios, ({ groups }) => _.flatMap(groups, ({ data }) => _.map(data, item => ({ quantity: item.quantity }))));

[ { quantity: 2100 }, { quantity: 750 }, { quantity: 0 } ]

var totals1 = _.flatMap(portfolios, ({ groups }) => _.map(groups, group => ({ firstTotal: group.total.quantity })));
[ { firstTotal: 2850 } ]

var totals2 = _.map(portfolios, portfolio => ({ secondTotal: portfolio.total.quantity }));
[ { secondTotal: 2850 } ]

Hope this helps!

Regards,
Orest

wow. Thank you. How do I learn this?

Thomas Zdon

You’re welcome @thomas.zdon!

Its really my pleasure.

If I’m being brutally honest, I really don’t know all this that well. But I am familiar with the concepts enough in that I was able to google it quite a bit, get some code snippets from StackOverflow, use that to piece together the Javascript that I shared, after some trial and error to get it working :smile: .

Its mostly about understanding the concepts well enough. Once you do, you can piece together anything really.

Best way to learn is to just get out there and when you encounter something you don’t know, get to the concepts first. Then learn to apply them by just going out and trying to do whatever it is that you need to accomplish.

I know that’s a bit vague, but I’m just being honest. It’s at least how I learned this stuff (let alone most things in IT :smile:)

Good Luck!
Orest

2 Likes

Orest,

Tried this solution but Postman tells me _.flatmap is not a function.

@thomas.zdon

You’ll have to require lodash (it’s the 4.x+ version)

_ = require('lodash');

// Now you can use _.flatMap
1 Like

@sivcan Beat me to it!

@thomas.zdon, that should suffice. My apologies for leaving it out. Additionally, not too sure if case matters, but I’d do _.flatMap over _.flatmap.

Let us know if this works!

—Orest

2 Likes