Sample call to Interactive Brokers for a currency pair? - trading

I'm attempting to run Interactive Broker's included code sample.
http://www.interactivebrokers.com/download/JavaAPIGettingStarted.pdf
On about page 42 it details how to pull market data feeds. My question is, has anyone successfully put in the parameters needed to pull currency pair data??
public synchronized void reqMktData(int tickerId, Contract contract, String genericTickList, boolean snapshot)
I cannot find the valid inputs that will correct the errors I'm seeing from the client.
Parameters needed
List of values inside Contract class are here : https://www.interactivebrokers.com/en/software/api/apiguide/java/contract.htm
STK == "stock" , should this be set to CASH for Forex data?
IDEALPRO == the exchange according to this page : http://ibkb.interactivebrokers.com/tag/fx-trader
USD.JPY = SYMBOL (this here is a guess on my part)
USD == "underlying currency" , here I am guessing again.. seems the currency needs to match the transaction currency.
the pair in the format Transaction Currency.Settlement Currency (example: EUR.USD). The Underlying column will display only the Transaction Currency.

After scouring IB's forum I have found something that works for FX data feeds. You need to put the TransactionCurrency as the Symbol, and the SettlementCurrency as the underlying in the dialog box.
Here is the resulting data feed

As I can remember, I used: CASH, IDEALPRO, EUR.USD, USD
You can see all parameters example in the TradeStation client. Just find the needed instrument and look at it's properties.
And remember that not all parameters must be necessarily filled
At the worst, show the error.

Related

Google Ads API: getMetrics doesn't get results for all passed keywords

