What is bloomberg's response when one of a few fields is not found? - bloomberg

I have a Java code that uses blpapi to request specific fields of specific securities. My code runs fine now. However, I have thought of a case that is not being handled by my current code.
Say, for example, I am requesting 'CUR_MKT_CAP', 'PX_LAST', and 'EQY_SH_OUT' for a specific security. What if Bloomberg does not have the value for 'PX_LAST'? What will Bloomberg give me then?
(a) Will it give me a field Element where PX_LAST = 0?
(b) Will it give me a field Element where PX_LAST = NULL?
(c) Will it not include PX_LAST to the response that I will receive? Thus, the response will look like this?
HistoricalDataResponse (choice) = {
securityData = {
security = XXXXX Equity
sequenceNumber = 0
fieldData[] = {
fieldData = {
date = YYYY-MM-DD
CUR_MKT_CAP = XX.XXXX
EQY_SH_OUT = XX.XXXX
}
}
} }
Basically, I just want to know how I should handle if one of the fields I need is not given by Bloomberg.

You are correct, if a field returns no data, it will be omitted from the fieldData element. If none of the fields returns data, the fieldData will be empty:
ReferenceDataResponse = {
securityData[] = {
securityData = {
security = "MSFT US Equity"
eidData[] = {
}
fieldExceptions[] = {
}
sequenceNumber = 0
fieldData = {
}
}
}
}
You can easily test this, for example using MSFT US Equity / YAS_BOND_YLD.

I tested it using #assylias's answer. It gave me the following results.
MSFT US Equity
HistoricalDataResponse (choice) = {
securityData = {
security = MSFT US Equity
sequenceNumber = 0
}
}
YAS_BOND_YLD
HistoricalDataResponse (choice) = {
securityData = {
security = YAS_BOND_YLD
sequenceNumber = 0
securityError = {
source = 500::bbdbh5
code = 15
category = BAD_SEC
message = Unknown/Invalid securityInvalid Security [nid:500]
subcategory = INVALID_SECURITY
}
}
}

As per #assylias comment, I used YAS_BOND_YLD as a field. And blpapi returned the following as a response.
My input to the request:
Ticker: XXX XX Equity Start/End Date: 20160818 Fields: CUR_MKT_CAP YAS_BOND_YLD PX_LAST EQY_SH_OUT
BLPAPI's response is,
HistoricalDataResponse (choice) = {
securityData = {
security = XXX XX Equity
sequenceNumber = 0
fieldData[] = {
fieldData = {
date = 2016-08-18
CUR_MKT_CAP = 117.7144
PX_LAST = 1.06
EQY_SH_OUT = 111.051
}
}
}
}
Note: I changed the ticker to XXX XX on purpose. =D

Related

Catch StatusCode from execution value in Xunit

I want to compare the return value from controller execution whether that fulfill the condition or not. From debugging I noticed the 'StatusCode' but not got an way to catch that value for comparing. My Code for testing is
public void PostAmount_Withdraw_Returns_Null()
{
// Arrange
Amount amount = new Amount() { Id = 0, PaymentDate = DateTime.Today,
PaymentTypeId = 3, PaymentAmount = 500, ClientId = 1, Balance = 0 };
_accountServiceMock.Setup(s => s.Withdraw(amount)).Throws(new Exception());
var target = SetupAmountsController();
//Act
var actual = target.PostAmount(amount);
//Assert
actual.ShouldNotBeNull();
//actual.Value.ShouldBe(response);
}
What call controller methods below : -
public ActionResult<Amount> PostAmount(Amount amount)
{
try
{
if (amount.PaymentTypeId == 1)
{
_accountService.Deposit(amount);
}
else if (amount.PaymentTypeId == 2)
{
_accountService.Withdraw(amount);
}
else
{
return Problem("Model 'Amounts' is null.");
}
return new OkObjectResult(new { Message = "Payment Success!" });
}
catch (DbUpdateConcurrencyException)
{
return Problem("There was error for updating model Payment");
}
}
And, returned the value after execution from Unit Test
I want to give condition likes below: -
actual.Result.StatusCode = HttpStatusCode.BadRequest or
actual.Result.StatusCode = 500
Just got the answer. It will be likes below: -
(actual.Result as ObjectResult).StatusCode.ShouldBe((int)HttpStatusCode.InternalServerError);
you need to define here 'status code' what want to compare. In my case it was 500.

