Wednesday, June 17, 2015

Sending email with Google AppEngine





import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

void email()
{
        Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);
     
        String msgBody = name + "\n" + description + "\n" + email;

        try {
            Message msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress("sender@email.com",
                    "sender"));
            msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
                    "recipientEmail", "recipientName"));
            msg.setSubject("Greetings");
            msg.setText("Hello");
            Transport.send(msg);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

}

Updating entity in Datastore

//https://cloud.google.com/appengine/docs/java/datastore/transactions

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.datastore.Transaction;
import com.google.appengine.api.datastore.TransactionOptions;

void myTxn() {
 DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
 TransactionOptions options = TransactionOptions.Builder.withXG(true);
 Transaction txn = datastore.beginTransaction(options);

 Entity a = new Entity("EntityName");
 a.setProperty("Property", "Value");
 datastore.put(txn, a);

 txn.commit();
}

Applying SMA10/20, SMA20/50 as trading signals

This is the comparison for results before and after applying SMA10/20 and SMA20/50 in the stock trader. Background Trading 3 stock ma...