PHP buy examples?

47 views
Skip to first unread message

johne5

unread,
Oct 16, 2011, 2:07:59 AM10/16/11
to Empire Avenue API Discussion
Does anyone have a PHP buy example?
I've been trying and trying, and can't get it to send post data. I
can do get requests all day long.
I've tried curl.
I can get a post buy request to work if I use a form submit. but i
have to manually click the submit button.

this is my form. but again i have to click the "Buy Me" button. and I
want the code to auto send it.
$buyurl = "<form name='buyform' action='https://api.empireavenue.com/
shares/buy?' method='post'>
<input type='hidden' name='username' value=$username />
<input type='hidden' name='password' value=$userpassword />
<input type='hidden' name='apikey' value=$API_KEY />
<input type='hidden' name='ticker' value=$ticker />
<input type='hidden' name='shares' value=10 />
<input type='hidden' name='last_trade' value=$price />
<input type='submit' value='Buy Me' />
</form>";
echo "<br>$buyurl<br>";

If any has a working example, i would love to get this working.

John S

unread,
Jan 11, 2012, 6:18:28 PM1/11/12
to empireave-ap...@googlegroups.com
I'll be writing some code to do buy's in PHP soon, and will provide some samples. Here is a chunk of my code from Python that works. It's what I will be basing my PHP version on. Python was just for quick testing stuff... My code below is a little messy, whatever.

You should not need the '?' after /buy since it's a post. Also I dont think you can do a buy without previously getting the portfolio or one of the other get's that includes the last_trade, as that timecode needs to be exact or it will fail.

        values = {
                  'apikey' : str(apikey),
                  'username' : str(username),
                  'password' : str(tkpw),
                  'ticker' : str(data[i]['ticker']),
                  'shares' : str(7),
                  'last_trade' : str(data[i]['last_trade']) 
                  }

        data2 = urllib.urlencode(values)
        req = urllib2.Request(url, data2)
        print(req)
        response = urllib2.urlopen(req)
        json_data = response.read()
        parsed = json.loads(json_data)
        data2 = parsed['data']

Kevin Umbach

unread,
Jan 11, 2012, 6:46:11 PM1/11/12
to empireave-ap...@googlegroups.com
Looks good, that should be doable in PHP. Nice to see you though of
encoding your data values., my app used to have a problem when
someone had & in their password.

On the topic of API 2.0...

My iPhone app takes a whopping 3 api calls to do a single buy:

1. Get the latest profile information. You do need the latest trade
price to pass on to the buy API method.
2. Get the commission rate between you and the person you are buying.
I do this so I can estimate the purchase amount and display it before
doing the transaction.
3. Do the actual buy transaction.

With a current limit of 150 requests per hour, I can't even spend all
my eaves in one session. Drives me crazy!!

I have hinted that I'd like to see a more efficient API that requires
less requests to perform tasks. And a MUCH higher limit.

Regards,
Kevin

John S

unread,
Jan 12, 2012, 11:18:03 AM1/12/12
to empireave-ap...@googlegroups.com
The way I am getting around the limit is by pretty much exclusively using "profile/info" which includes pretty much everything. While it's a single call you can request up to 20 users with it at once which is just an outrageous amount of data. Since I can get multiple users I have  a database and am getting as much as I can per hour for my users, storing it in a database for the specified users and then I can do stuff with a reasonable tolerance level. Accessing the API with only profile/info you can get  5000 user profiles/hour.. Or I can.. my limit is 250.. did they change it?

For a buy... I guess I would need to call profile/info again to get the latest trade price.. but im not that far into development yet. profile/info includes the commission percent as well... You cant just use that?

Yea... I would much rather just get the info I want then this mess of data the comes with profile/info but oh well.

John S

unread,
Jan 12, 2012, 11:23:14 AM1/12/12
to empireave-ap...@googlegroups.com
Oh. Here is a nifty jQuery thing I put together based on the data I have been collecting, it's not live updating currently. My cron jobs are not yet setup to collect data automatically. 
Simple ranking of them based on dividend/share vs share price... bigger numbers are better. 

eGREENSBORO

unread,
Jan 13, 2012, 2:11:26 PM1/13/12
to empireave-ap...@googlegroups.com
I tried to check the link is busted 404 FYI. I will check back thanks

John S [ZZBOMB]

unread,
Jan 14, 2012, 11:38:50 AM1/14/12
to empireave-ap...@googlegroups.com
Funny story about that. Realized I spelled summary incorrectly so I fixed it by renaming the file. Woops.

http://ea.zzstack.com/summary.php

John S [ZZBOMB]

unread,
Jan 14, 2012, 11:50:26 AM1/14/12
to empireave-ap...@googlegroups.com
I cant currently update the database from which that page is getting it's data from until I fix my _GET script. I love having the data in a separate database, makes for creating frontend stuff a breeze and you don't have to use the API anymore.

I need to break my GET script up into pieces or something because currently it tries to collect all profile/info for my entire portfolio and since its php it times out. It cannot do like 70 API calls in 30 seconds.. Who knew? (I expected this issue. was too lazy to make it properly, just wanted a few thousand rows of data first to test stuff.)

I have a much more efficient way of doing it that I can cron more easily and make easily expandable. But that's going to like require another several hundred lines or so to properly make it oop. So going to do that sometime soon. It shall be one of those late nights where I intake a superfluous amount of caffeine and then just watch my hands do the magic. Yea.
Reply all
Reply to author
Forward
0 new messages