I'm on migration from the old Google AdWords API to the new Google Ads API, using PHP-SDK by Google.
This is the use case, where I'm stuck:
I feed an amount of keywords (paginating them by keyword plans a 10k) to generateHistoricalMetrics($keywordPlanResource) and collect the results.
To do so I followed instructions at https://developers.google.com/google-ads/api/docs/keyword-planning/generate-historical-metrics and, especially, https://developers.google.com/google-ads/api/docs/keyword-planning/generate-historical-metrics#mapping_to_the_ui, with using of KeywordPlanAdGroupKeywords (with a single ad group) and avoiding to pass a specific date range for now, relying on the default value.
Further I had to apply some filters on my keywords because of KEYWORD_HAS_INVALID_CHARS and KEYWORD_TEXT_TOO_LONG, but all the errors which I'm aware of are gone now.
Now, I found out, that the KeywordPlanHistoricalMetrics object does not contain any keyword id (of the form customers//keywordPlanAdGroupKeywords/) So, I have to rely on the correct ordering. This is ok as it seems, that the original ordering of keywords is preserved within the results, as here https://developers.google.com/protocol-buffers/docs/encoding#optional
But still I have the problem, that
count($keywordPlanServiceClient->generateHistoricalMetrics($keywordPlanResource)->getMetrics()) is lower then count($passedKeywords), where each of $passedKeywords where passed to
new KeywordPlanAdGroupKeyword([
'text' => $passedKeyword,
'match_type' => KeywordMatchType::EXACT
'keyword_plan_ad_group' => $planAdGroupResource
]);
Q: So I have two questions here:
Why getMetrics() does not yield the same amount of results as the amount of passed keywords?
I'm struggling with debugging at this moment: Say, I want to know which keywords are let out. Either for providing more information at this place or just to skip them, and let my customer know, that these particular keywords were not queried. How to do this, when although I have a keyword id for every passed keyword I cannot match the returned metrics to them, because the KeywordPlanHistoricalMetrics object does not contain any keyword id.
Detail: While testing I found out, that the reducing of an amount of queried keywords reduces the amount of lost keyword data:
10k of queried keywords - 4,72% loss,
5k - 2,12%,
2,5k - 0,78%,
1,25k - 0,43%,
625 - 0,3%,
500 - 0,24%,
250 - 0,03%
200 - 0,03% of lost keywords.
But I can't imagine, that keywords should be queried one by one.

Is there a way to tell if one tweet was created after another based on the tweet id?

Currently I'm checking if a tweet was created after another tweet based on the timestamp, but this is proving inconsistent. What is working locally is not working all the time on my server. I suspect a timezone issue (my server is in another time zone).
But I was wondering if I can do this based on Twitter's unique ids for each tweet? Something in the form:
if (tweet2.id > tweet1.id) {
// tweet2 created after tweet 1
} else {
// tweet2 created before tweet 1
}
Is this possible? If not I'll ask another question about what could be going wrong with my date implementation.
Twitter ids are generated by twitter snowflake mechanism which
is an algorithm and a cluster of machines to produce it. In general
those id's are sequential so your comparison will basically hold. The
problem is those id's are currently > 64 bits so js will truncate
those. The trick is to use tweetXXX.id_str field which is the id
casted to a string for your comparison.
I haven't see your date implementation but probably you are no comparing UTC date values. Any way comparison made on datetime will not give you correct results even on ms scale there will be many tweets on same date time.

Detect VOIDed invoices from quickbooks

Our system pulls lots of data from quickbooks using the QBWC/QBXML.
We also poll TxnDeletedQuery to get a list of deleted invoices, etc...
How do I query for or detect a 'Voided' invoice? I don't see anything in the InvoiceQueryRs schema that would indicate a voided invoice.
Does quickbooks do anything but zero-out the line item quantities?
Thanks!
The only thing QuickBooks does when voiding is:
sets the quantities/rates to zero
adds a "VOID" string to the Memo field
To detect it, you'd have to parse the Memo field and look at the rates/quantities. There's no way to filter by it in a query unfortunately.

Getting adjusted price information from Yahoo! Finance API for multiple symbols in one call

I would like to get the adjusted price (adjusting for splits and dividends) for a group of stock symbols using Yahoo! Finance. It looks like the historical prices call is limited to one symbol at a time. Could please let me know if there is a way to get multiple symbols in one call?
I would like to get this data so I can do some back testing on that data. Since I may require quite a few symbols (say 500-1000), it will be easier if I can make just a few batch calls to Yahoo!'s servers instead of making one call per symbol everyday.
Another way of getting the adjusted price is to use their daily stock price api and adjust it manually using dividend and splits information (they allow multiple symbols for their daily stock quotes). Unfortunately I cannot find any way to get splits information from the http call (guessing based on 50% or 200% is one option but if you deal with penny stocks, this can be dangerous and cannot figure out uneven splits). Also, the dividend information returned by it is not easy to decode. They seem to be returning the total over 4 quarters and the dividend date doesn't really correspond with the actual dividend date based on the historical price. The various options for the call can be found here: http://www.gummy-stuff.org/Yahoo-data.htm
Any suggestions on getting adjusted price for multiple symbols? Or Am I unnecessarily worrying about making 100s of calls to Yahoo! everyday? Ideally I would like to download all the required data within a couple of hours each day - that would be 10-20 calls per minute. Is that too much? I couldn't find any documentation on the permissible number of requests per second.
I am open to other places where I can get similar data. However, since I am just trying to learn the basics of quant trading and not trade, I would prefer free downloads.
Thanks
-e
This is an old question, but I did find a source where split data is available. Not sure how comprehensive these announcements are though:
http://biz.yahoo.com/c/09/s1.html
In the url, the "09" part is the year (2009), and the "s1" part is the month (s1 = Jan, s2 = Feb., s3 = Mar., etc.)
It isn't a nice clean CSV, but the format of the page is consistent and should be parseable. Just make a query each day for the current month, parse the page, and process any splits that you didn't see the day before.
ETA: And another source (probably less reliable than Yahoo, but can be queried by ticker):
http://getsplithistory.com/
I am not sure which language you are using but I have a sample in C#. I think it will give you the idea at least or may be help some one else
private string BASE_URL = "http://query.yahooapis.com/v1/public/yql?q=" + "select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20({0})" + "&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
Collection<Quote> quotes;
string symbolList = String.Join("%2C", quotes.Select(w => "%22" + w.Symbol + "%22").ToArray());
string url = string.Format(BASE_URL,symbolList);
XDocument doc = XDocument.Load(url);
Parse(quotes,doc);
What we are doing here is appending "," to each array item then passing that symbol list to yahoo. I have successfully fetched prices for 700 symbols in each call. Hitting yahoo servers for each ticker is a pain. I fetch stock prices for all of 6500+ tickers everyday. Earlier it use to take 3 hours now it is less than 2 mins.....sweet
Source link for that code is here - http://www.jarloo.com/get-yahoo-finance-api-data-via-yql/
P.S. Please get a api key to work smoothly. The above url is a public link where tables are timed out most of the time. Once you get an api key then your url will be (minus "public")
http://query.yahooapis.com/v1/yql

Quickbooks: Adding a negative value to an invoice using the QBDSK

Is there any way to add a line item containing a negative amount to an existing invoice?
I'm using QBSDK7 and QB Enterprise. (and if it matters .Net 3.5)
What we're attempting to do is automate the way we're creating invoices. We're already pulling in employee's time and applying it to the correct invoices, but when we go to add credits (just a negative amount on a line item on the invoice) using
InvoiceLineMod.Amount.SetValue(-1234)
it fails with the error "Transaction must be positive"
I've also tried adding a Service Item with a negative amount and giving it a positive quantity and I get the same result.
This seems like such a no-brainer as we have been doing this manually for the last 10 years. I'm guessing there is artificial restriction on this.
Some things to consider:
Credit Memos are no good as we need to display exact details of the reduction on the same page.
We don't have payments to apply yet in most cases.
This need to be done before any retainers are applied.
Any help would be greatly appreciated.
Can you show the complete code you're using to modify the invoice? Can you also show the exact error message you're getting?
It is possible, though to do you need to make sure that you're using a Discount Item as your ItemRef type (a Service Item will not work), and you need to make sure that the transaction as a whole is for a positive amount.
Sometimes our app has to adjust an invoice down with a negative number. I have been able to add negative line items using the following code. I have to set a quantity and a rate, instead of setting the amount.
IInvoiceLineAdd ila = ia.ORInvoiceLineAddList.Append().InvoiceLineAdd;
ila.ItemRef.ListID.SetValue(GetQBID(JobKey));
ila.Desc.SetValue("Adjustment");
ila.Quantity.SetValue(1);
ila.ORRatePriceLevel.Rate.SetValue(-1.00);
Quickbooks doesn't allow you to post an invoice with a negative balance. If you try to do it through the UI, it prompts you to create a credit memo instead. (And vice-versa if you try it with a credit memo.)
You can enter negative quantities and/or prices into the line items, but the total of the invoice has to be >= 0 or it won't post (i.e., add other line items that offset the negative amounts).
The solution is to use credit memos. Your client-side processing will be more complicated, but it's the only choice with Quickbooks.

Resources