package page.example.betfair;
/*
import java.io.IOException;
import org.wikiwebserver.core.WareHouse;
import org.wikiwebserver.core.WikiMap;
import org.wikiwebserver.handler.http.interfaces.HTTPResponder;
import org.wikiwebserver.util.BetFairHelper;
import page.tools.html.TemplatedPushPage;
import static org.wikiwebserver.html.HTMLHelper.*;
import com.betfair.www.publicapi.types.exchange.v3.*;
public class BetFairWatcher extends TemplatedPushPage implements HTTPResponder {
private BetFairHelper betFair;
private String username, password;
private static int marketID = 2839755;
private Market market;
protected void generate() {
if (getFormData() != null) {
username = getFormData().getFirst("username");
password = getFormData().getFirst("password");
marketID = Integer.parseInt(getFormData().getFirst("market"));
setUpdatePeriod(6100);
setPushEnabled(true);
}
setTitle("BetFair Market Watcher - WikiWebServer.org");
addResourceRoot("/templates/default/betfair/");
addCSSLink("betfair.css");
String url = WareHouse.getUrlPathForClass(page.image.LineGraph.class)
+ "?w=700&f=reciprocal&d=" + marketID;
append("
BetFair Market Watcher
" +
"The BetFair market watcher uses the BetFair Java API to monitor " +
" and render graphical betting information for live sporting events." +
" (Requires BetFair login, secure connection recommended)
" +
"Log in
" +
form(div("userdetails", div("loginDiv", "Not logged in") +
div("balanceDiv", "") +
div("errorDiv", "")) +
inputRow("Username: ", textfield("username", username), "(Betfair login)") +
inputRow("Password: ", passwordfield("password", password), "") +
inputRow("MarketID: ", textfield("market", String.valueOf(marketID)), "") +
"" + submitbutton("action", "Begin", "class='submit'")));
append("Market
" + div("marketDiv") +
"Betting data
" + div("dataDiv") +
image(url, "Graph of odds", "id='graph'"));
}
protected void begin() throws IOException {
updateDiv("loginDiv", "Logging in as " + username + "...");
betFair = new BetFairHelper(username, password);
try {
String result = betFair.login();
updateDiv("loginDiv", result);
} catch (Exception ex) {
updateDiv("loginDiv", ex.getMessage());
throw new IOException(ex.getMessage());
}
try {
GetAccountFundsResp funds = betFair.getAcctFunds();
updateDiv("balanceDiv", "Available Funds:
£" + funds.getAvailBalance());
} catch (Exception ex) {
updateDiv("balanceDiv", ex.getMessage());
throw new IOException(ex.getMessage());
}
try {
market = betFair.getMarket(marketID);
} catch (Exception ex) {
updateDiv("marketDiv", ex.getMessage());
throw new IOException(ex.getMessage());
}
}
protected void update() throws IOException {
try {
StringBuilder buffer = new StringBuilder();
buffer.append("" + market.getName() + "
");
buffer.append("" + market.getMarketDescription() + "
");
updateDiv("marketDiv", buffer.toString());
MarketPrices marketPrices = betFair.getMarketPrices(marketID);
if (marketPrices.getMarketStatus() == MarketStatusEnum.CLOSED) {
throw new Exception("Market is now " + marketPrices.getMarketStatus());
}
buffer = new StringBuilder();
buffer.append("Status: " + marketPrices.getMarketStatus() + "
");
Runner[] runners = market.getRunners();
RunnerPrices[] prices = marketPrices.getRunnerPrices();
buffer.append("");
buffer.append("Name | Price 1 | Price 2 | Price 3 |
");
// Data for graphing
StringBuilder headings = new StringBuilder();
headings.append("Time");
StringBuilder dataRow = new StringBuilder();
long time = System.currentTimeMillis();
dataRow.append(String.valueOf(time));
for (int i=0; i" + runners[i].getName() + " | ");
Price[] bestPrices = prices[i].getBestPricesToBack();
// Data for graphing
headings.append("," + runners[i].getName());
dataRow.append("," + bestPrices[0].getPrice());
for (int j=0; j" + bestPrices[j].getPrice() + "
");
buffer.append("£" + bestPrices[j].getAmountAvailable() + "");
}
buffer.append("");
}
buffer.append("
");
String lgd = (String) getData().get(String.valueOf(marketID));
if (lgd == null) lgd = headings.toString() + "\n";
lgd += dataRow.toString() + "\n";
getData().put(String.valueOf(marketID), lgd);
String url = WareHouse.getUrlPathForClass(page.image.LineGraph.class)
+ "?w=700&f=reciprocal&t=" + time + "&d=" + marketID;
append(javaScript(updateSrcScript("graph", url)));
updateDiv("dataDiv", buffer.toString());
} catch (Exception e) {
updateDiv("errorDiv", e.getMessage());
setPushEnabled(false);
}
}
private void updateDiv(String id, String newContent) throws IOException {
append(javaScript(updateHTMLScript(id, newContent)));
flush();
}
private String inputRow(String label, String field, String detail) {
return "";
}
public WikiMap getData() {
WikiMap data = WareHouse.getWikiMap("LineGraphData");
if (data == null) data = WareHouse.initWikiMap("LineGraphData");
return data;
}
}
*/