How to get the trading price and commission in Interactive Brokers new API (9.73) after placing an order? - interactive-brokers

I'm looking at ib_insync, framework for new Interactive Brokers python API. One thing I can't figure out is how to get the trading price after placing market order. Has anyone figured it out?
I've seen this question, but it's for the old API and IBPY.

If anyone wants to know, here's how to get the price at which you bought/sold:
from ib_insync.order import MarketOrder
order = MarketOrder(action, quantity)
trade = self.ib.placeOrder(contract, order)
# Wait for the trade to complete
...
filled_quantity = trade.filled()
filled_price = trade.orderStatus.avgFillPrice

Related

Twilio API "IncomingPhoneNumber.list()" is slow on Master account (And I only need the total amount of numbers)

I have a Flask App that uses twilio. I display the total amount of incomingphonenumbers in an account/subaccount to the user.
Here is what I'm currently doing to get the total:
client = Client(accountsid,accounttoken)
# Get the list
pnlist = client.incoming_phone_numbers.list(limit=1)
# Get the length of the list
total = len(pnlist)
This takes upwards of 19 seconds just to get the numbers in the Master account. On top of that I have to repeat this for all subaccounts.
Is there a better way to just get the total numbers for a account/subaccount?
Thanks in advance!
Twilio developer evangelist here.
I would recommend that, rather than listing all the numbers every time you want to count them, you cache the count within your own database against the account.
You can then update the count either when you know it changes, if you are purchasing/releasing numbers via the API in your app, or periodically (say, once a day) with a background job.

Quickbooks SDK - Lot number from sales order

Is it possible to get the lot number from a sales order using the quickbooks QBFC SDK.
I have the code running and working, but lot number doesn't come through the QBFC SDK.
Lot number is there in the sales order in quickbooks.
How do I get lot number from a sales order via the SDK?
Thanks
Although the SDK has fields for the Serial / Lot numbers, they currently don't return any information on a SalesOrder. This functionality hasn't been implemented in the latest version of the SDK (13.0). The only way that I know of to get this information would be to do a CustomDetailReportQueryRq and filter the report with the following:
ReportTxnTypeFilter = SalesOrder
ReportDetailLevelFilter = AllExceptSummary
ReportPostingStatusFilter = NonPosting
SummarizeRowsBy = TotalOnly
IncludeColumn = SerialOrLotNumber
You will probably want to add in the columns for RefNumber, TxnID, and ItemName to help parse out the values that you need.

Is there a way to import aggregated sales into quickbooks

Is there a way to import aggregated sales into quickbooks using the webconnector.
For example. I have 500 dollars in sales, 300 dollars in liquer sales, and 200 dollars in discounts.
How do I import this data. Do i need to import all the line items and have quickbooks sum it up (which is terrible i feel).
Or can i just import the rolled up data?
If i can do the rolled up data, how would i do that? If not how do i have quickbooks magically sum up the line items?
If you create an invoice with a bunch of line items, it's always going to automatically sum up all of the line items to show the total invoice amount/balance.
With that said, if you simply don't want the actual line item detail to go into QuickBooks, there's a number of ways you can do that, but you should probably talk to your accountant first or actually find out how the accountant wants the data entered into QuickBooks first.
e.g. your question doesn't really sound programming related, it's more of a "how do I use QuickBooks question".
The most common ways of not sending line item detail are to either:
Just send an invoice with a single line item, for the sum of all of the stuff
OR
Send a Journal Entry, which is a base-level transaction that only allows a single amount

Jira - JQL report to show average number of resolved/created tickets over 30days

I'm trying to figure out how to create a JQL query that will pull back the average number of resolved tickets over the last 30 days and the average number of created tickets over the last 30 days...
I've used the created resolved report in Jira which is great, but now I just need the averages calculated..
I'm quite sure that this cannot be achieved using the out-of-the-box JQL.
You can do this easily using Jira's remote API, using jira-python for example :
from jira.client import JIRA
jira = JIRA(basic_auth=('admin', 'admin')) # a username/password tuple
props = jira.application_properties()
# Find all issues from the last month:
issuesResolved = jira.search_issues('resolved > startOfMonth()')
issuesCreated = jira.search_issues('created > startOfMonth()')
# and so on...
What should the output be exactly? average per day for the last 30 days? average for every 30 months?
Anyway, if you need help coding that let me know... good luck !

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

Resources