Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot condition check and return both parent value as well as child (nested array) values #19

Open
b-ron-son opened this issue Nov 23, 2020 · 3 comments

Comments

@b-ron-son
Copy link

{
"code": 200,
"data": [
{
"currency": "usdt",
"assetType": 1,
"chains": [
{
"chain": "trc20usdt",
"displayName": "TRC20",
"baseChain": "TRX",
"baseChainProtocol": "TRC20",
"isDynamic": false,
"numOfConfirmations": 1,
"numOfFastConfirmations": 1,
"depositStatus": "allowed",
"minDepositAmt": "1",
"withdrawStatus": "allowed",
"minWithdrawAmt": "2",
"withdrawPrecision": 6,
"maxWithdrawAmt": "1000000.00000000",
"withdrawQuotaPerDay": "1000000.00000000",
"withdrawQuotaPerYear": null,
"withdrawQuotaTotal": null,
"withdrawFeeType": "fixed",
"transactFeeWithdraw": "0.00000000",
"addrWithTag": false,
"addrDepositTag": false
},
{
"chain": "usdt",
"displayName": "OMNI",
"baseChain": "BTC",
"baseChainProtocol": "OMNI",
"isDynamic": false,
"numOfConfirmations": 2,
"numOfFastConfirmations": 1,
"depositStatus": "allowed",
"minDepositAmt": "20",
"withdrawStatus": "allowed",
"minWithdrawAmt": "200",
"withdrawPrecision": 8,
"maxWithdrawAmt": "600000.00000000",
"withdrawQuotaPerDay": "600000.00000000",
"withdrawQuotaPerYear": null,
"withdrawQuotaTotal": null,
"withdrawFeeType": "fixed",
"transactFeeWithdraw": "5.00000000",
"addrWithTag": false,
"addrDepositTag": false
},
{
"chain": "usdterc20",
"displayName": "ERC20",
"baseChain": "ETH",
"baseChainProtocol": "ERC20",
"isDynamic": false,
"numOfConfirmations": 12,
"numOfFastConfirmations": 12,
"depositStatus": "allowed",
"minDepositAmt": "1",
"withdrawStatus": "allowed",
"minWithdrawAmt": "10",
"withdrawPrecision": 6,
"maxWithdrawAmt": "1000000.00000000",
"withdrawQuotaPerDay": "1000000.00000000",
"withdrawQuotaPerYear": null,
"withdrawQuotaTotal": null,
"withdrawFeeType": "fixed",
"transactFeeWithdraw": "3.00000000",
"addrWithTag": false,
"addrDepositTag": false
}
],
"instStatus": "normal"
},
{
"currency": "husd",
"assetType": 1,
"chains": [
{
"chain": "husd",
"displayName": "HUSD",
"baseChain": "ETH",
"baseChainProtocol": "ERC20",
"isDynamic": false,
"numOfConfirmations": 12,
"numOfFastConfirmations": 12,
"depositStatus": "allowed",
"minDepositAmt": "1",
"withdrawStatus": "allowed",
"minWithdrawAmt": "2",
"withdrawPrecision": 8,
"maxWithdrawAmt": "1000000.00000000",
"withdrawQuotaPerDay": "1000000.00000000",
"withdrawQuotaPerYear": null,
"withdrawQuotaTotal": null,
"withdrawFeeType": "fixed",
"transactFeeWithdraw": "1.00000000",
"addrWithTag": false,
"addrDepositTag": false
}
],
"instStatus": "normal"
},

Hi there, I am trying to retrieve the following based on satisfying all the following conditions:
Condition 1 - "chain" is not empty
Condition 2 - "instStatus is "normal"
Condition 3 - "depositStatus is not "prohibited

Return the following:

  • currency
  • depositStatus

URL endpoint - https://api.huobi.pro/v2/reference/currencies

I manage to return "currency" based the Condition 1 and Condition 2.

=IMPORTJSONAPI("https://api.huobi.pro/v2/reference/currencies","$.data[?(@.chains!='' && @.instStatus=='normal')]","currency")

However, when I tried adding Condition 3, it doesn't seem to do anything (I get the same result)
=IMPORTJSONAPI("https://api.huobi.pro/v2/reference/currencies","$.data[?(@.chains!='' && @.instStatus=='normal' && @.chains.depositStatus!='prohibited')]","currency")

Also, can't seem to get "depositStatus" value back either.
PLEASE HELP

@qeet
Copy link
Owner

qeet commented Nov 23, 2020

I think the best thing to do is first retrieve all the raw data in one tab:

=IMPORTJSONAPI("https://api.huobi.pro/v2/reference/currencies","$.data[*].chains[*]", "^^currency, depositStatus,^^instStatus")

Now in another tab use the QUERY function to filter out the rows you don't want.

@qeet
Copy link
Owner

qeet commented Nov 23, 2020

Actually you can do it all with a single statement:

=QUERY(IMPORTJSONAPI("https://api.huobi.pro/v2/reference/currencies","$.data[*].chains[*]", "^^currency, depositStatus,^^instStatus"), "select Col1, Col2 where Col3 = 'normal' and Col2 != 'prohibited'")

@b-ron-son
Copy link
Author

Thats fantastic! Problem solved. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants