Skip to content

Commit

Permalink
wip first commit reading orders from console or file
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnieskywalker committed Mar 15, 2023
0 parents commit d1c9f96
Show file tree
Hide file tree
Showing 29 changed files with 1,736 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .breakpoints
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"files": {}
}
1 change: 1 addition & 0 deletions .cache/replit/__replit_disk_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"nonce":6607054972745264056,"last_updated":{"seconds":1678914868,"nanos":372311000}}
1 change: 1 addition & 0 deletions .cache/replit/modules.stamp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2jmj7l5rSw0yVb_vlWAYkK_YBwk=
1 change: 1 addition & 0 deletions .cache/replit/nix/env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"entries":{"replit.nix":{"env":{"AR":"ar","AS":"as","CC":"gcc","CONFIG_SHELL":"/nix/store/dsd5gz46hdbdk2rfdimqddhq6m8m8fqs-bash-5.1-p16/bin/bash","CXX":"g++","HOST_PATH":"/nix/store/5wq7080jgnp0j8fc477ql3khl6hbibm2-imagemagick-6.9.12-26-dev/bin:/nix/store/63ncbq2mzg4cc1l6r81rzf1r4zgsdm0a-fftw-double-3.3.10-dev/bin:/nix/store/67n7ypjxgg0k63ysvgyhyfg7paa2hgsx-imagemagick-6.9.12-26/bin:/nix/store/gpxl5qgg8kicmcvivwmybwjlpf7wh20l-graalvm17-ce-22.3.0/bin:/nix/store/6z9ag3ihc8mq2hzsw48lhbznvzny65nz-apache-maven-3.8.6/bin:/nix/store/m6gcpi1ii6rghy04cjwjddcavv7i90df-jdt-language-server-1.9.0/bin:/nix/store/84xs5alhs01zrbr4ywm05kxbjbp5590l-java-debug/bin:/nix/store/a7gvj343m05j2s32xcnwr35v31ynlypr-coreutils-9.1/bin:/nix/store/mydc6f4k2z73xlcz7ilif3v2lcaiqvza-findutils-4.9.0/bin:/nix/store/j9p3g8472iijd50vhdprx0nmk2fqn5gv-diffutils-3.8/bin:/nix/store/89zs7rms6x00xfq4dq6m7mjnhkr8a6r4-gnused-4.8/bin:/nix/store/86bp03jkmsl6f92w0yzg4s59g5mhxwmy-gnugrep-3.7/bin:/nix/store/hwcdqw4jrjnd37wxqgsd47hd0j8bnj09-gawk-5.1.1/bin:/nix/store/cfbhw8r8ags41vwqaz47r583d0p4h4a1-gnutar-1.34/bin:/nix/store/p3m1ndl1lapwrlh698bnb5lvvxh67378-gzip-1.12/bin:/nix/store/a8mhcagrsly7c7mpjrpsnaahk4aax056-bzip2-1.0.8-bin/bin:/nix/store/mblgz65m3zv9x548a3d5m96fj2pbwr09-gnumake-4.3/bin:/nix/store/dsd5gz46hdbdk2rfdimqddhq6m8m8fqs-bash-5.1-p16/bin:/nix/store/v7ljksji50mg3w61dykaa3n3y79n6nil-patch-2.7.6/bin:/nix/store/zlcnmqq14jz5x9439jf937mvayyl63da-xz-5.2.7-bin/bin:/nix/store/y6aj732zm9m87c82fpvf103a1xb22blp-file-5.43/bin","JAVA_HOME":"/nix/store/gpxl5qgg8kicmcvivwmybwjlpf7wh20l-graalvm17-ce-22.3.0","LD":"ld","LOCALE_ARCHIVE":"/usr/lib/locale/locale-archive","NIX_BINTOOLS":"/nix/store/1d6ian3r8kdzspw8hacjhl3xkp40g1lj-binutils-wrapper-2.39","NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu":"1","NIX_BUILD_CORES":"8","NIX_BUILD_TOP":"/tmp","NIX_CC":"/nix/store/dq0xwmsk1g0i2ayg6pb7y87na2knzylh-gcc-wrapper-11.3.0","NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu":"1","NIX_CFLAGS_COMPILE":" -frandom-seed=3amv8d2qar -isystem /nix/store/5wq7080jgnp0j8fc477ql3khl6hbibm2-imagemagick-6.9.12-26-dev/include -isystem /nix/store/63ncbq2mzg4cc1l6r81rzf1r4zgsdm0a-fftw-double-3.3.10-dev/include -isystem /nix/store/gpxl5qgg8kicmcvivwmybwjlpf7wh20l-graalvm17-ce-22.3.0/include -isystem /nix/store/0y971q54v6jm9ss243xhl4y0gnlsm9c8-zlib-1.2.13-dev/include -isystem /nix/store/5wq7080jgnp0j8fc477ql3khl6hbibm2-imagemagick-6.9.12-26-dev/include -isystem /nix/store/63ncbq2mzg4cc1l6r81rzf1r4zgsdm0a-fftw-double-3.3.10-dev/include -isystem /nix/store/gpxl5qgg8kicmcvivwmybwjlpf7wh20l-graalvm17-ce-22.3.0/include -isystem /nix/store/0y971q54v6jm9ss243xhl4y0gnlsm9c8-zlib-1.2.13-dev/include","NIX_ENFORCE_NO_NATIVE":"1","NIX_HARDENING_ENABLE":"fortify stackprotector pic strictoverflow format relro bindnow","NIX_INDENT_MAKE":"1","NIX_LDFLAGS":"-rpath /nix/store/3amv8d2qarvg9nqjm0l6w25imm4bdw9l-nix-shell/lib64 -rpath /nix/store/3amv8d2qarvg9nqjm0l6w25imm4bdw9l-nix-shell/lib -L/nix/store/4sy52csa9ys3kjlsxipm8anlcykzjx9f-fftw-double-3.3.10/lib -L/nix/store/67n7ypjxgg0k63ysvgyhyfg7paa2hgsx-imagemagick-6.9.12-26/lib -L/nix/store/gpxl5qgg8kicmcvivwmybwjlpf7wh20l-graalvm17-ce-22.3.0/lib -L/nix/store/026hln0aq1hyshaxsdvhg0kmcm6yf45r-zlib-1.2.13/lib -L/nix/store/2h0a1ma7bp2vprkmh6n4n2k1hcn1z0x8-graalvm17-ce-22.3.0-lib/lib -L/nix/store/4sy52csa9ys3kjlsxipm8anlcykzjx9f-fftw-double-3.3.10/lib -L/nix/store/67n7ypjxgg0k63ysvgyhyfg7paa2hgsx-imagemagick-6.9.12-26/lib -L/nix/store/gpxl5qgg8kicmcvivwmybwjlpf7wh20l-graalvm17-ce-22.3.0/lib -L/nix/store/026hln0aq1hyshaxsdvhg0kmcm6yf45r-zlib-1.2.13/lib -L/nix/store/2h0a1ma7bp2vprkmh6n4n2k1hcn1z0x8-graalvm17-ce-22.3.0-lib/lib","NIX_STORE":"/nix/store","NM":"nm","OBJCOPY":"objcopy","OBJDUMP":"objdump","PATH":"/nix/store/bap4d0lpcrhpwmpb8ayjcgkmvfj62lnq-bash-interactive-5.1-p16/bin:/nix/store/pr5n59mb4jzmfx6kanwxly0l07p861fg-patchelf-0.15.0/bin:/nix/store/dq0xwmsk1g0i2ayg6pb7y87na2knzylh-gcc-wrapper-11.3.0/bin:/nix/store/1gf2flfqnpqbr1b4p4qz2f72y42bs56r-gcc-11.3.0/bin:/nix/store/57xv61c5zi8pphjbcwxxjlgc34p61ic9-glibc-2.35-163-bin/bin:/nix/store/a7gvj343m05j2s32xcnwr35v31ynlypr-coreutils-9.1/bin:/nix/store/1d6ian3r8kdzspw8hacjhl3xkp40g1lj-binutils-wrapper-2.39/bin:/nix/store/039g378vc3pc3dvi9dzdlrd0i4q93qwf-binutils-2.39/bin:/nix/store/5wq7080jgnp0j8fc477ql3khl6hbibm2-imagemagick-6.9.12-26-dev/bin:/nix/store/63ncbq2mzg4cc1l6r81rzf1r4zgsdm0a-fftw-double-3.3.10-dev/bin:/nix/store/67n7ypjxgg0k63ysvgyhyfg7paa2hgsx-imagemagick-6.9.12-26/bin:/nix/store/gpxl5qgg8kicmcvivwmybwjlpf7wh20l-graalvm17-ce-22.3.0/bin:/nix/store/6z9ag3ihc8mq2hzsw48lhbznvzny65nz-apache-maven-3.8.6/bin:/nix/store/m6gcpi1ii6rghy04cjwjddcavv7i90df-jdt-language-server-1.9.0/bin:/nix/store/84xs5alhs01zrbr4ywm05kxbjbp5590l-java-debug/bin:/nix/store/a7gvj343m05j2s32xcnwr35v31ynlypr-coreutils-9.1/bin:/nix/store/mydc6f4k2z73xlcz7ilif3v2lcaiqvza-findutils-4.9.0/bin:/nix/store/j9p3g8472iijd50vhdprx0nmk2fqn5gv-diffutils-3.8/bin:/nix/store/89zs7rms6x00xfq4dq6m7mjnhkr8a6r4-gnused-4.8/bin:/nix/store/86bp03jkmsl6f92w0yzg4s59g5mhxwmy-gnugrep-3.7/bin:/nix/store/hwcdqw4jrjnd37wxqgsd47hd0j8bnj09-gawk-5.1.1/bin:/nix/store/cfbhw8r8ags41vwqaz47r583d0p4h4a1-gnutar-1.34/bin:/nix/store/p3m1ndl1lapwrlh698bnb5lvvxh67378-gzip-1.12/bin:/nix/store/a8mhcagrsly7c7mpjrpsnaahk4aax056-bzip2-1.0.8-bin/bin:/nix/store/mblgz65m3zv9x548a3d5m96fj2pbwr09-gnumake-4.3/bin:/nix/store/dsd5gz46hdbdk2rfdimqddhq6m8m8fqs-bash-5.1-p16/bin:/nix/store/v7ljksji50mg3w61dykaa3n3y79n6nil-patch-2.7.6/bin:/nix/store/zlcnmqq14jz5x9439jf937mvayyl63da-xz-5.2.7-bin/bin:/nix/store/y6aj732zm9m87c82fpvf103a1xb22blp-file-5.43/bin","RANLIB":"ranlib","READELF":"readelf","SIZE":"size","SOURCE_DATE_EPOCH":"315532800","STRINGS":"strings","STRIP":"strip","XDG_DATA_DIRS":"/nix/store/pr5n59mb4jzmfx6kanwxly0l07p861fg-patchelf-0.15.0/share","_":"/nix/store/a7gvj343m05j2s32xcnwr35v31ynlypr-coreutils-9.1/bin/env","__ETC_PROFILE_SOURCED":"1","buildInputs":"/nix/store/5wq7080jgnp0j8fc477ql3khl6hbibm2-imagemagick-6.9.12-26-dev /nix/store/gpxl5qgg8kicmcvivwmybwjlpf7wh20l-graalvm17-ce-22.3.0 /nix/store/6z9ag3ihc8mq2hzsw48lhbznvzny65nz-apache-maven-3.8.6 /nix/store/m6gcpi1ii6rghy04cjwjddcavv7i90df-jdt-language-server-1.9.0 /nix/store/84xs5alhs01zrbr4ywm05kxbjbp5590l-java-debug","buildPhase":"echo \"------------------------------------------------------------\" \u003e\u003e$out\necho \" WARNING: the existence of this path is not guaranteed.\" \u003e\u003e$out\necho \" It is an internal implementation detail for pkgs.mkShell.\" \u003e\u003e$out\necho \"------------------------------------------------------------\" \u003e\u003e$out\necho \u003e\u003e $out\n# Record all build inputs as runtime dependencies\nexport \u003e\u003e $out\n","builder":"/nix/store/dsd5gz46hdbdk2rfdimqddhq6m8m8fqs-bash-5.1-p16/bin/bash","cmakeFlags":"","configureFlags":"","depsBuildBuild":"","depsBuildBuildPropagated":"","depsBuildTarget":"","depsBuildTargetPropagated":"","depsHostHost":"","depsHostHostPropagated":"","depsTargetTarget":"","depsTargetTargetPropagated":"","doCheck":"","doInstallCheck":"","mesonFlags":"","name":"nix-shell","nativeBuildInputs":"","out":"/nix/store/3amv8d2qarvg9nqjm0l6w25imm4bdw9l-nix-shell","outputs":"out","patches":"","phases":"buildPhase","propagatedBuildInputs":"","propagatedNativeBuildInputs":"","shell":"/nix/store/dsd5gz46hdbdk2rfdimqddhq6m8m8fqs-bash-5.1-p16/bin/bash","shellHook":"","stdenv":"/nix/store/kmfaajdpyyyg319vfqni5jm9wkxjmf73-stdenv-linux","strictDeps":"","system":"x86_64-linux"},"dependencies":[{"path":"replit.nix","mod_time":"2023-03-15T17:09:03.945609274Z"}],"channel":"stable-22_11","channel_nix_path":"/nix/store/nw56f75dmj9iyb0gmkcqyl62i7800d82-nixpkgs-stable-22_11-22.11.tar.gz/nixpkgs-stable-22_11"}}}
44 changes: 44 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
34 changes: 34 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>myartifactid</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
<filteredResources>
<filter>
<id>1678653352941</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
59 changes: 59 additions & 0 deletions .replit
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
compile = "javac -classpath .:target/dependency/* -d . $(find . -type f -name '*.java')"
run = "java -classpath .:target/dependency/* Main"
entrypoint = "Main.java"
hidden = ["**/*.class"]

[packager]
language = "java"

[packager.features]
packageSearch = true

[languages.java]
pattern = "**/*.java"

[languages.java.languageServer]
start = "jdt-language-server"

[unitTest]
language = "java"

[nix]
channel = "stable-22_11"

[debugger]
support = true

[debugger.compile]
command = "javac -classpath .:/run_dir/junit-4.12.jar:target/dependency/* -g -d . $(find . -type f -name '*.java')"

[debugger.interactive]
transport = "localhost:0"
connectTimeout = 60
startCommand = "java-debug"

[debugger.interactive.initializeMessage]
command = "initialize"
type = "request"

[debugger.interactive.initializeMessage.arguments]
adapterID = "cppdbg"
clientID = "replit"
clientName = "replit.com"
columnsStartAt1 = true
linesStartAt1 = true
locale = "en-us"
pathFormat = "path"
supportsInvalidatedEvent = true
supportsProgressReporting = true
supportsRunInTerminalRequest = true
supportsVariablePaging = true
supportsVariableType = true

[debugger.interactive.launchMessage]
command = "launch"
type = "request"

[debugger.interactive.launchMessage.arguments]
classPaths = ["."]
mainClass = "Main"
2 changes: 2 additions & 0 deletions .settings/org.eclipse.jdt.apt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=false
9 changes: 9 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
4 changes: 4 additions & 0 deletions .settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
1 change: 1 addition & 0 deletions .upm/store.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":2,"languages":{"java-maven":{"specfileHash":"3ff69d18804bae1a389cb7ea263f0c5b","lockfileHash":"3ff69d18804bae1a389cb7ea263f0c5b"}}}
Binary file added Main.class
Binary file not shown.
87 changes: 87 additions & 0 deletions Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.time.Instant;