How to send api request from test class to Main class in salesforce?

Class :
#RestResource(urlMapping='/api/fetch_status/*')
global class RestDemo{
#HttpGet
global static Account getResult(){
Account account;
String accountId = '';
RestRequest restReq = RestContext.request;
RestResponse restRes = RestContext.response;
// reading url
try{
//accountId = restReq.params.get('accountId');
accountId = restReq.requestURI.substring(restReq.requestURI.lastIndexOf('/') + 1);
account = [SELECT Id, Name FROM Account WHERE Id = :accountId Limit 1];
if(account != null){ //checked whether any record is returned or not
restRes.responseBody = Blob.valueOf(JSON.serialize(account));
restRes.statusCode = 200;
}else{
/* String account_not_found= '{"message":"Not Found"}';
restRes.responseBody = Blob.valueOf(account_not_found); */
restRes.statusCode = 404;
}
}
catch(Exception ex){
restRes.responseBody = Blob.valueOf(ex.getMessage());
restRes.statusCode = 500;
}
return account;
}
}
Test Class :
private class RestDemoTest {
#testSetup
static void dataSetup() {
Account acc = new Account(Name = 'Testing5');
insert acc;
}
static testMethod void testGet() {
//case 1 when the id is valid
Account acc = [ SELECT Id FROM Account LIMIT 1 ];
RestRequest req = new RestRequest();
RestResponse res = new RestResponse();
req.requestURI = '/services/apexrest/api/fetch_status/' + acc.Id;
req.httpMethod = 'GET';
RestContext.request = req;
RestContext.response= res;
Account acct1 = RestDemo.getResult();
system.assertEquals(acct1.Name, 'Testing5');
// case 2 when the id is not present
String str_id = '0012x000004UjZX';
Id id = Id.valueOf(str_id);
req.requestURI = '/services/apexrest/api/fetch_status/' + id;
req.httpMethod = 'GET';
RestContext.request = req;
RestContext.response= res;
Account acct2 = RestDemo.getResult();
system.assertEquals(acct2, null);
}
}
I want to test the test case 2 where the account with the random id is not present.
But while testing the test class (in test case 2 )it is giving exception.
In this i used an existing id and changed it a little.So while test case2 runs it should go through the else statement of the main class but it is throwing exception (catch statement,Tested it in salesforce developer console).
account = [SELECT Id, Name FROM Account WHERE Id = :accountId Limit 1];
The way you written it account will never be null. It'll just throw "List has no rows for assignment to SObject".
Change to this
List<Account> accs = [SELECT Id, Name FROM Account WHERE Id = :accountId Limit 1];
if(!accs.isEmpty()){
// return 200;
} else {
// return 400;
}
If you query that way it'll always come as List. It can be empty list but it will be a list (not null). Assign query results to single Account/Contact/... only if you're 100% sure it'll return something. Or catch the exceptions

Map within a map in terraform variables

Does anyone know if it's possible with possibly code snipits representing whether I can create a map variable within a map variable in terraform variables?
variable "var" {
type = map
default = {
firstchoice = {
firstAChoice ="foo"
firstBChoice = "bar"
}
secondchoice = {
secondAChoice = "foobar"
secondBChoice = "barfoo"
}
}
}
If anyone has any insight to whether this is possible or any documentation that elaborates that would be great.
Yes, it's possible to have map variable as value of map variable key. Your variable just needed right indentation. Also I am putting ways to access that variable.
variable "var" {
default = {
firstchoice = {
firstAChoice = "foo"
firstBChoice = "bar"
}
secondchoice = {
secondAChoice = "foobar"
secondBChoice = "barfoo"
}
}
}
To access entire map value of a map key firstchoice, you can try following
value = "${var.var["firstchoice"]}"
output:
{
firstAChoice = foo
firstBChoice = bar
}
To access specific key of that map key (example firstAChoice), you can try
value = "${lookup(var.var["firstchoice"],"firstAChoice")}"
output: foo
Would this syntax be possible? ${var.var[firstchoice[firstAchoice]]}
With Terraform 0.12+ nested blocks are supported seamlessly. Extending #Avichal Badaya's answer to explain it using an example:
# Nested Variable
variable "test" {
default = {
firstchoice = {
firstAChoice = "foo"
firstBChoice = "bar"
}
secondchoice = {
secondAChoice = "foobar"
secondBChoice = "barfoo"
}
thirdchoice = {
thirdAChoice = {
thirdBChoice = {
thirdKey = "thirdValue"
}
}
}
}
}
# Outputs
output "firstchoice" {
value = var.test["firstchoice"]
}
output "FirstAChoice" {
value = var.test["firstchoice"]["firstAChoice"]
}
output "thirdKey" {
value = var.test["thirdchoice"]["thirdAChoice"]["thirdBChoice"]["thirdKey"]
}
Applying the above, you can verify that Terraform map nesting is now quite powerful and this makes a lot of things easier.
# Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
# Outputs:
firstchoice = {
"firstAChoice" = "foo"
"firstBChoice" = "bar"
}
thirdKey = thirdValue
For more complex structures and Rich Value Types, see HashiCorp Terraform 0.12 Preview: Rich Value Types

Getting "Received unknown parameter: amounts" for bank Account "Verify" function for jaymedavis/stripe.net code.?

I am implementing WCF service to implement online Net banking using github jaymedavis/stripe.net code (https://github.com/jaymedavis/stripe.net#charges).
here is my code for creating customer, Bank Account and Bank Account service for verifying Bank account and Creating charges.
Code:
//1. Create Customer
var myCustomer = new StripeCustomerCreateOptions();
myCustomer.Email = "pork#email.com";
myCustomer.Description = "Johnny Tenderloin (pork#email.com)";
//myCustomer.SourceToken = *token*;
//myCustomer.PlanId = *planId*; // only if you have a plan
//myCustomer.TaxPercent = 20; // only if you are passing a plan, this tax percent will be added to the price.
//myCustomer.Coupon = *couponId*; // only if you have a coupon
//myCustomer.TrialEnd = DateTime.UtcNow.AddMonths(1); // when the customers trial ends (overrides the plan if applicable)
//myCustomer.Quantity = 1; // optional, defaults to 1
//2. Create Customer Service
var customerService = new StripeCustomerService(StripeApiKey);
StripeCustomer stripeCustomer = customerService.Create(myCustomer);
//3. Create bankAccount
var myBankAccount = new BankAccountCreateOptions
{
SourceBankAccount = new SourceBankAccount()
{
AccountNumber = "000123456789", //,
Country = "US",
Currency = "usd",
AccountHolderName = "Frank", //"Johnny Tenderloin",
AccountHolderType = BankAccountHolderType.Individual,
RoutingNumber = "110000000", //"021000021",
Metadata = new Dictionary<string, string>
{
{ "Name", "Ray Barone" },
{ "OftenSays", "Thatttttt's right" }
}
}
};
//4. Create bankAccount Service
var bankAccountService = new BankAccountService(StripeApiKey);
CustomerBankAccount bankAccount = bankAccountService.Create(stripeCustomer.Id, myBankAccount);
BankAccountVerifyOptions bankAccountVerifyOpt = new BankAccountVerifyOptions();
bankAccountVerifyOpt.AmountOne = 32;
bankAccountVerifyOpt.AmountTwo = 45;
//
//5. Verify bankAccount or service
bankAccount = bankAccountService.Verify(stripeCustomer.Id, bankAccount.Id, bankAccountVerifyOpt );
//6. Create Charge
var myChargeBank = new StripeChargeCreateOptions();
// amount = Returnamount.amount;
myChargeBank.Amount = int.Parse("250") * 100;
myChargeBank.Currency = "usd";
myChargeBank.CustomerId = stripeCustomer.Id;
myChargeBank.Capture = true;
StripeCharge stripeCharge = null;
stripeCharge = new StripeCharge();
var chargeService = new StripeChargeService(StripeApiKey);
stripeCharge = chargeService.Create(myChargeBank);
if (stripeCharge.Status.ToLower() == "succeeded" & stripeCharge.Paid == true) {
} else {
}
In this code, I am getting:
Stripe Exception for Verify method (bankAccountService.Verify(stripeCustomer.Id, bankAccount.Id, bankAccountVerifyOpt );)
Exception is Received unknown parameter: amounts.
on "https://github.com/jaymedavis/stripe.net#charges" implementation for 'Verify a bank account' is missing so Please help me to solve this problem so that bank account get verify successfully.
I had the same issue and I did 2 things:
1) On stripe.com, I went to my account API settings and updated them to use the lasted API.
2) I updated the Stripe.net Nuget package
After that everything worked perfectly.

