-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
massive changes, probably broke some things; converted to Guice, remo…
…ving ModuleLoader (#21); renamed old Commands to RunMode; added ConsoleRunMode; added Commands and Antlr; renamed Esper to Context; moved modules out of packages; started Strategy implementation
- Loading branch information
tim
committed
Jun 16, 2014
1 parent
1aea992
commit 76d027a
Showing
96 changed files
with
2,198 additions
and
891 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
grammar Base; | ||
|
||
WS: // ignore whitespace | ||
[ \r\t\n]+ | ||
-> skip | ||
; | ||
|
||
Amount: | ||
[0-9]+ | ||
| | ||
[0-9]* '.' [0-9]+ | ||
; | ||
|
||
Currency: | ||
[a-zA-Z][a-zA-Z]([a-zA-Z]([a-zA-Z])?)? // 2-4 alphas.. todo isn't there a better way to do this [a-zA-Z]{2-4} doesn't work | ||
; | ||
|
||
Exchange: | ||
[a-zA-Z_]+ | ||
; | ||
|
||
Listing: | ||
Currency '.' Currency | ||
; | ||
|
||
Market: | ||
Exchange ':' Listing | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
grammar Order; | ||
|
||
import Base; | ||
|
||
|
||
args : volume market ('stop' stopPrice)? ('limit' limitPrice)? ; | ||
|
||
market : Market; | ||
|
||
volume : Amount; | ||
|
||
stopPrice : Amount; | ||
|
||
limitPrice : Amount; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/main/java/org/cryptocoinpartners/bin/ConsoleRunMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package org.cryptocoinpartners.bin; | ||
|
||
import com.beust.jcommander.Parameters; | ||
import jline.Completor; | ||
import jline.ConsoleReader; | ||
import jline.History; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.cryptocoinpartners.command.Command; | ||
import org.cryptocoinpartners.command.CommandBase; | ||
import org.cryptocoinpartners.command.ConsoleWriter; | ||
import org.cryptocoinpartners.command.ParseError; | ||
import org.cryptocoinpartners.module.Context; | ||
import org.cryptocoinpartners.module.BasicAccountService; | ||
import org.cryptocoinpartners.module.MockOrderService; | ||
import org.cryptocoinpartners.module.BasicQuoteService; | ||
import org.cryptocoinpartners.module.TickWindow; | ||
import org.cryptocoinpartners.module.xchangedata.XchangeData; | ||
import org.cryptocoinpartners.schema.Fund; | ||
import org.cryptocoinpartners.util.Config; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
|
||
/** | ||
* @author Tim Olson | ||
*/ | ||
@SuppressWarnings("UnusedDeclaration") | ||
@Parameters(commandNames = {"console","terminal"}, commandDescription = "run in interactive mode") | ||
public class ConsoleRunMode extends RunMode { | ||
|
||
public void run() { | ||
try { | ||
init(); | ||
//noinspection InfiniteLoopStatement | ||
while(true) { | ||
String line = console.readLine(); | ||
if( StringUtils.isEmpty(line) ) | ||
continue; | ||
Matcher matcher = Pattern.compile("^(\\w+)(\\s+.*)?$").matcher(line); | ||
if( !matcher.matches() ) { | ||
out.println("Could not understand command name"); | ||
continue; | ||
} | ||
String commandName = matcher.group(1); | ||
Command command = CommandBase.commandForName(commandName,context); | ||
if( command == null ) { | ||
out.println("Unknown command " + commandName + ". Available commands:"); | ||
out.printList(CommandBase.allCommandNames()); | ||
continue; | ||
} | ||
String argStr = matcher.group(2); | ||
if( argStr == null ) | ||
argStr = ""; | ||
try { | ||
command.parse(argStr); | ||
} | ||
catch( ParseError e ) { | ||
out.println(e.getMessage()); | ||
} | ||
catch( Throwable e ) { | ||
log.warn("Could not parse command " + commandName, e); | ||
} | ||
try { | ||
command.run(); | ||
} | ||
catch( Throwable e ) { | ||
log.warn("Could not run command "+commandName,e); | ||
out.println("Internal error: see cointrader.log"); | ||
} | ||
} | ||
} | ||
catch( IOException e ) { | ||
throw new Error("Console exception",e); | ||
} | ||
} | ||
|
||
|
||
private void init() throws IOException { | ||
context = new Context(); | ||
|
||
context.attach(XchangeData.class); | ||
context.attach(TickWindow.class); | ||
context.attach(BasicQuoteService.class); | ||
context.attach(BasicAccountService.class); | ||
context.attach(MockOrderService.class); | ||
|
||
console = new ConsoleReader(); | ||
String prompt = Config.combined().getString("console.cursor","ct>"); | ||
console.setDefaultPrompt(prompt); | ||
console.setHistory(new History()); | ||
console.setUseHistory(true); | ||
console.addCompletor(new Completor() { | ||
public int complete(String s, int i, List list) { | ||
return 0; | ||
} | ||
}); | ||
out = new ConsoleWriter(console); | ||
context.attach(PrintWriter.class,out); | ||
} | ||
|
||
|
||
private Fund fund; | ||
private Context context; | ||
private ConsoleReader console; | ||
private ConsoleWriter out; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.