import wiki.misie.CentralLimitOrderBook;
import wiki.misie.Order;

class Main {
public static void main(String[] args) throws IOException {
CentralLimitOrderBook orderBook = new CentralLimitOrderBook();

List<Order> orders = new ArrayList<>();
if (args.length > 0) {
orders.addAll(readOrdersFromTxtFile(args[0]));
} else {
orders.addAll(readOrdersFromCommandLine());
}

for (Order order : orders) {
orderBook.addOrder(order.withTimestamp(Instant.now().getEpochSecond()));
}
}

private static List<Order> readOrdersFromTxtFile(String fileName) {
List<Order> orders = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
String line;
while ((line = br.readLine()) != null) {
String[] parts = line.split(" ");
if (parts.length != 3) {
System.out.println("Invalid input: " + line);
continue;
}
double price;
int quantity;
try {
price = Double.parseDouble(parts[1]);
quantity = Integer.parseInt(parts[2]);
} catch (NumberFormatException e) {
System.out.println("Invalid input: " + line);
continue;
}
if (parts[0].equalsIgnoreCase("buy")) {
orders.add(new Order(Order.Type.BUY, price, quantity));
} else if (parts[0].equalsIgnoreCase("sell")) {
orders.add(new Order(Order.Type.SELL, price, quantity));
} else {
System.out.println("Invalid input: " + line);
}
}
} catch (IOException e) {
System.out.println("Error reading orders from file: " + e.getMessage());
}
return orders;
}