TYPO3 - parent page field for title in typolink

I have a problem with TYPO3 which I encountered several times now.
If i fetch an object with the TYPO3 CONTENT Object i have the possibility to render the fields with the renderObj...
So far so good...
But if i try to fetch an object which i fetched already before i dont get any response..
Following setup:
temp.current = COA
temp.current {
10 = CONTENT
10 {
table = pages
select {
pidInList = 22
max = 1
}
renderObj = COA
renderObj {
10 = CONTENT
10 {
table = tt_content
select {
pidInList.field = uid
where = colPos = 9
max = 1
languageField = sys_language_uid
}
renderObj = COA
renderObj {
5 = TEXT
5 {
value = here
typolink {
parameter.field = pid
title {
cObject = RECORDS
cObject {
tables = pages
source.field = pid
conf.pages = TEXT
conf.pages.field = title
}
}
}
}
20 = IMAGE
20 {
required = 1
file{
import = uploads/pics/
import.field = image
import.data = levelmedia: -1, slide
import.listNum = 0
width = 300c
height = 300c
}
titleText.field = titleText // altText
altText.field = altText // titleText
imageLinkWrap = 1
imageLinkWrap {
enable = 1
typolink {
parameter.data = field:pid
}
}
}
}
}
}
}
}
This is my current setup which i need to get a current project... Whatever..
The important part is:
5 = TEXT
5 {
value = here
typolink {
parameter.field = pid
title {
cObject = RECORDS
cObject {
tables = pages
source.field = pid
conf.pages = TEXT
conf.pages.field = title
}
}
}
}
I've already debugged the result of source... The value is 92, which is the correct uid from the page from where I need the title field...
Also I know that the code should be okay, because I use this snippet on many pages.
I think the problem is, that I try to fetch a content which i already fetched before..
Right here:
temp.current = COA
temp.current {
10 = CONTENT
10 {
table = pages
select {
pidInList = 22
max = 1
}
}
}
Many thanks!
// EDIT
I found a very good solution for my problem..
5 = TEXT
5 {
value = hier
typolink {
parameter.field = pid
title.cObject = TEXT
title.cObject {
data.dataWrap = DB:pages:{field:pid}:title
}
}
}
I found a solution!
5 = TEXT
5 {
value = hier
typolink {
parameter.field = pid
title.cObject = TEXT
title.cObject {
data.dataWrap = DB:pages:{field:pid}:title
}
}
}
According to http://forge.typo3.org/issues/20541 you are right and this has not been viewed as a bug but a feature ("recursion prevention").