private static List<Order> readOrdersFromCommandLine(String[] args) {
List<Order> orders = new ArrayList<>();
for (String arg : args) {
String[] parts = arg.split(" ");
if (parts.length != 3) {
System.out.println("Invalid input: " + arg);
continue;
}
double price;
int quantity;
try {
price = Double.parseDouble(parts[1]);
quantity = Integer.parseInt(parts[2]);
} catch (NumberFormatException e) {
System.out.println("Invalid input: " + arg);
continue;
}
if (parts[0].equalsIgnoreCase("buy")) {
orders.add(new Order(Order.Type.BUY, price, quantity));
} else if (parts[0].equalsIgnoreCase("sell")) {
orders.add(new Order(Order.Type.SELL, price, quantity));
} else {
System.out.println("Invalid input: " + arg);
}
}
return orders;
}
}
Binary file added OrderBook.class
Binary file not shown.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Order Book

## Example way to call with args from console

```sh
java -classpath .:target/dependency/* Main "buy 1000 99" "buy 500 99" "buy 500 98" "buy 1200 98" "sell 2000 101"
```

## Example with load from file

```sh
java -classpath .:target/dependency/* Main "orders.txt"
```

example orders.txt file

```
buy 100.5 10
sell 101.2 5
buy 99.5 20
sell 101.0 15
```
Loading

0 comments on commit d1c9f96

Please sign in to comment.