├── micro.png ├── chronograf.db ├── services ├── Python │ ├── test_pb2.pyc │ ├── .Dockerfile.swp │ ├── test.proto │ ├── Dockerfile │ ├── python-client.py │ ├── test_pb2.py │ └── yahoo_ticker.py ├── telegraf │ ├── Dockerfile │ ├── proto │ │ ├── telegraf.proto │ │ └── telegraf.pb.go │ └── telegraf.conf ├── javaconsumer │ ├── .settings │ │ ├── org.eclipse.m2e.core.prefs │ │ ├── org.eclipse.core.resources.prefs │ │ └── org.eclipse.jdt.core.prefs │ ├── Dockerfile │ ├── src │ │ ├── main │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── slack │ │ │ │ └── openalgot │ │ │ │ ├── client │ │ │ │ ├── HeaderAndBody.java │ │ │ │ └── Subscriber.java │ │ │ │ └── MarketEventProtos.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── biteagle │ │ │ └── tradingalgo │ │ │ └── DeserializationTest.java │ ├── .project │ ├── .classpath │ └── pom.xml ├── web │ ├── Dockerfile │ └── main.go ├── Sidecar │ ├── Dockerfile │ └── main.go ├── TickRecorder │ ├── Dockerfile │ ├── proto │ │ ├── tick.proto │ │ └── tick.pb.go │ ├── subscriber │ │ ├── tick.go │ │ └── trade.go │ ├── publisher │ │ ├── tick.go │ │ └── trade.go │ └── main.go ├── OandaTickSubscriber │ ├── Dockerfile │ └── main.go └── BitstampTickSubscriber │ ├── Dockerfile │ ├── main_test.go │ └── main.go ├── .gitignore ├── examplequery ├── Dockerfile ├── glide.yaml ├── docker-compose.yml ├── README.md └── glide.lock /micro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nii236/nii-finance/HEAD/micro.png -------------------------------------------------------------------------------- /chronograf.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nii236/nii-finance/HEAD/chronograf.db -------------------------------------------------------------------------------- /services/Python/test_pb2.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nii236/nii-finance/HEAD/services/Python/test_pb2.pyc -------------------------------------------------------------------------------- /services/Python/.Dockerfile.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nii236/nii-finance/HEAD/services/Python/.Dockerfile.swp -------------------------------------------------------------------------------- /services/telegraf/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM telegraf:0.13-alpine 2 | 3 | COPY ./telegraf.conf /etc/telegraf/telegraf.conf 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | services/OandaTickSubscriber/OandaTickSubscriber 2 | services/TickRecorder/TickRecorder 3 | services/Sidecar/Sidecar 4 | vendor 5 | -------------------------------------------------------------------------------- /services/Python/test.proto: -------------------------------------------------------------------------------- 1 | package openalgot; 2 | 3 | message MessageData { 4 | required string name = 1; 5 | required int32 id = 2; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /services/javaconsumer/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /services/javaconsumer/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/test/java=UTF-8 4 | encoding/=UTF-8 5 | -------------------------------------------------------------------------------- /examplequery: -------------------------------------------------------------------------------- 1 | {"Header":{"Content-Type":"application/octet-stream","X-From-Id":"script","X-User-Id":"john"},"Body":"CNjDnuf5mc2tFBG9c8IiFAVZQBnSs6PUDjlZQCGhSSQnWztZQCoGQVVEVVNEMgVvYW5kYQ=="} 2 | 3 | 176 4 | -------------------------------------------------------------------------------- /services/web/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openalgotplatform_go:0.1 2 | WORKDIR /go/src/github.com/nii236/nii-finance/services/web 3 | COPY . /go/src/github.com/nii236/nii-finance/ 4 | RUN go install 5 | ENTRYPOINT ["web"] 6 | -------------------------------------------------------------------------------- /services/Sidecar/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openalgotplatform_go:0.1 2 | WORKDIR /go/src/github.com/nii236/nii-finance/services/Sidecar 3 | COPY . /go/src/github.com/nii236/nii-finance/ 4 | RUN go install 5 | ENTRYPOINT ["Sidecar"] 6 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.6-alpine 2 | RUN apk update && apk add git 3 | RUN go get github.com/Masterminds/glide 4 | COPY . /go/src/github.com/nii236/nii-finance 5 | WORKDIR /go/src/github.com/nii236/nii-finance 6 | RUN glide up 7 | -------------------------------------------------------------------------------- /services/TickRecorder/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openalgotplatform_go:0.1 2 | WORKDIR /go/src/github.com/nii236/nii-finance/services/TickRecorder 3 | COPY . /go/src/github.com/nii236/nii-finance/ 4 | RUN go install 5 | ENTRYPOINT ["TickRecorder"] 6 | -------------------------------------------------------------------------------- /services/OandaTickSubscriber/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openalgotplatform_go:0.1 2 | WORKDIR /go/src/github.com/nii236/nii-finance/services/OandaTickSubscriber 3 | COPY . /go/src/github.com/nii236/nii-finance/ 4 | RUN go install 5 | ENTRYPOINT ["OandaTickSubscriber"] 6 | -------------------------------------------------------------------------------- /services/telegraf/proto/telegraf.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package go.srv.telegraf; 4 | 5 | message Telegraf { 6 | string measurement = 1; 7 | string key = 2; 8 | string value = 3; 9 | string time = 4; 10 | } 11 | -------------------------------------------------------------------------------- /services/BitstampTickSubscriber/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openalgotplatform_go:0.1 2 | WORKDIR /go/src/github.com/nii236/nii-finance/services/BitstampTickSubscriber 3 | COPY . /go/src/github.com/nii236/nii-finance/ 4 | RUN go install 5 | ENTRYPOINT ["BitstampTickSubscriber"] 6 | -------------------------------------------------------------------------------- /services/javaconsumer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM maven:3-jdk-8 2 | RUN mkdir -p /usr/src/app 3 | WORKDIR /usr/src/app 4 | ADD . /usr/src/app 5 | RUN mvn install 6 | RUN mvn package 7 | WORKDIR /usr/src/app/target 8 | ENTRYPOINT ["java", "-jar", "javaconsumer-0.0.1-SNAPSHOT.jar"] 9 | -------------------------------------------------------------------------------- /services/Python/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:2.7-alpine 2 | 3 | MAINTAINER jacob.everist@gmail.com 4 | 5 | RUN pip install werkzeug 6 | RUN pip install requests 7 | RUN pip install protobuf 8 | 9 | 10 | EXPOSE 4000 11 | 12 | ADD . /python_app 13 | 14 | WORKDIR /python_app 15 | 16 | CMD [ "python", "yahoo_ticker.py" ] 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /services/BitstampTickSubscriber/main_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | "time" 7 | ) 8 | 9 | func TestPublish(t *testing.T) { 10 | fmt.Println(time.Now().UnixNano()) 11 | input := `{"price": 469.0, "timestamp": "1464340140", "amount": 1.80891143, "type": 0, "id": 11226014}` 12 | publish(input) 13 | 14 | } 15 | -------------------------------------------------------------------------------- /services/TickRecorder/proto/tick.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package go.srv.TickRecorder; 4 | 5 | option java_package = "com.slack.openalgot"; 6 | option java_outer_classname = "MarketEventProtos"; 7 | 8 | message Tick { 9 | int64 time = 1; 10 | double bid = 2; 11 | double ask = 3; 12 | double last = 4; 13 | string pair = 5; 14 | string broker = 6; 15 | } 16 | 17 | message Trade { 18 | int64 time = 1; 19 | double price = 2; 20 | double amount = 3; 21 | int32 type = 4; 22 | string broker = 6; 23 | string pair = 7; 24 | } 25 | -------------------------------------------------------------------------------- /services/Python/python-client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Thu Jun 02 22:36:21 2016 4 | 5 | @author: Jacob 6 | """ 7 | 8 | import test_pb2 9 | import requests 10 | 11 | payload = {"jsonrpc": "2.0", 12 | "method": "postMessage", 13 | "params": [{"name": "Jacob"}], 14 | "id": 99} 15 | 16 | msg = test_pb2.MessageData() 17 | msg.id = 1234 18 | msg.name = "John Doe" 19 | 20 | url = "http://127.0.0.1:4000" 21 | 22 | # POST with protobuf 23 | r = requests.post(url, data=msg.SerializeToString()) 24 | 25 | print r.text 26 | print r.headers['content-type'] 27 | print r.status_code 28 | 29 | -------------------------------------------------------------------------------- /services/web/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | ccli "github.com/micro/cli" 5 | "github.com/micro/go-micro/cmd" 6 | "github.com/micro/micro/web" 7 | 8 | _ "github.com/micro/go-plugins/broker/nats" 9 | _ "github.com/micro/go-plugins/registry/nats" 10 | _ "github.com/micro/go-plugins/transport/nats" 11 | ) 12 | 13 | func main() { 14 | app := cmd.App() 15 | app.Commands = append(app.Commands, web.Commands()...) 16 | app.Action = func(context *ccli.Context) { ccli.ShowAppHelp(context) } 17 | cmd.Init( 18 | cmd.Name("micro"), 19 | cmd.Description("This version of micro contains only the web UI"), 20 | cmd.Version("latest"), 21 | ) 22 | } 23 | -------------------------------------------------------------------------------- /services/Sidecar/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | ccli "github.com/micro/cli" 5 | "github.com/micro/go-micro/cmd" 6 | "github.com/micro/micro/car" 7 | 8 | _ "github.com/micro/go-plugins/broker/nats" 9 | _ "github.com/micro/go-plugins/registry/nats" 10 | _ "github.com/micro/go-plugins/transport/nats" 11 | ) 12 | 13 | func main() { 14 | app := cmd.App() 15 | app.Commands = append(app.Commands, car.Commands()...) 16 | app.Action = func(context *ccli.Context) { ccli.ShowAppHelp(context) } 17 | cmd.Init( 18 | cmd.Name("micro"), 19 | cmd.Description("This version of micro contains only the micro web UI"), 20 | cmd.Version("latest"), 21 | ) 22 | } 23 | -------------------------------------------------------------------------------- /services/javaconsumer/src/main/java/com/slack/openalgot/client/HeaderAndBody.java: -------------------------------------------------------------------------------- 1 | package com.slack.openalgot.client; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | 6 | @JsonIgnoreProperties({"Header"}) 7 | public class HeaderAndBody { 8 | 9 | @JsonProperty("Body") 10 | private String body; 11 | 12 | public String getBody() { 13 | return body; 14 | } 15 | 16 | public void setBody(String body) { 17 | this.body = body; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return "HeaderAndBody [body=" + body + "]"; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /services/javaconsumer/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | javaconsumer 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /services/TickRecorder/subscriber/tick.go: -------------------------------------------------------------------------------- 1 | package subscriber 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/micro/go-micro/client" 7 | "golang.org/x/net/context" 8 | proto "github.com/nii236/nii-finance/services/TickRecorder/proto" 9 | "github.com/nii236/nii-finance/services/TickRecorder/publisher" 10 | ) 11 | 12 | // Tick is a struct that contains Tick handlers 13 | type Tick struct { 14 | Client client.Client 15 | } 16 | 17 | // Handle will respond to relevant messages on the topic it is registered 18 | func (e *Tick) Handle(ctx context.Context, msg *proto.Tick) error { 19 | log.Print("Handler received tick data. Publishing...") 20 | publisher.PublishTick(msg) 21 | return nil 22 | } 23 | -------------------------------------------------------------------------------- /services/TickRecorder/subscriber/trade.go: -------------------------------------------------------------------------------- 1 | package subscriber 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/micro/go-micro/client" 7 | "golang.org/x/net/context" 8 | proto "github.com/nii236/nii-finance/services/TickRecorder/proto" 9 | "github.com/nii236/nii-finance/services/TickRecorder/publisher" 10 | ) 11 | 12 | // Trade is a struct that contains Trade handlers 13 | type Trade struct { 14 | c client.Client 15 | } 16 | 17 | // Handle will respond to relevant messages on the topic it is registered 18 | func (e *Trade) Handle(ctx context.Context, msg *proto.Trade) error { 19 | log.Print("TickRecorder received trade data. Publishing...") 20 | publisher.PublishTrade(msg) 21 | return nil 22 | } 23 | -------------------------------------------------------------------------------- /services/javaconsumer/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.8 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 12 | org.eclipse.jdt.core.compiler.source=1.8 13 | -------------------------------------------------------------------------------- /services/TickRecorder/publisher/tick.go: -------------------------------------------------------------------------------- 1 | package publisher 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | 7 | nats "github.com/nats-io/nats" 8 | 9 | tickproto "github.com/nii236/nii-finance/services/TickRecorder/proto" 10 | ) 11 | 12 | // PublishTick sends out single tick to telegraf to save to InfluxDB 13 | func PublishTick(t *tickproto.Tick) { 14 | broker := t.Broker 15 | last := t.Last 16 | ask := t.Ask 17 | bid := t.Bid 18 | pair := t.Pair 19 | time := t.Time 20 | 21 | nc, err := nats.Connect("nats://nats:4222") 22 | if err != nil { 23 | log.Println(err) 24 | } 25 | defer nc.Close() 26 | 27 | msg := fmt.Sprintf("tick,broker=%s,pair=%s ask=%f,bid=%f,last=%f %d", broker, pair, ask, bid, last, time) 28 | if err := nc.Publish("go.micro.telegraf", []byte(msg)); err != nil { 29 | log.Println(err) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /glide.yaml: -------------------------------------------------------------------------------- 1 | package: github.com/nii236/nii-finance 2 | import: 3 | - package: github.com/Sirupsen/logrus 4 | - package: github.com/golang/protobuf 5 | subpackages: 6 | - proto 7 | - package: github.com/micro/cli 8 | - package: github.com/micro/go-micro 9 | subpackages: 10 | - client 11 | - cmd 12 | - metadata 13 | - server 14 | - package: github.com/micro/go-plugins 15 | subpackages: 16 | - broker/nats 17 | - registry/nats 18 | - transport/nats 19 | - package: github.com/micro/micro 20 | subpackages: 21 | - car 22 | - package: github.com/nats-io/nats 23 | - package: github.com/pusher-community/pusher-websocket-go 24 | - package: golang.org/x/net 25 | subpackages: 26 | - context 27 | - package: google.golang.org/grpc 28 | subpackages: 29 | - metadata 30 | - package: github.com/nii236/nii-finance 31 | subpackages: 32 | - github.com/serenize/snaker 33 | -------------------------------------------------------------------------------- /services/TickRecorder/publisher/trade.go: -------------------------------------------------------------------------------- 1 | package publisher 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | 7 | nats "github.com/nats-io/nats" 8 | 9 | tickproto "github.com/nii236/nii-finance/services/TickRecorder/proto" 10 | ) 11 | 12 | func PublishTrade(t *tickproto.Trade) { 13 | broker := t.Broker 14 | price := t.Price 15 | time := t.Time 16 | amount := t.Amount 17 | pair := t.Pair 18 | tradeType := "untyped" 19 | if t.Type == 0 { 20 | tradeType = "buy" 21 | } else if t.Type == 1 { 22 | tradeType = "sell" 23 | } 24 | nc, err := nats.Connect("nats://nats:4222") 25 | if err != nil { 26 | log.Println(err) 27 | } 28 | defer nc.Close() 29 | 30 | msg := fmt.Sprintf("trade,broker=%s,type=%s,pair=%s price=%f,amount=%f %d", broker, tradeType, pair, price, amount, time) 31 | if err := nc.Publish("go.micro.telegraf", []byte(msg)); err != nil { 32 | log.Println(err) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /services/javaconsumer/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /services/javaconsumer/src/test/java/com/biteagle/tradingalgo/DeserializationTest.java: -------------------------------------------------------------------------------- 1 | package com.biteagle.tradingalgo; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.Base64; 6 | 7 | import org.junit.After; 8 | import org.junit.AfterClass; 9 | import org.junit.Before; 10 | import org.junit.BeforeClass; 11 | import org.junit.Test; 12 | 13 | import com.google.protobuf.InvalidProtocolBufferException; 14 | import com.slack.openalgot.MarketEventProtos.Trade; 15 | 16 | public class DeserializationTest { 17 | 18 | @BeforeClass 19 | public static void setUpBeforeClass() throws Exception { 20 | } 21 | 22 | @AfterClass 23 | public static void tearDownAfterClass() throws Exception { 24 | } 25 | 26 | @Before 27 | public void setUp() throws Exception { 28 | } 29 | 30 | @After 31 | public void tearDown() throws Exception { 32 | } 33 | 34 | @Test 35 | public void test() { 36 | byte[] b = Base64.getDecoder().decode("EQAAAAAAyoBAGWiR7Xw/Nb4/"); 37 | try { 38 | Trade trade = Trade.parseFrom(b); 39 | System.out.println(trade.getTime()); 40 | System.out.println(trade.getAmount()); 41 | System.out.println(trade.getPrice()); 42 | } catch (InvalidProtocolBufferException e) { 43 | // TODO Auto-generated catch block 44 | e.printStackTrace(); 45 | fail(); 46 | } 47 | 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /services/OandaTickSubscriber/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "math/rand" 6 | "net" 7 | "sync" 8 | "time" 9 | 10 | "github.com/micro/go-micro/client" 11 | "github.com/micro/go-micro/cmd" 12 | "github.com/micro/go-micro/metadata" 13 | _ "github.com/micro/go-plugins/broker/nats" 14 | _ "github.com/micro/go-plugins/registry/nats" 15 | _ "github.com/micro/go-plugins/transport/nats" 16 | proto "github.com/nii236/nii-finance/services/TickRecorder/proto" 17 | "golang.org/x/net/context" 18 | ) 19 | 20 | type pairslice []string 21 | 22 | var pairs pairslice 23 | 24 | func main() { 25 | cmd.Init() 26 | log.Println("Starting up Oanda Tick Subscriber...") 27 | addrs, err := net.InterfaceAddrs() 28 | if err != nil { 29 | log.Println(err) 30 | } 31 | log.Println("Interfaces:") 32 | for _, add := range addrs { 33 | log.Println(add.Network()+":", add.String()) 34 | } 35 | r := rand.New(rand.NewSource(time.Now().UnixNano())) 36 | wg := sync.WaitGroup{} 37 | wg.Add(1) 38 | t := time.NewTicker(10 * time.Second) 39 | for range t.C { 40 | log.Println("Publishing mock tick data...") 41 | ctx := metadata.NewContext(context.Background(), map[string]string{ 42 | "X-User-Id": "john", 43 | "X-From-Id": "script", 44 | }) 45 | tmpbid := 100.0 + rand.Float64() 46 | now := time.Now().UnixNano() 47 | msg := client.NewPublication("go.micro.srv.TickRecorder.Tick", &proto.Tick{ 48 | Time: now, 49 | Bid: tmpbid, 50 | Ask: tmpbid + r.Float64(), 51 | Last: 100.0 + r.Float64(), 52 | Pair: "AUDUSD", 53 | Broker: "oanda", 54 | }) 55 | if err := client.Publish(ctx, msg); err != nil { 56 | log.Println("publish err: ", err) 57 | } 58 | } 59 | wg.Wait() 60 | } 61 | -------------------------------------------------------------------------------- /services/TickRecorder/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net" 5 | "time" 6 | 7 | log "github.com/Sirupsen/logrus" 8 | 9 | micro "github.com/micro/go-micro" 10 | "github.com/micro/go-micro/cmd" 11 | "github.com/micro/go-micro/server" 12 | _ "github.com/micro/go-plugins/broker/nats" 13 | _ "github.com/micro/go-plugins/registry/nats" 14 | _ "github.com/micro/go-plugins/transport/nats" 15 | "github.com/nii236/nii-finance/services/TickRecorder/subscriber" 16 | ) 17 | 18 | func opts(o *micro.Options) { 19 | o.Server = server.NewServer(func(o *server.Options) { 20 | o.Name = "go.micro.srv.tickrecorder" 21 | }) 22 | } 23 | 24 | func handle() { 25 | log.Println("Tick received") 26 | } 27 | 28 | func main() { 29 | cmd.Init() 30 | log.Println("Starting up Tick Recorder...") 31 | addrs, err := net.InterfaceAddrs() 32 | if err != nil { 33 | log.Println(err) 34 | } 35 | log.Println("Interfaces:") 36 | for _, add := range addrs { 37 | log.Println(add.Network()+":", add.String()) 38 | } 39 | s := micro.NewService(opts) 40 | if err = s.Server().Subscribe( 41 | server.NewSubscriber( 42 | "go.micro.srv.TickRecorder.Tick", 43 | new(subscriber.Tick), 44 | ), 45 | ); err != nil { 46 | log.Fatal(err) 47 | } 48 | 49 | if err = s.Server().Subscribe( 50 | server.NewSubscriber( 51 | "go.micro.srv.TickRecorder.Trade", 52 | new(subscriber.Trade), 53 | ), 54 | ); err != nil { 55 | log.Fatal(err) 56 | } 57 | 58 | retry := time.NewTicker(1 * time.Second) 59 | RetryLoop: 60 | for { 61 | select { 62 | case <-retry.C: 63 | if err = s.Options().Broker.Connect(); err != nil { 64 | log.Error(err) 65 | } else { 66 | retry.Stop() 67 | break RetryLoop 68 | } 69 | } 70 | } 71 | 72 | if err = s.Run(); err != nil { 73 | log.Error(err) 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /services/BitstampTickSubscriber/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "log" 6 | "sync" 7 | "time" 8 | 9 | "github.com/micro/go-micro/cmd" 10 | _ "github.com/micro/go-plugins/broker/nats" 11 | _ "github.com/micro/go-plugins/registry/nats" 12 | _ "github.com/micro/go-plugins/transport/nats" 13 | 14 | proto "github.com/nii236/nii-finance/services/TickRecorder/proto" 15 | "golang.org/x/net/context" 16 | "google.golang.org/grpc/metadata" 17 | 18 | "github.com/micro/go-micro/client" 19 | pusher "github.com/pusher-community/pusher-websocket-go" 20 | ) 21 | 22 | //Example data: {"price": 469.0, "timestamp": "1464340140", "amount": 1.80891143, "type": 0, "id": 11226014} 23 | type trade struct { 24 | Price float64 `json:"price"` 25 | Timestamp int64 `json:"timestamp"` 26 | Amount float64 `json:"amount"` 27 | Type int `json:"type"` 28 | ID int `json:"id"` 29 | Broker string 30 | } 31 | 32 | func main() { 33 | cmd.Init() 34 | wg := &sync.WaitGroup{} 35 | p := pusher.New("de504dc5763aeef9ff52") 36 | 37 | wg.Add(1) 38 | ticker := p.Subscribe("live_trades") 39 | ticker.Bind("trade", publish) 40 | wg.Wait() 41 | 42 | } 43 | 44 | func publish(data interface{}) { 45 | log.Println("Publishing trade data...", data.(string)) 46 | 47 | t := &trade{} 48 | json.Unmarshal([]byte(data.(string)), t) 49 | t.Broker = "bitstamp" 50 | ctx := metadata.NewContext(context.Background(), metadata.MD{"X-User-Id": []string{"BitstampTickSubscriber"}}) 51 | now := time.Now().UnixNano() 52 | msg := client.NewPublication("go.micro.srv.TickRecorder.Trade", &proto.Trade{ 53 | Time: now, 54 | Price: t.Price, 55 | Amount: t.Amount, 56 | Broker: t.Broker, 57 | Type: int32(t.Type), 58 | Pair: "BTCUSD", 59 | }) 60 | if err := client.Publish(ctx, msg); err != nil { 61 | log.Println("publish err: ", err) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | nats: 4 | image: nats:0.8.0 5 | ports: 6 | - "4222:4222" 7 | - "8222:8222" 8 | bitstampticksubscriber: 9 | build: 10 | dockerfile: ./services/BitstampTickSubscriber/Dockerfile 11 | context: ./ 12 | command: --broker nats --registry nats --transport nats --broker_address nats:4222 --registry_address nats:4222 --transport_address nats:4222 13 | restart: always 14 | depends_on: 15 | - nats 16 | oandaticksubscriber: 17 | build: 18 | dockerfile: ./services/OandaTickSubscriber/Dockerfile 19 | context: ./ 20 | command: --broker nats --registry nats --transport nats --broker_address nats:4222 --registry_address nats:4222 --transport_address nats:4222 21 | restart: always 22 | depends_on: 23 | - nats 24 | tickrecorder: 25 | build: 26 | dockerfile: ./services/TickRecorder/Dockerfile 27 | context: ./ 28 | restart: always 29 | command: --broker nats --registry nats --transport nats --broker_address nats:4222 --registry_address nats:4222 --transport_address nats:4222 30 | depends_on: 31 | - nats 32 | java_consumer: 33 | build: ./services/javaconsumer/ 34 | restart: always 35 | command: -s nats://nats:4222 "go.micro.srv.TickRecorder.Trade" 36 | depends_on: 37 | - nats 38 | web: 39 | build: 40 | dockerfile: ./services/web/Dockerfile 41 | context: ./ 42 | command: --broker nats --registry nats --transport nats --broker_address nats:4222 --registry_address nats:4222 --transport_address nats:4222 web 43 | restart: always 44 | ports: 45 | - "8082:8082" 46 | depends_on: 47 | - nats 48 | sidecar: 49 | build: 50 | dockerfile: ./services/Sidecar/Dockerfile 51 | context: ./ 52 | command: --broker nats --registry nats --transport nats --broker_address nats:4222 --registry_address nats:4222 --transport_address nats:4222 sidecar 53 | restart: always 54 | ports: 55 | - "8081:8081" 56 | depends_on: 57 | - nats 58 | telegraf: 59 | build: ./services/telegraf/ 60 | depends_on: 61 | - nats 62 | - influx 63 | restart: always 64 | influx: 65 | image: influxdb:0.13-alpine 66 | ports: 67 | - "8083:8083" 68 | - "8086:8086" 69 | depends_on: 70 | - nats 71 | chronograf: 72 | image: chronograf:0.13 73 | environment: 74 | - CHRONOGRAF_BIND=0.0.0.0:10000 75 | ports: 76 | - "10000:10000" 77 | -------------------------------------------------------------------------------- /services/Python/test_pb2.py: -------------------------------------------------------------------------------- 1 | # Generated by the protocol buffer compiler. DO NOT EDIT! 2 | # source: test.proto 3 | 4 | import sys 5 | _b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) 6 | from google.protobuf import descriptor as _descriptor 7 | from google.protobuf import message as _message 8 | from google.protobuf import reflection as _reflection 9 | from google.protobuf import symbol_database as _symbol_database 10 | from google.protobuf import descriptor_pb2 11 | # @@protoc_insertion_point(imports) 12 | 13 | _sym_db = _symbol_database.Default() 14 | 15 | 16 | 17 | 18 | DESCRIPTOR = _descriptor.FileDescriptor( 19 | name='test.proto', 20 | package='openalgot', 21 | serialized_pb=_b('\n\ntest.proto\x12\topenalgot\"\'\n\x0bMessageData\x12\x0c\n\x04name\x18\x01 \x02(\t\x12\n\n\x02id\x18\x02 \x02(\x05') 22 | ) 23 | _sym_db.RegisterFileDescriptor(DESCRIPTOR) 24 | 25 | 26 | 27 | 28 | _MESSAGEDATA = _descriptor.Descriptor( 29 | name='MessageData', 30 | full_name='openalgot.MessageData', 31 | filename=None, 32 | file=DESCRIPTOR, 33 | containing_type=None, 34 | fields=[ 35 | _descriptor.FieldDescriptor( 36 | name='name', full_name='openalgot.MessageData.name', index=0, 37 | number=1, type=9, cpp_type=9, label=2, 38 | has_default_value=False, default_value=_b("").decode('utf-8'), 39 | message_type=None, enum_type=None, containing_type=None, 40 | is_extension=False, extension_scope=None, 41 | options=None), 42 | _descriptor.FieldDescriptor( 43 | name='id', full_name='openalgot.MessageData.id', index=1, 44 | number=2, type=5, cpp_type=1, label=2, 45 | has_default_value=False, default_value=0, 46 | message_type=None, enum_type=None, containing_type=None, 47 | is_extension=False, extension_scope=None, 48 | options=None), 49 | ], 50 | extensions=[ 51 | ], 52 | nested_types=[], 53 | enum_types=[ 54 | ], 55 | options=None, 56 | is_extendable=False, 57 | extension_ranges=[], 58 | oneofs=[ 59 | ], 60 | serialized_start=25, 61 | serialized_end=64, 62 | ) 63 | 64 | DESCRIPTOR.message_types_by_name['MessageData'] = _MESSAGEDATA 65 | 66 | MessageData = _reflection.GeneratedProtocolMessageType('MessageData', (_message.Message,), dict( 67 | DESCRIPTOR = _MESSAGEDATA, 68 | __module__ = 'test_pb2' 69 | # @@protoc_insertion_point(class_scope:openalgot.MessageData) 70 | )) 71 | _sym_db.RegisterMessage(MessageData) 72 | 73 | 74 | # @@protoc_insertion_point(module_scope) 75 | -------------------------------------------------------------------------------- /services/javaconsumer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | com.slack.openalgot 7 | javaconsumer 8 | 0.0.1-SNAPSHOT 9 | javaconsumer 10 | http://maven.apache.org 11 | 12 | UTF-8 13 | 1.8 14 | 15 | 16 | 17 | io.nats 18 | jnats 19 | 0.4.1 20 | 21 | 22 | 23 | com.fasterxml.jackson.core 24 | jackson-databind 25 | 2.2.3 26 | 27 | 28 | 29 | com.google.protobuf 30 | protobuf-java 31 | 3.0.0-beta-3 32 | 33 | 34 | 35 | junit 36 | junit 37 | 4.11 38 | test 39 | 40 | 41 | 42 | 43 | 44 | 45 | org.apache.maven.plugins 46 | maven-compiler-plugin 47 | 2.3.2 48 | 49 | ${jdk.version} 50 | ${jdk.version} 51 | 52 | 53 | 54 | org.apache.maven.plugins 55 | maven-shade-plugin 56 | 2.3 57 | 58 | 59 | 60 | package 61 | 62 | shade 63 | 64 | 65 | 66 | 68 | com.slack.openalgot.client.Subscriber 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Nii Finance Trading Swarm 2 | 3 | ![micro](micro.png) 4 | 5 | This repo is a complete demo of using [Micro](https://github.com/micro/micro) and [NATS](https://nats.io). Here is the relevant [blog post](https://oren.github.io/blog/micro.html). 6 | 7 | ## Installation 8 | 9 | ### Dependencies 10 | - [Go 1.6](https://golang.org/) 11 | - [Glide](https://glide.sh/) 12 | - [NATS](http://nats.io/) 13 | - [Docker](https://www.docker.com/) 14 | 15 | ### Spinup 16 | ``` 17 | $ go get -d github.com/nii236/nii-finance/... 18 | $ cd $GOPATH/src/github.com/nii236/nii-finance 19 | $ glide install 20 | $ docker build -t openalgotplatform_go:0.1 . 21 | $ docker-compose build 22 | $ docker-compose up 23 | ``` 24 | 25 | ## Usage 26 | 27 | In its current state, the swarm will: 28 | - Subscribe to the IB Gateway 29 | - Pull out USDJPY ticker data 30 | - Publish onto the NATS queue 31 | - Be received by the tickRecorder service 32 | - Write the data point into InfluxDB 33 | 34 | ## Things that you can do with this setup 35 | 36 | ### For OS X Users 37 | If you use OS X (like myself), you'll need to know what your docker IP is and substitute that for any `localhost` you see below. 38 | 39 | ``` 40 | docker-machine ip 41 | ``` 42 | 43 | Will give you your docker machine's IP. 44 | 45 | ### Micro Web Console 46 | 47 | http://localhost:8082 48 | 49 | ### NATS 50 | 51 | Install nats-top 52 | ``` 53 | go get github.com/nats-io/nats-top 54 | ``` 55 | 56 | Run nats-top 57 | ``` 58 | nats-top 59 | ``` 60 | 61 | ### InfluxDB 62 | 63 | Web console: http://localhost:8083 64 | Change the database at the top right to `openalgot` and run this query: `select * from trade` 65 | 66 | ### Chronograf 67 | 68 | Visualisations of InfluxDB are available using [chronograph](https://influxdata.com/time-series-platform/chronograf/), just visit [http://localhost:10000]() 69 | 70 | ## Contributing 71 | 72 | 1. Fork it! 73 | 2. Create your feature branch using `git flow feature start my-new-feature` 74 | 3. Commit your changes: `git commit -am 'Add some feature'` 75 | 4. Push to the branch: `git push origin my-new-feature` 76 | 5. Submit a pull request 77 | 78 | ### Ideas 79 | 80 | - A service that writes into MongoDB instead of InfluxDB 81 | - A service that calculates indicators based on drip feed data on NATS 82 | - A service that opens and closes trades for you 83 | - A service that pulls historical data from InfluxDB in a defined time resolution 84 | - Using go-micro's sidecar to allow writing algorithms in any language 85 | 86 | ## TODO 87 | - Use ENV vars for everything instead of hard coding strings 88 | - Make services more durable (when dependent services such as IB Gateway go down) 89 | -------------------------------------------------------------------------------- /services/telegraf/proto/telegraf.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. 2 | // source: github.com/nii236/nii-finance/services/telegraf/proto/telegraf.proto 3 | // DO NOT EDIT! 4 | 5 | /* 6 | Package go_srv_telegraf is a generated protocol buffer package. 7 | 8 | It is generated from these files: 9 | github.com/nii236/nii-finance/services/telegraf/proto/telegraf.proto 10 | 11 | It has these top-level messages: 12 | Telegraf 13 | */ 14 | package go_srv_telegraf 15 | 16 | import proto "github.com/golang/protobuf/proto" 17 | import fmt "fmt" 18 | import math "math" 19 | 20 | // Reference imports to suppress errors if they are not otherwise used. 21 | var _ = proto.Marshal 22 | var _ = fmt.Errorf 23 | var _ = math.Inf 24 | 25 | // This is a compile-time assertion to ensure that this generated file 26 | // is compatible with the proto package it is being compiled against. 27 | const _ = proto.ProtoPackageIsVersion1 28 | 29 | type Telegraf struct { 30 | Measurement string `protobuf:"bytes,1,opt,name=measurement" json:"measurement,omitempty"` 31 | Key string `protobuf:"bytes,2,opt,name=key" json:"key,omitempty"` 32 | Value string `protobuf:"bytes,3,opt,name=value" json:"value,omitempty"` 33 | Time string `protobuf:"bytes,4,opt,name=time" json:"time,omitempty"` 34 | } 35 | 36 | func (m *Telegraf) Reset() { *m = Telegraf{} } 37 | func (m *Telegraf) String() string { return proto.CompactTextString(m) } 38 | func (*Telegraf) ProtoMessage() {} 39 | func (*Telegraf) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } 40 | 41 | func init() { 42 | proto.RegisterType((*Telegraf)(nil), "go.srv.telegraf.Telegraf") 43 | } 44 | 45 | var fileDescriptor0 = []byte{ 46 | // 163 bytes of a gzipped FileDescriptorProto 47 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x4c, 0xcd, 0xbf, 0x0a, 0xc2, 0x30, 48 | 0x10, 0xc7, 0x71, 0x6a, 0xab, 0x68, 0xaa, 0x08, 0x75, 0xc9, 0x28, 0x4e, 0x2e, 0x4d, 0x06, 0x9f, 49 | 0xc2, 0xdd, 0x59, 0x48, 0xcb, 0xaf, 0xa5, 0x98, 0xf4, 0xca, 0x25, 0x2d, 0xf8, 0xf6, 0xd2, 0xe0, 50 | 0xbf, 0xed, 0xfb, 0xb9, 0x3b, 0x38, 0x71, 0xa7, 0x01, 0x7d, 0x69, 0x6c, 0x4b, 0x41, 0x79, 0xf0, 51 | 0x84, 0x0a, 0x60, 0x55, 0x93, 0xd3, 0xbf, 0xc5, 0x5f, 0x96, 0x83, 0x35, 0xa1, 0x21, 0x76, 0x7a, 52 | 0x3e, 0xee, 0x6a, 0x78, 0x1d, 0x60, 0xd1, 0xb2, 0x69, 0xf4, 0xc0, 0x14, 0xe8, 0x4b, 0x15, 0x59, 53 | 0xec, 0x5b, 0x52, 0x9e, 0x27, 0xf5, 0x19, 0x9f, 0xae, 0x62, 0x7d, 0x7b, 0x77, 0x71, 0x10, 0xb9, 54 | 0x83, 0xf1, 0x23, 0xc3, 0xa1, 0x0f, 0x32, 0x39, 0x26, 0xe7, 0x4d, 0x91, 0x8b, 0xf4, 0x81, 0xa7, 55 | 0x5c, 0x44, 0xec, 0xc4, 0x72, 0x32, 0x76, 0x84, 0x4c, 0x23, 0xb7, 0x22, 0x0b, 0x9d, 0x83, 0xcc, 56 | 0x66, 0x55, 0xab, 0xf8, 0xe2, 0xf2, 0x0a, 0x00, 0x00, 0xff, 0xff, 0xfb, 0x5f, 0x05, 0x3d, 0xc4, 57 | 0x00, 0x00, 0x00, 58 | } 59 | -------------------------------------------------------------------------------- /services/Python/yahoo_ticker.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Spyder Editor 4 | 5 | This is a temporary script file. 6 | """ 7 | 8 | # pip install websocket-client 9 | # pip install protobuf 10 | # pandas 11 | # numpy 12 | 13 | 14 | 15 | #import pandas.io.data as web 16 | #import websocket 17 | #import numpy as np 18 | #import requests 19 | 20 | 21 | import test_pb2 22 | 23 | 24 | 25 | from werkzeug.wrappers import Request, Response 26 | from werkzeug.serving import run_simple 27 | #from jsonrpc import JSONRPCResponseManager, dispatcher 28 | 29 | import uuid 30 | import requests 31 | import json 32 | 33 | #// units ns|us|ms|s|m|h 34 | #// http://127.0.0.1:8081/registry?ttl=10s 35 | 36 | payload={"Name": "foo.bar", 37 | "Nodes": [{ 38 | "Port": 9091, 39 | "Address": "127.0.0.1", 40 | "Id": "foo.bar-017da09a-734f-11e5-8136-68a86d0d36b6" 41 | }]} 42 | 43 | def register(): 44 | register_uri = "http://192.168.99.100:8081/registry" 45 | service = "go.micro.srv.yahoo" 46 | headers = {'content-type': 'application/json'} 47 | payload = { 48 | "name": service, 49 | "nodes": [{ 50 | "id": service + "-" + str(uuid.uuid4()), 51 | "address": "192.168.0.7", 52 | "port": 4000, 53 | }], 54 | } 55 | requests.post(register_uri, data=json.dumps(payload), headers=headers) 56 | 57 | @Request.application 58 | def application(request): 59 | # Dispatcher is dictionary {: callable} 60 | 61 | # dispatcher["Say.Hello"] = lambda s: "hello " + s["name"] 62 | 63 | msg = test_pb2.MessageData() 64 | msg.ParseFromString(request.data) 65 | 66 | #response = JSONRPCResponseManager.handle( 67 | # request.data, dispatcher) 68 | #return Response(response.json, mimetype='application/json') 69 | 70 | return Response(msg.SerializeToString(), mimetype='application/octet-stream') 71 | 72 | 73 | if __name__ == '__main__': 74 | print "registering service" 75 | register() 76 | print "running service" 77 | run_simple('localhost', 4000, application) 78 | 79 | 80 | 81 | 82 | #r = requests.post('http://192.168.99.100:8081', json=payload) 83 | 84 | 85 | #r = requests.get('http://192.168.99.100:8081/registry') 86 | #print r.status_code 87 | #print r.headers['content-type'] 88 | 89 | #r = requests.get('http://192.168.99.100:8081/registry') 90 | #print r.text 91 | 92 | 93 | #ws = websocket.WebSocket() 94 | #ws.connect("ws://192.168.99.100:8081/broker?topic=go.micro.srv.BitstampRecorder") 95 | #ws.connect("ws://192.168.99.100:8081/broker?topic=go.micro.srv.TickRecorder") 96 | #print ws.recv() 97 | 98 | #ws://192.168.0.12:8081/broker?topic=go.micro.srv.TickRecorder 99 | 100 | 101 | #foo = np.random.randint(0, 10, (4,5,6)) 102 | 103 | #print foo 104 | 105 | #print foo.mean(axis=0) 106 | 107 | 108 | #DAX = web.DataReader(name='GOOG', data_source='yahoo', start='2000-1-1') 109 | #DAX.info() 110 | #DAX['Close'].plot() 111 | 112 | #print DAX.tail() 113 | -------------------------------------------------------------------------------- /glide.lock: -------------------------------------------------------------------------------- 1 | hash: 26ac752e9a9d63bb97be02a40d03dfdd009a10d9843657795d6dd35cc567ea2d 2 | updated: 2016-06-27T10:43:28.584654454+08:00 3 | imports: 4 | - name: github.com/eclipse/paho.mqtt.golang 5 | version: 45f9b18f4864c81d49c3ed01e5faec9eeb05de31 6 | subpackages: 7 | - packets 8 | - name: github.com/golang/protobuf 9 | version: 0c1f6d65b5a189c2250d10e71a5506f06f9fa0a0 10 | subpackages: 11 | - proto 12 | - name: github.com/gorilla/context 13 | version: aed02d124ae4a0e94fea4541c8effd05bf0c8296 14 | - name: github.com/gorilla/handlers 15 | version: 66e6c6f01d8da976ee113437745ca029c2b585a6 16 | - name: github.com/gorilla/mux 17 | version: 9fa818a44c2bf1396a17f9d5a3c0f6dd39d2ff8e 18 | - name: github.com/gorilla/websocket 19 | version: a68708917c6a4f06314ab4e52493cc61359c9d42 20 | - name: github.com/hashicorp/consul 21 | version: 09cfda47ed103910a8e1af76fa378a7e6acd5310 22 | subpackages: 23 | - api 24 | - watch 25 | - name: github.com/hashicorp/go-cleanhttp 26 | version: 875fb671b3ddc66f8e2f0acc33829c8cb989a38d 27 | - name: github.com/hashicorp/serf 28 | version: 6c4672d66fc6312ddde18399262943e21175d831 29 | subpackages: 30 | - coordinate 31 | - serf 32 | - name: github.com/micro/cli 33 | version: 3d2263bb092286dde294a31049c92665f8373820 34 | - name: github.com/micro/go-micro 35 | version: 7968a8eb6db0d96de0fcacd87a6730ac4f8f2753 36 | subpackages: 37 | - client 38 | - cmd 39 | - metadata 40 | - server 41 | - broker 42 | - codec 43 | - codec/jsonrpc 44 | - codec/protorpc 45 | - errors 46 | - registry 47 | - selector 48 | - transport 49 | - broker/http 50 | - broker/mqtt 51 | - registry/consul 52 | - registry/mdns 53 | - selector/cache 54 | - transport/http 55 | - server/debug 56 | - server/debug/proto 57 | - name: github.com/micro/go-plugins 58 | version: a7849c8b4c7c98be7a9c71ae7381906a77b5c357 59 | subpackages: 60 | - broker/nats 61 | - registry/nats 62 | - transport/nats 63 | - name: github.com/micro/mdns 64 | version: d37bec73c909e7cb2930877f877e63dde9998d25 65 | - name: github.com/micro/micro 66 | version: 8f9177c9239f57a3d9b8b8a88e7c8ed304bb3d0a 67 | subpackages: 68 | - car 69 | - web 70 | - internal/handler 71 | - internal/helper 72 | - internal/server 73 | - internal/stats 74 | - plugin 75 | - name: github.com/micro/misc 76 | version: 677e2a0beb40a3dd7418548fe0cdc661e2922859 77 | subpackages: 78 | - lib/tls 79 | - name: github.com/miekg/dns 80 | version: 75e6e86cc601825c5dbcd4e0c209eab180997cd7 81 | - name: github.com/mitchellh/hashstructure 82 | version: b098c52ef6beab8cd82bc4a32422cf54b890e8fa 83 | - name: github.com/nats-io/nats 84 | version: 2c1f69d5c7719e30736c024a3ab43430cc7d8ee2 85 | subpackages: 86 | - encoders/builtin 87 | - name: github.com/nats-io/nuid 88 | version: a5152d67cf63cbfb5d992a395458722a45194715 89 | - name: github.com/nii236/nii-finance 90 | version: 3f4f5dd64b230344e3eea5f6db0965f5f811b93d 91 | subpackages: 92 | - vendor/github.com/serenize/snaker 93 | - services/TickRecorder/proto 94 | - services/TickRecorder/subscriber 95 | - services/TickRecorder/publisher 96 | - name: github.com/pborman/uuid 97 | version: c55201b036063326c5b1b89ccfe45a184973d073 98 | - name: github.com/pusher-community/pusher-websocket-go 99 | version: 8872644df4d121342338d3296646ed78269d8a4b 100 | - name: github.com/serenize/snaker 101 | version: 8824b61eca66d308fcb2d515287d3d7a28dba8d6 102 | - name: github.com/Sirupsen/logrus 103 | version: f3cfb454f4c209e6668c95216c4744b8fddb2356 104 | - name: golang.org/x/net 105 | version: bc3663df0ac92f928d419e31e0d2af22e683a5a2 106 | subpackages: 107 | - context 108 | - websocket 109 | - ipv4 110 | - ipv6 111 | - bpf 112 | - internal/iana 113 | - name: golang.org/x/sys 114 | version: 62bee037599929a6e9146f29d10dd5208c43507d 115 | subpackages: 116 | - unix 117 | - name: google.golang.org/grpc 118 | version: 69420784d409f9ff88b424436f52001b26144e20 119 | subpackages: 120 | - metadata 121 | devImports: [] 122 | -------------------------------------------------------------------------------- /services/TickRecorder/proto/tick.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. 2 | // source: github.com/nii236/nii-finance/services/TickRecorder/proto/tick.proto 3 | // DO NOT EDIT! 4 | 5 | /* 6 | Package go_srv_TickRecorder is a generated protocol buffer package. 7 | 8 | It is generated from these files: 9 | github.com/nii236/nii-finance/services/TickRecorder/proto/tick.proto 10 | 11 | It has these top-level messages: 12 | Tick 13 | Trade 14 | */ 15 | package go_srv_TickRecorder 16 | 17 | import proto "github.com/golang/protobuf/proto" 18 | import fmt "fmt" 19 | import math "math" 20 | 21 | // Reference imports to suppress errors if they are not otherwise used. 22 | var _ = proto.Marshal 23 | var _ = fmt.Errorf 24 | var _ = math.Inf 25 | 26 | // This is a compile-time assertion to ensure that this generated file 27 | // is compatible with the proto package it is being compiled against. 28 | const _ = proto.ProtoPackageIsVersion1 29 | 30 | type Tick struct { 31 | Time int64 `protobuf:"varint,1,opt,name=time" json:"time,omitempty"` 32 | Bid float64 `protobuf:"fixed64,2,opt,name=bid" json:"bid,omitempty"` 33 | Ask float64 `protobuf:"fixed64,3,opt,name=ask" json:"ask,omitempty"` 34 | Last float64 `protobuf:"fixed64,4,opt,name=last" json:"last,omitempty"` 35 | Pair string `protobuf:"bytes,5,opt,name=pair" json:"pair,omitempty"` 36 | Broker string `protobuf:"bytes,6,opt,name=broker" json:"broker,omitempty"` 37 | } 38 | 39 | func (m *Tick) Reset() { *m = Tick{} } 40 | func (m *Tick) String() string { return proto.CompactTextString(m) } 41 | func (*Tick) ProtoMessage() {} 42 | func (*Tick) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } 43 | 44 | type Trade struct { 45 | Time int64 `protobuf:"varint,1,opt,name=time" json:"time,omitempty"` 46 | Price float64 `protobuf:"fixed64,2,opt,name=price" json:"price,omitempty"` 47 | Amount float64 `protobuf:"fixed64,3,opt,name=amount" json:"amount,omitempty"` 48 | Type int32 `protobuf:"varint,4,opt,name=type" json:"type,omitempty"` 49 | Broker string `protobuf:"bytes,6,opt,name=broker" json:"broker,omitempty"` 50 | Pair string `protobuf:"bytes,7,opt,name=pair" json:"pair,omitempty"` 51 | } 52 | 53 | func (m *Trade) Reset() { *m = Trade{} } 54 | func (m *Trade) String() string { return proto.CompactTextString(m) } 55 | func (*Trade) ProtoMessage() {} 56 | func (*Trade) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } 57 | 58 | func init() { 59 | proto.RegisterType((*Tick)(nil), "go.srv.TickRecorder.Tick") 60 | proto.RegisterType((*Trade)(nil), "go.srv.TickRecorder.Trade") 61 | } 62 | 63 | var fileDescriptor0 = []byte{ 64 | // 216 bytes of a gzipped FileDescriptorProto 65 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x5c, 0x8f, 0xbd, 0x4e, 0x03, 0x31, 66 | 0x10, 0x84, 0x75, 0xdc, 0x0f, 0xc2, 0xfc, 0x14, 0xa6, 0x71, 0x89, 0x52, 0xd1, 0xc4, 0x2e, 0x78, 67 | 0x13, 0x94, 0x8a, 0x02, 0x61, 0xfb, 0x96, 0xc8, 0xba, 0x73, 0xd6, 0x5a, 0x2f, 0x91, 0x78, 0x7b, 68 | 0x6c, 0x0b, 0x48, 0x94, 0x6e, 0x3e, 0x7b, 0x76, 0x66, 0x57, 0xbc, 0x63, 0x82, 0xc3, 0xd6, 0xae, 69 | 0x7b, 0x64, 0x9d, 0x81, 0x8e, 0xe0, 0x00, 0x48, 0x7b, 0x8c, 0xe6, 0xf4, 0x71, 0x26, 0xb7, 0x69, 70 | 0xb5, 0xfc, 0x89, 0x14, 0x4d, 0x35, 0x07, 0x0f, 0xd9, 0xec, 0x82, 0x5f, 0x5e, 0xc1, 0x23, 0xcd, 71 | 0x40, 0x26, 0x11, 0x32, 0x1a, 0x2e, 0x4f, 0xba, 0x49, 0xf9, 0xb8, 0x47, 0x9d, 0xe9, 0xa8, 0xcf, 72 | 0x5d, 0x9b, 0x37, 0x31, 0x54, 0x96, 0x77, 0x62, 0xe0, 0x10, 0x41, 0x75, 0x4f, 0xdd, 0x73, 0x2f, 73 | 0x6f, 0x45, 0xef, 0xc2, 0xac, 0xae, 0x0a, 0x74, 0x15, 0x6c, 0x5e, 0x54, 0xdf, 0xa0, 0xf8, 0x56, 74 | 0x9b, 0x59, 0x0d, 0x7f, 0x94, 0x6c, 0x20, 0x35, 0x16, 0xba, 0x91, 0x0f, 0x62, 0x72, 0x84, 0x0b, 75 | 0x90, 0x9a, 0x2a, 0x6f, 0x3e, 0xc4, 0xb8, 0x23, 0x3b, 0xc3, 0x45, 0xf8, 0xbd, 0x18, 0x13, 0x95, 76 | 0x7d, 0x7f, 0xe3, 0xcb, 0x94, 0x8d, 0xf8, 0x75, 0xe0, 0x53, 0x03, 0x7f, 0x27, 0x68, 0x0d, 0xe3, 77 | 0x65, 0xe6, 0x7f, 0xe3, 0x75, 0x25, 0x37, 0xb5, 0xcb, 0x5e, 0x7e, 0x02, 0x00, 0x00, 0xff, 0xff, 78 | 0x89, 0xed, 0xa5, 0x26, 0x3b, 0x01, 0x00, 0x00, 79 | } 80 | -------------------------------------------------------------------------------- /services/telegraf/telegraf.conf: -------------------------------------------------------------------------------- 1 | [global_tags] 2 | ## Environment variables can be used as tags, and throughout the config file 3 | # user = "$USER" 4 | # Configuration for telegraf agent 5 | [agent] 6 | ## Default data collection interval for all inputs 7 | interval = "5s" 8 | ## Rounds collection interval to 'interval' 9 | ## ie, if interval="10s" then always collect on :00, :10, :20, etc. 10 | round_interval = true 11 | 12 | ## Telegraf will send metrics to outputs in batches of at 13 | ## most metric_batch_size metrics. 14 | metric_batch_size = 1000 15 | ## For failed writes, telegraf will cache metric_buffer_limit metrics for each 16 | ## output, and will flush this buffer on a successful write. Oldest metrics 17 | ## are dropped first when this buffer fills. 18 | metric_buffer_limit = 10000 19 | 20 | ## Collection jitter is used to jitter the collection by a random amount. 21 | ## Each plugin will sleep for a random time within jitter before collecting. 22 | ## This can be used to avoid many plugins querying things like sysfs at the 23 | ## same time, which can have a measurable effect on the system. 24 | collection_jitter = "0s" 25 | 26 | ## Default flushing interval for all outputs. You shouldn't set this below 27 | ## interval. Maximum flush_interval will be flush_interval + flush_jitter 28 | flush_interval = "10s" 29 | ## Jitter the flush interval by a random amount. This is primarily to avoid 30 | ## large write spikes for users running a large number of telegraf instances. 31 | ## ie, a jitter of 5s and interval 10s means flushes will happen every 10-15s 32 | flush_jitter = "0s" 33 | 34 | ## Run telegraf in debug mode 35 | debug = false 36 | ## Run telegraf in quiet mode 37 | quiet = false 38 | ## Override default hostname, if empty use os.Hostname() 39 | hostname = "" 40 | ## If set to true, do no set the "host" tag in the telegraf agent. 41 | omit_hostname = false 42 | 43 | 44 | ############################################################################### 45 | # OUTPUT PLUGINS # 46 | ############################################################################### 47 | 48 | # Configuration for influxdb server to send metrics to 49 | [[outputs.influxdb]] 50 | ## The full HTTP or UDP endpoint URL for your InfluxDB instance. 51 | ## Multiple urls can be specified as part of the same cluster, 52 | ## this means that only ONE of the urls will be written to each interval. 53 | # urls = ["udp://localhost:8089"] # UDP endpoint example 54 | urls = ["http://influx:8086"] # required 55 | ## The target database for metrics (telegraf will create it if not exists). 56 | database = "openalgot" # required 57 | ## Precision of writes, valid values are "ns", "us" (or "µs"), "ms", "s", "m", "h". 58 | ## note: using "s" precision greatly improves InfluxDB compression. 59 | precision = "ns" 60 | 61 | ## Retention policy to write to. 62 | retention_policy = "default" 63 | ## Write consistency (clusters only), can be: "any", "one", "quorom", "all" 64 | write_consistency = "any" 65 | 66 | ## Write timeout (for the InfluxDB client), formatted as a string. 67 | ## If not provided, will default to 5s. 0s means no timeout (not recommended). 68 | timeout = "5s" 69 | 70 | ############################################################################### 71 | # SERVICE INPUT PLUGINS # 72 | ############################################################################### 73 | 74 | # # Read metrics from NATS subject(s) 75 | [[inputs.nats_consumer]] 76 | ## urls of NATS servers 77 | servers = ["nats://nats:4222"] 78 | ## Use Transport Layer Security 79 | secure = false 80 | ## subject(s) to consume 81 | subjects = ["go.micro.telegraf"] 82 | ## name a queue group 83 | queue_group = "telegraf_consumers" 84 | 85 | ## Data format to consume. 86 | ## Each data format has it's own unique set of configuration options, read 87 | ## more about them here: 88 | ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md 89 | data_format = "influx" 90 | -------------------------------------------------------------------------------- /services/javaconsumer/src/main/java/com/slack/openalgot/client/Subscriber.java: -------------------------------------------------------------------------------- 1 | package com.slack.openalgot.client; 2 | 3 | import java.io.IOException; 4 | import java.time.LocalDateTime; 5 | import java.util.ArrayList; 6 | import java.util.Arrays; 7 | import java.util.Base64; 8 | import java.util.Iterator; 9 | import java.util.List; 10 | import java.util.concurrent.TimeoutException; 11 | import java.util.concurrent.atomic.AtomicInteger; 12 | 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | import com.fasterxml.jackson.databind.ObjectMapper; 17 | import com.slack.openalgot.MarketEventProtos.Trade; 18 | 19 | import io.nats.client.Connection; 20 | import io.nats.client.ConnectionFactory; 21 | import io.nats.client.Subscription; 22 | 23 | public class Subscriber { 24 | static final Logger log = LoggerFactory.getLogger(Subscriber.class); 25 | 26 | private String url = ConnectionFactory.DEFAULT_URL; 27 | private String subject; 28 | private String qgroup; 29 | 30 | static final String usageString = "\nUsage: java Subscriber \n\nOptions:\n" 31 | + " -s, --server NATS server URL(default: " 32 | + ConnectionFactory.DEFAULT_URL + ")\n" 33 | + " -q, --qgroup Queue group\n"; 34 | 35 | Subscriber(String[] args) { 36 | parseArgs(args); 37 | if (subject == null) { 38 | usage(); 39 | } 40 | } 41 | 42 | void usage() { 43 | System.err.println(usageString); 44 | System.exit(-1); 45 | } 46 | 47 | void run() throws IOException, TimeoutException { 48 | ConnectionFactory cf = new ConnectionFactory(url); 49 | 50 | try (final Connection nc = cf.createConnection()) { 51 | // System.out.println("Connected successfully to " + cf.getNatsUrl()); 52 | AtomicInteger count = new AtomicInteger(); 53 | try (final Subscription sub = nc.subscribe(subject, qgroup, m -> { 54 | System.out.println("[#"+count.incrementAndGet()+"] At: "+LocalDateTime.now().toString()); 55 | try { 56 | byte[] jsonData = m.getData(); 57 | ObjectMapper objectMapper = new ObjectMapper(); 58 | HeaderAndBody hb = objectMapper.readValue(jsonData, HeaderAndBody.class); 59 | //System.out.println(hb.toString()); 60 | byte[] decoded = Base64.getDecoder().decode(hb.getBody().getBytes()); 61 | Trade trade = Trade.parseFrom(decoded); 62 | System.out.println("Time: "+trade.getTime()+" Price: "+trade.getPrice()+" Amount: "+trade.getAmount()+" Type: "+trade.getType()); 63 | 64 | } catch (Exception e) { 65 | // TODO Auto-generated catch block 66 | e.printStackTrace(); 67 | } 68 | 69 | })) { 70 | System.out.printf("Listening on [%s]\n", subject); 71 | Runtime.getRuntime().addShutdownHook(new Thread(() -> { 72 | System.err.println("\nCaught CTRL-C, shutting down gracefully...\n"); 73 | try { 74 | sub.unsubscribe(); 75 | } catch (IOException e) { 76 | log.error("Problem unsubscribing", e); 77 | } 78 | nc.close(); 79 | })); 80 | while (true) { 81 | // loop forever 82 | } 83 | } 84 | } 85 | } 86 | 87 | private void parseArgs(String[] args) { 88 | if (args == null || args.length < 1) { 89 | usage(); 90 | return; 91 | } 92 | 93 | List argList = new ArrayList(Arrays.asList(args)); 94 | 95 | // The last arg should be subject 96 | // get the subject and remove it from args 97 | subject = argList.remove(argList.size() - 1); 98 | 99 | // Anything left is flags + args 100 | Iterator it = argList.iterator(); 101 | while (it.hasNext()) { 102 | String arg = it.next(); 103 | switch (arg) { 104 | case "-s": 105 | case "--server": 106 | if (!it.hasNext()) { 107 | usage(); 108 | } 109 | it.remove(); 110 | url = it.next(); 111 | it.remove(); 112 | continue; 113 | case "-q": 114 | case "--qgroup": 115 | if (!it.hasNext()) { 116 | usage(); 117 | } 118 | it.remove(); 119 | qgroup = it.next(); 120 | it.remove(); 121 | continue; 122 | default: 123 | System.err.printf("Unexpected token: '%s'\n", arg); 124 | usage(); 125 | break; 126 | } 127 | } 128 | } 129 | 130 | /** 131 | * Subscribes to a subject. 132 | * 133 | * @param args the subject, cluster info, and subscription options 134 | */ 135 | public static void main(String[] args) { 136 | try { 137 | new Subscriber(args).run(); 138 | } catch (IOException | TimeoutException e) { 139 | log.error("Couldn't create Subscriber", e); 140 | System.exit(-1); 141 | } 142 | System.exit(0); 143 | } 144 | } -------------------------------------------------------------------------------- /services/javaconsumer/src/main/java/com/slack/openalgot/MarketEventProtos.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: tick.proto 3 | 4 | package com.slack.openalgot; 5 | 6 | public final class MarketEventProtos { 7 | private MarketEventProtos() {} 8 | public static void registerAllExtensions( 9 | com.google.protobuf.ExtensionRegistry registry) { 10 | } 11 | public interface TickOrBuilder extends 12 | // @@protoc_insertion_point(interface_extends:go.srv.TickRecorder.Tick) 13 | com.google.protobuf.MessageOrBuilder { 14 | 15 | /** 16 | * optional int64 time = 1; 17 | */ 18 | long getTime(); 19 | 20 | /** 21 | * optional double bid = 2; 22 | */ 23 | double getBid(); 24 | 25 | /** 26 | * optional double ask = 3; 27 | */ 28 | double getAsk(); 29 | 30 | /** 31 | * optional double last = 4; 32 | */ 33 | double getLast(); 34 | 35 | /** 36 | * optional string pair = 5; 37 | */ 38 | java.lang.String getPair(); 39 | /** 40 | * optional string pair = 5; 41 | */ 42 | com.google.protobuf.ByteString 43 | getPairBytes(); 44 | 45 | /** 46 | * optional string broker = 6; 47 | */ 48 | java.lang.String getBroker(); 49 | /** 50 | * optional string broker = 6; 51 | */ 52 | com.google.protobuf.ByteString 53 | getBrokerBytes(); 54 | } 55 | /** 56 | * Protobuf type {@code go.srv.TickRecorder.Tick} 57 | */ 58 | public static final class Tick extends 59 | com.google.protobuf.GeneratedMessage implements 60 | // @@protoc_insertion_point(message_implements:go.srv.TickRecorder.Tick) 61 | TickOrBuilder { 62 | // Use Tick.newBuilder() to construct. 63 | private Tick(com.google.protobuf.GeneratedMessage.Builder builder) { 64 | super(builder); 65 | } 66 | private Tick() { 67 | time_ = 0L; 68 | bid_ = 0D; 69 | ask_ = 0D; 70 | last_ = 0D; 71 | pair_ = ""; 72 | broker_ = ""; 73 | } 74 | 75 | @java.lang.Override 76 | public final com.google.protobuf.UnknownFieldSet 77 | getUnknownFields() { 78 | return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); 79 | } 80 | private Tick( 81 | com.google.protobuf.CodedInputStream input, 82 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 83 | throws com.google.protobuf.InvalidProtocolBufferException { 84 | this(); 85 | int mutable_bitField0_ = 0; 86 | try { 87 | boolean done = false; 88 | while (!done) { 89 | int tag = input.readTag(); 90 | switch (tag) { 91 | case 0: 92 | done = true; 93 | break; 94 | default: { 95 | if (!input.skipField(tag)) { 96 | done = true; 97 | } 98 | break; 99 | } 100 | case 8: { 101 | 102 | time_ = input.readInt64(); 103 | break; 104 | } 105 | case 17: { 106 | 107 | bid_ = input.readDouble(); 108 | break; 109 | } 110 | case 25: { 111 | 112 | ask_ = input.readDouble(); 113 | break; 114 | } 115 | case 33: { 116 | 117 | last_ = input.readDouble(); 118 | break; 119 | } 120 | case 42: { 121 | java.lang.String s = input.readStringRequireUtf8(); 122 | 123 | pair_ = s; 124 | break; 125 | } 126 | case 50: { 127 | java.lang.String s = input.readStringRequireUtf8(); 128 | 129 | broker_ = s; 130 | break; 131 | } 132 | } 133 | } 134 | } catch (com.google.protobuf.InvalidProtocolBufferException e) { 135 | throw e.setUnfinishedMessage(this); 136 | } catch (java.io.IOException e) { 137 | throw new com.google.protobuf.InvalidProtocolBufferException( 138 | e).setUnfinishedMessage(this); 139 | } finally { 140 | makeExtensionsImmutable(); 141 | } 142 | } 143 | public static final com.google.protobuf.Descriptors.Descriptor 144 | getDescriptor() { 145 | return com.slack.openalgot.MarketEventProtos.internal_static_go_srv_TickRecorder_Tick_descriptor; 146 | } 147 | 148 | protected com.google.protobuf.GeneratedMessage.FieldAccessorTable 149 | internalGetFieldAccessorTable() { 150 | return com.slack.openalgot.MarketEventProtos.internal_static_go_srv_TickRecorder_Tick_fieldAccessorTable 151 | .ensureFieldAccessorsInitialized( 152 | com.slack.openalgot.MarketEventProtos.Tick.class, com.slack.openalgot.MarketEventProtos.Tick.Builder.class); 153 | } 154 | 155 | public static final int TIME_FIELD_NUMBER = 1; 156 | private long time_; 157 | /** 158 | * optional int64 time = 1; 159 | */ 160 | public long getTime() { 161 | return time_; 162 | } 163 | 164 | public static final int BID_FIELD_NUMBER = 2; 165 | private double bid_; 166 | /** 167 | * optional double bid = 2; 168 | */ 169 | public double getBid() { 170 | return bid_; 171 | } 172 | 173 | public static final int ASK_FIELD_NUMBER = 3; 174 | private double ask_; 175 | /** 176 | * optional double ask = 3; 177 | */ 178 | public double getAsk() { 179 | return ask_; 180 | } 181 | 182 | public static final int LAST_FIELD_NUMBER = 4; 183 | private double last_; 184 | /** 185 | * optional double last = 4; 186 | */ 187 | public double getLast() { 188 | return last_; 189 | } 190 | 191 | public static final int PAIR_FIELD_NUMBER = 5; 192 | private volatile java.lang.Object pair_; 193 | /** 194 | * optional string pair = 5; 195 | */ 196 | public java.lang.String getPair() { 197 | java.lang.Object ref = pair_; 198 | if (ref instanceof java.lang.String) { 199 | return (java.lang.String) ref; 200 | } else { 201 | com.google.protobuf.ByteString bs = 202 | (com.google.protobuf.ByteString) ref; 203 | java.lang.String s = bs.toStringUtf8(); 204 | pair_ = s; 205 | return s; 206 | } 207 | } 208 | /** 209 | * optional string pair = 5; 210 | */ 211 | public com.google.protobuf.ByteString 212 | getPairBytes() { 213 | java.lang.Object ref = pair_; 214 | if (ref instanceof java.lang.String) { 215 | com.google.protobuf.ByteString b = 216 | com.google.protobuf.ByteString.copyFromUtf8( 217 | (java.lang.String) ref); 218 | pair_ = b; 219 | return b; 220 | } else { 221 | return (com.google.protobuf.ByteString) ref; 222 | } 223 | } 224 | 225 | public static final int BROKER_FIELD_NUMBER = 6; 226 | private volatile java.lang.Object broker_; 227 | /** 228 | * optional string broker = 6; 229 | */ 230 | public java.lang.String getBroker() { 231 | java.lang.Object ref = broker_; 232 | if (ref instanceof java.lang.String) { 233 | return (java.lang.String) ref; 234 | } else { 235 | com.google.protobuf.ByteString bs = 236 | (com.google.protobuf.ByteString) ref; 237 | java.lang.String s = bs.toStringUtf8(); 238 | broker_ = s; 239 | return s; 240 | } 241 | } 242 | /** 243 | * optional string broker = 6; 244 | */ 245 | public com.google.protobuf.ByteString 246 | getBrokerBytes() { 247 | java.lang.Object ref = broker_; 248 | if (ref instanceof java.lang.String) { 249 | com.google.protobuf.ByteString b = 250 | com.google.protobuf.ByteString.copyFromUtf8( 251 | (java.lang.String) ref); 252 | broker_ = b; 253 | return b; 254 | } else { 255 | return (com.google.protobuf.ByteString) ref; 256 | } 257 | } 258 | 259 | private byte memoizedIsInitialized = -1; 260 | public final boolean isInitialized() { 261 | byte isInitialized = memoizedIsInitialized; 262 | if (isInitialized == 1) return true; 263 | if (isInitialized == 0) return false; 264 | 265 | memoizedIsInitialized = 1; 266 | return true; 267 | } 268 | 269 | public void writeTo(com.google.protobuf.CodedOutputStream output) 270 | throws java.io.IOException { 271 | if (time_ != 0L) { 272 | output.writeInt64(1, time_); 273 | } 274 | if (bid_ != 0D) { 275 | output.writeDouble(2, bid_); 276 | } 277 | if (ask_ != 0D) { 278 | output.writeDouble(3, ask_); 279 | } 280 | if (last_ != 0D) { 281 | output.writeDouble(4, last_); 282 | } 283 | if (!getPairBytes().isEmpty()) { 284 | com.google.protobuf.GeneratedMessage.writeString(output, 5, pair_); 285 | } 286 | if (!getBrokerBytes().isEmpty()) { 287 | com.google.protobuf.GeneratedMessage.writeString(output, 6, broker_); 288 | } 289 | } 290 | 291 | public int getSerializedSize() { 292 | int size = memoizedSize; 293 | if (size != -1) return size; 294 | 295 | size = 0; 296 | if (time_ != 0L) { 297 | size += com.google.protobuf.CodedOutputStream 298 | .computeInt64Size(1, time_); 299 | } 300 | if (bid_ != 0D) { 301 | size += com.google.protobuf.CodedOutputStream 302 | .computeDoubleSize(2, bid_); 303 | } 304 | if (ask_ != 0D) { 305 | size += com.google.protobuf.CodedOutputStream 306 | .computeDoubleSize(3, ask_); 307 | } 308 | if (last_ != 0D) { 309 | size += com.google.protobuf.CodedOutputStream 310 | .computeDoubleSize(4, last_); 311 | } 312 | if (!getPairBytes().isEmpty()) { 313 | size += com.google.protobuf.GeneratedMessage.computeStringSize(5, pair_); 314 | } 315 | if (!getBrokerBytes().isEmpty()) { 316 | size += com.google.protobuf.GeneratedMessage.computeStringSize(6, broker_); 317 | } 318 | memoizedSize = size; 319 | return size; 320 | } 321 | 322 | private static final long serialVersionUID = 0L; 323 | public static com.slack.openalgot.MarketEventProtos.Tick parseFrom( 324 | com.google.protobuf.ByteString data) 325 | throws com.google.protobuf.InvalidProtocolBufferException { 326 | return PARSER.parseFrom(data); 327 | } 328 | public static com.slack.openalgot.MarketEventProtos.Tick parseFrom( 329 | com.google.protobuf.ByteString data, 330 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 331 | throws com.google.protobuf.InvalidProtocolBufferException { 332 | return PARSER.parseFrom(data, extensionRegistry); 333 | } 334 | public static com.slack.openalgot.MarketEventProtos.Tick parseFrom(byte[] data) 335 | throws com.google.protobuf.InvalidProtocolBufferException { 336 | return PARSER.parseFrom(data); 337 | } 338 | public static com.slack.openalgot.MarketEventProtos.Tick parseFrom( 339 | byte[] data, 340 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 341 | throws com.google.protobuf.InvalidProtocolBufferException { 342 | return PARSER.parseFrom(data, extensionRegistry); 343 | } 344 | public static com.slack.openalgot.MarketEventProtos.Tick parseFrom(java.io.InputStream input) 345 | throws java.io.IOException { 346 | return com.google.protobuf.GeneratedMessage 347 | .parseWithIOException(PARSER, input); 348 | } 349 | public static com.slack.openalgot.MarketEventProtos.Tick parseFrom( 350 | java.io.InputStream input, 351 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 352 | throws java.io.IOException { 353 | return com.google.protobuf.GeneratedMessage 354 | .parseWithIOException(PARSER, input, extensionRegistry); 355 | } 356 | public static com.slack.openalgot.MarketEventProtos.Tick parseDelimitedFrom(java.io.InputStream input) 357 | throws java.io.IOException { 358 | return com.google.protobuf.GeneratedMessage 359 | .parseDelimitedWithIOException(PARSER, input); 360 | } 361 | public static com.slack.openalgot.MarketEventProtos.Tick parseDelimitedFrom( 362 | java.io.InputStream input, 363 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 364 | throws java.io.IOException { 365 | return com.google.protobuf.GeneratedMessage 366 | .parseDelimitedWithIOException(PARSER, input, extensionRegistry); 367 | } 368 | public static com.slack.openalgot.MarketEventProtos.Tick parseFrom( 369 | com.google.protobuf.CodedInputStream input) 370 | throws java.io.IOException { 371 | return com.google.protobuf.GeneratedMessage 372 | .parseWithIOException(PARSER, input); 373 | } 374 | public static com.slack.openalgot.MarketEventProtos.Tick parseFrom( 375 | com.google.protobuf.CodedInputStream input, 376 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 377 | throws java.io.IOException { 378 | return com.google.protobuf.GeneratedMessage 379 | .parseWithIOException(PARSER, input, extensionRegistry); 380 | } 381 | 382 | public Builder newBuilderForType() { return newBuilder(); } 383 | public static Builder newBuilder() { 384 | return DEFAULT_INSTANCE.toBuilder(); 385 | } 386 | public static Builder newBuilder(com.slack.openalgot.MarketEventProtos.Tick prototype) { 387 | return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); 388 | } 389 | public Builder toBuilder() { 390 | return this == DEFAULT_INSTANCE 391 | ? new Builder() : new Builder().mergeFrom(this); 392 | } 393 | 394 | @java.lang.Override 395 | protected Builder newBuilderForType( 396 | com.google.protobuf.GeneratedMessage.BuilderParent parent) { 397 | Builder builder = new Builder(parent); 398 | return builder; 399 | } 400 | /** 401 | * Protobuf type {@code go.srv.TickRecorder.Tick} 402 | */ 403 | public static final class Builder extends 404 | com.google.protobuf.GeneratedMessage.Builder implements 405 | // @@protoc_insertion_point(builder_implements:go.srv.TickRecorder.Tick) 406 | com.slack.openalgot.MarketEventProtos.TickOrBuilder { 407 | public static final com.google.protobuf.Descriptors.Descriptor 408 | getDescriptor() { 409 | return com.slack.openalgot.MarketEventProtos.internal_static_go_srv_TickRecorder_Tick_descriptor; 410 | } 411 | 412 | protected com.google.protobuf.GeneratedMessage.FieldAccessorTable 413 | internalGetFieldAccessorTable() { 414 | return com.slack.openalgot.MarketEventProtos.internal_static_go_srv_TickRecorder_Tick_fieldAccessorTable 415 | .ensureFieldAccessorsInitialized( 416 | com.slack.openalgot.MarketEventProtos.Tick.class, com.slack.openalgot.MarketEventProtos.Tick.Builder.class); 417 | } 418 | 419 | // Construct using com.slack.openalgot.MarketEventProtos.Tick.newBuilder() 420 | private Builder() { 421 | maybeForceBuilderInitialization(); 422 | } 423 | 424 | private Builder( 425 | com.google.protobuf.GeneratedMessage.BuilderParent parent) { 426 | super(parent); 427 | maybeForceBuilderInitialization(); 428 | } 429 | private void maybeForceBuilderInitialization() { 430 | if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { 431 | } 432 | } 433 | public Builder clear() { 434 | super.clear(); 435 | time_ = 0L; 436 | 437 | bid_ = 0D; 438 | 439 | ask_ = 0D; 440 | 441 | last_ = 0D; 442 | 443 | pair_ = ""; 444 | 445 | broker_ = ""; 446 | 447 | return this; 448 | } 449 | 450 | public com.google.protobuf.Descriptors.Descriptor 451 | getDescriptorForType() { 452 | return com.slack.openalgot.MarketEventProtos.internal_static_go_srv_TickRecorder_Tick_descriptor; 453 | } 454 | 455 | public com.slack.openalgot.MarketEventProtos.Tick getDefaultInstanceForType() { 456 | return com.slack.openalgot.MarketEventProtos.Tick.getDefaultInstance(); 457 | } 458 | 459 | public com.slack.openalgot.MarketEventProtos.Tick build() { 460 | com.slack.openalgot.MarketEventProtos.Tick result = buildPartial(); 461 | if (!result.isInitialized()) { 462 | throw newUninitializedMessageException(result); 463 | } 464 | return result; 465 | } 466 | 467 | public com.slack.openalgot.MarketEventProtos.Tick buildPartial() { 468 | com.slack.openalgot.MarketEventProtos.Tick result = new com.slack.openalgot.MarketEventProtos.Tick(this); 469 | result.time_ = time_; 470 | result.bid_ = bid_; 471 | result.ask_ = ask_; 472 | result.last_ = last_; 473 | result.pair_ = pair_; 474 | result.broker_ = broker_; 475 | onBuilt(); 476 | return result; 477 | } 478 | 479 | public Builder mergeFrom(com.google.protobuf.Message other) { 480 | if (other instanceof com.slack.openalgot.MarketEventProtos.Tick) { 481 | return mergeFrom((com.slack.openalgot.MarketEventProtos.Tick)other); 482 | } else { 483 | super.mergeFrom(other); 484 | return this; 485 | } 486 | } 487 | 488 | public Builder mergeFrom(com.slack.openalgot.MarketEventProtos.Tick other) { 489 | if (other == com.slack.openalgot.MarketEventProtos.Tick.getDefaultInstance()) return this; 490 | if (other.getTime() != 0L) { 491 | setTime(other.getTime()); 492 | } 493 | if (other.getBid() != 0D) { 494 | setBid(other.getBid()); 495 | } 496 | if (other.getAsk() != 0D) { 497 | setAsk(other.getAsk()); 498 | } 499 | if (other.getLast() != 0D) { 500 | setLast(other.getLast()); 501 | } 502 | if (!other.getPair().isEmpty()) { 503 | pair_ = other.pair_; 504 | onChanged(); 505 | } 506 | if (!other.getBroker().isEmpty()) { 507 | broker_ = other.broker_; 508 | onChanged(); 509 | } 510 | onChanged(); 511 | return this; 512 | } 513 | 514 | public final boolean isInitialized() { 515 | return true; 516 | } 517 | 518 | public Builder mergeFrom( 519 | com.google.protobuf.CodedInputStream input, 520 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 521 | throws java.io.IOException { 522 | com.slack.openalgot.MarketEventProtos.Tick parsedMessage = null; 523 | try { 524 | parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); 525 | } catch (com.google.protobuf.InvalidProtocolBufferException e) { 526 | parsedMessage = (com.slack.openalgot.MarketEventProtos.Tick) e.getUnfinishedMessage(); 527 | throw e.unwrapIOException(); 528 | } finally { 529 | if (parsedMessage != null) { 530 | mergeFrom(parsedMessage); 531 | } 532 | } 533 | return this; 534 | } 535 | 536 | private long time_ ; 537 | /** 538 | * optional int64 time = 1; 539 | */ 540 | public long getTime() { 541 | return time_; 542 | } 543 | /** 544 | * optional int64 time = 1; 545 | */ 546 | public Builder setTime(long value) { 547 | 548 | time_ = value; 549 | onChanged(); 550 | return this; 551 | } 552 | /** 553 | * optional int64 time = 1; 554 | */ 555 | public Builder clearTime() { 556 | 557 | time_ = 0L; 558 | onChanged(); 559 | return this; 560 | } 561 | 562 | private double bid_ ; 563 | /** 564 | * optional double bid = 2; 565 | */ 566 | public double getBid() { 567 | return bid_; 568 | } 569 | /** 570 | * optional double bid = 2; 571 | */ 572 | public Builder setBid(double value) { 573 | 574 | bid_ = value; 575 | onChanged(); 576 | return this; 577 | } 578 | /** 579 | * optional double bid = 2; 580 | */ 581 | public Builder clearBid() { 582 | 583 | bid_ = 0D; 584 | onChanged(); 585 | return this; 586 | } 587 | 588 | private double ask_ ; 589 | /** 590 | * optional double ask = 3; 591 | */ 592 | public double getAsk() { 593 | return ask_; 594 | } 595 | /** 596 | * optional double ask = 3; 597 | */ 598 | public Builder setAsk(double value) { 599 | 600 | ask_ = value; 601 | onChanged(); 602 | return this; 603 | } 604 | /** 605 | * optional double ask = 3; 606 | */ 607 | public Builder clearAsk() { 608 | 609 | ask_ = 0D; 610 | onChanged(); 611 | return this; 612 | } 613 | 614 | private double last_ ; 615 | /** 616 | * optional double last = 4; 617 | */ 618 | public double getLast() { 619 | return last_; 620 | } 621 | /** 622 | * optional double last = 4; 623 | */ 624 | public Builder setLast(double value) { 625 | 626 | last_ = value; 627 | onChanged(); 628 | return this; 629 | } 630 | /** 631 | * optional double last = 4; 632 | */ 633 | public Builder clearLast() { 634 | 635 | last_ = 0D; 636 | onChanged(); 637 | return this; 638 | } 639 | 640 | private java.lang.Object pair_ = ""; 641 | /** 642 | * optional string pair = 5; 643 | */ 644 | public java.lang.String getPair() { 645 | java.lang.Object ref = pair_; 646 | if (!(ref instanceof java.lang.String)) { 647 | com.google.protobuf.ByteString bs = 648 | (com.google.protobuf.ByteString) ref; 649 | java.lang.String s = bs.toStringUtf8(); 650 | pair_ = s; 651 | return s; 652 | } else { 653 | return (java.lang.String) ref; 654 | } 655 | } 656 | /** 657 | * optional string pair = 5; 658 | */ 659 | public com.google.protobuf.ByteString 660 | getPairBytes() { 661 | java.lang.Object ref = pair_; 662 | if (ref instanceof String) { 663 | com.google.protobuf.ByteString b = 664 | com.google.protobuf.ByteString.copyFromUtf8( 665 | (java.lang.String) ref); 666 | pair_ = b; 667 | return b; 668 | } else { 669 | return (com.google.protobuf.ByteString) ref; 670 | } 671 | } 672 | /** 673 | * optional string pair = 5; 674 | */ 675 | public Builder setPair( 676 | java.lang.String value) { 677 | if (value == null) { 678 | throw new NullPointerException(); 679 | } 680 | 681 | pair_ = value; 682 | onChanged(); 683 | return this; 684 | } 685 | /** 686 | * optional string pair = 5; 687 | */ 688 | public Builder clearPair() { 689 | 690 | pair_ = getDefaultInstance().getPair(); 691 | onChanged(); 692 | return this; 693 | } 694 | /** 695 | * optional string pair = 5; 696 | */ 697 | public Builder setPairBytes( 698 | com.google.protobuf.ByteString value) { 699 | if (value == null) { 700 | throw new NullPointerException(); 701 | } 702 | checkByteStringIsUtf8(value); 703 | 704 | pair_ = value; 705 | onChanged(); 706 | return this; 707 | } 708 | 709 | private java.lang.Object broker_ = ""; 710 | /** 711 | * optional string broker = 6; 712 | */ 713 | public java.lang.String getBroker() { 714 | java.lang.Object ref = broker_; 715 | if (!(ref instanceof java.lang.String)) { 716 | com.google.protobuf.ByteString bs = 717 | (com.google.protobuf.ByteString) ref; 718 | java.lang.String s = bs.toStringUtf8(); 719 | broker_ = s; 720 | return s; 721 | } else { 722 | return (java.lang.String) ref; 723 | } 724 | } 725 | /** 726 | * optional string broker = 6; 727 | */ 728 | public com.google.protobuf.ByteString 729 | getBrokerBytes() { 730 | java.lang.Object ref = broker_; 731 | if (ref instanceof String) { 732 | com.google.protobuf.ByteString b = 733 | com.google.protobuf.ByteString.copyFromUtf8( 734 | (java.lang.String) ref); 735 | broker_ = b; 736 | return b; 737 | } else { 738 | return (com.google.protobuf.ByteString) ref; 739 | } 740 | } 741 | /** 742 | * optional string broker = 6; 743 | */ 744 | public Builder setBroker( 745 | java.lang.String value) { 746 | if (value == null) { 747 | throw new NullPointerException(); 748 | } 749 | 750 | broker_ = value; 751 | onChanged(); 752 | return this; 753 | } 754 | /** 755 | * optional string broker = 6; 756 | */ 757 | public Builder clearBroker() { 758 | 759 | broker_ = getDefaultInstance().getBroker(); 760 | onChanged(); 761 | return this; 762 | } 763 | /** 764 | * optional string broker = 6; 765 | */ 766 | public Builder setBrokerBytes( 767 | com.google.protobuf.ByteString value) { 768 | if (value == null) { 769 | throw new NullPointerException(); 770 | } 771 | checkByteStringIsUtf8(value); 772 | 773 | broker_ = value; 774 | onChanged(); 775 | return this; 776 | } 777 | public final Builder setUnknownFields( 778 | final com.google.protobuf.UnknownFieldSet unknownFields) { 779 | return this; 780 | } 781 | 782 | public final Builder mergeUnknownFields( 783 | final com.google.protobuf.UnknownFieldSet unknownFields) { 784 | return this; 785 | } 786 | 787 | 788 | // @@protoc_insertion_point(builder_scope:go.srv.TickRecorder.Tick) 789 | } 790 | 791 | // @@protoc_insertion_point(class_scope:go.srv.TickRecorder.Tick) 792 | private static final com.slack.openalgot.MarketEventProtos.Tick DEFAULT_INSTANCE; 793 | static { 794 | DEFAULT_INSTANCE = new com.slack.openalgot.MarketEventProtos.Tick(); 795 | } 796 | 797 | public static com.slack.openalgot.MarketEventProtos.Tick getDefaultInstance() { 798 | return DEFAULT_INSTANCE; 799 | } 800 | 801 | private static final com.google.protobuf.Parser 802 | PARSER = new com.google.protobuf.AbstractParser() { 803 | public Tick parsePartialFrom( 804 | com.google.protobuf.CodedInputStream input, 805 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 806 | throws com.google.protobuf.InvalidProtocolBufferException { 807 | return new Tick(input, extensionRegistry); 808 | } 809 | }; 810 | 811 | public static com.google.protobuf.Parser parser() { 812 | return PARSER; 813 | } 814 | 815 | @java.lang.Override 816 | public com.google.protobuf.Parser getParserForType() { 817 | return PARSER; 818 | } 819 | 820 | public com.slack.openalgot.MarketEventProtos.Tick getDefaultInstanceForType() { 821 | return DEFAULT_INSTANCE; 822 | } 823 | 824 | } 825 | 826 | public interface TradeOrBuilder extends 827 | // @@protoc_insertion_point(interface_extends:go.srv.TickRecorder.Trade) 828 | com.google.protobuf.MessageOrBuilder { 829 | 830 | /** 831 | * optional int64 time = 1; 832 | */ 833 | long getTime(); 834 | 835 | /** 836 | * optional double price = 2; 837 | */ 838 | double getPrice(); 839 | 840 | /** 841 | * optional double amount = 3; 842 | */ 843 | double getAmount(); 844 | 845 | /** 846 | * optional int32 type = 4; 847 | */ 848 | int getType(); 849 | } 850 | /** 851 | * Protobuf type {@code go.srv.TickRecorder.Trade} 852 | */ 853 | public static final class Trade extends 854 | com.google.protobuf.GeneratedMessage implements 855 | // @@protoc_insertion_point(message_implements:go.srv.TickRecorder.Trade) 856 | TradeOrBuilder { 857 | // Use Trade.newBuilder() to construct. 858 | private Trade(com.google.protobuf.GeneratedMessage.Builder builder) { 859 | super(builder); 860 | } 861 | private Trade() { 862 | time_ = 0L; 863 | price_ = 0D; 864 | amount_ = 0D; 865 | type_ = 0; 866 | } 867 | 868 | @java.lang.Override 869 | public final com.google.protobuf.UnknownFieldSet 870 | getUnknownFields() { 871 | return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); 872 | } 873 | private Trade( 874 | com.google.protobuf.CodedInputStream input, 875 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 876 | throws com.google.protobuf.InvalidProtocolBufferException { 877 | this(); 878 | int mutable_bitField0_ = 0; 879 | try { 880 | boolean done = false; 881 | while (!done) { 882 | int tag = input.readTag(); 883 | switch (tag) { 884 | case 0: 885 | done = true; 886 | break; 887 | default: { 888 | if (!input.skipField(tag)) { 889 | done = true; 890 | } 891 | break; 892 | } 893 | case 8: { 894 | 895 | time_ = input.readInt64(); 896 | break; 897 | } 898 | case 17: { 899 | 900 | price_ = input.readDouble(); 901 | break; 902 | } 903 | case 25: { 904 | 905 | amount_ = input.readDouble(); 906 | break; 907 | } 908 | case 32: { 909 | 910 | type_ = input.readInt32(); 911 | break; 912 | } 913 | } 914 | } 915 | } catch (com.google.protobuf.InvalidProtocolBufferException e) { 916 | throw e.setUnfinishedMessage(this); 917 | } catch (java.io.IOException e) { 918 | throw new com.google.protobuf.InvalidProtocolBufferException( 919 | e).setUnfinishedMessage(this); 920 | } finally { 921 | makeExtensionsImmutable(); 922 | } 923 | } 924 | public static final com.google.protobuf.Descriptors.Descriptor 925 | getDescriptor() { 926 | return com.slack.openalgot.MarketEventProtos.internal_static_go_srv_TickRecorder_Trade_descriptor; 927 | } 928 | 929 | protected com.google.protobuf.GeneratedMessage.FieldAccessorTable 930 | internalGetFieldAccessorTable() { 931 | return com.slack.openalgot.MarketEventProtos.internal_static_go_srv_TickRecorder_Trade_fieldAccessorTable 932 | .ensureFieldAccessorsInitialized( 933 | com.slack.openalgot.MarketEventProtos.Trade.class, com.slack.openalgot.MarketEventProtos.Trade.Builder.class); 934 | } 935 | 936 | public static final int TIME_FIELD_NUMBER = 1; 937 | private long time_; 938 | /** 939 | * optional int64 time = 1; 940 | */ 941 | public long getTime() { 942 | return time_; 943 | } 944 | 945 | public static final int PRICE_FIELD_NUMBER = 2; 946 | private double price_; 947 | /** 948 | * optional double price = 2; 949 | */ 950 | public double getPrice() { 951 | return price_; 952 | } 953 | 954 | public static final int AMOUNT_FIELD_NUMBER = 3; 955 | private double amount_; 956 | /** 957 | * optional double amount = 3; 958 | */ 959 | public double getAmount() { 960 | return amount_; 961 | } 962 | 963 | public static final int TYPE_FIELD_NUMBER = 4; 964 | private int type_; 965 | /** 966 | * optional int32 type = 4; 967 | */ 968 | public int getType() { 969 | return type_; 970 | } 971 | 972 | private byte memoizedIsInitialized = -1; 973 | public final boolean isInitialized() { 974 | byte isInitialized = memoizedIsInitialized; 975 | if (isInitialized == 1) return true; 976 | if (isInitialized == 0) return false; 977 | 978 | memoizedIsInitialized = 1; 979 | return true; 980 | } 981 | 982 | public void writeTo(com.google.protobuf.CodedOutputStream output) 983 | throws java.io.IOException { 984 | if (time_ != 0L) { 985 | output.writeInt64(1, time_); 986 | } 987 | if (price_ != 0D) { 988 | output.writeDouble(2, price_); 989 | } 990 | if (amount_ != 0D) { 991 | output.writeDouble(3, amount_); 992 | } 993 | if (type_ != 0) { 994 | output.writeInt32(4, type_); 995 | } 996 | } 997 | 998 | public int getSerializedSize() { 999 | int size = memoizedSize; 1000 | if (size != -1) return size; 1001 | 1002 | size = 0; 1003 | if (time_ != 0L) { 1004 | size += com.google.protobuf.CodedOutputStream 1005 | .computeInt64Size(1, time_); 1006 | } 1007 | if (price_ != 0D) { 1008 | size += com.google.protobuf.CodedOutputStream 1009 | .computeDoubleSize(2, price_); 1010 | } 1011 | if (amount_ != 0D) { 1012 | size += com.google.protobuf.CodedOutputStream 1013 | .computeDoubleSize(3, amount_); 1014 | } 1015 | if (type_ != 0) { 1016 | size += com.google.protobuf.CodedOutputStream 1017 | .computeInt32Size(4, type_); 1018 | } 1019 | memoizedSize = size; 1020 | return size; 1021 | } 1022 | 1023 | private static final long serialVersionUID = 0L; 1024 | public static com.slack.openalgot.MarketEventProtos.Trade parseFrom( 1025 | com.google.protobuf.ByteString data) 1026 | throws com.google.protobuf.InvalidProtocolBufferException { 1027 | return PARSER.parseFrom(data); 1028 | } 1029 | public static com.slack.openalgot.MarketEventProtos.Trade parseFrom( 1030 | com.google.protobuf.ByteString data, 1031 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 1032 | throws com.google.protobuf.InvalidProtocolBufferException { 1033 | return PARSER.parseFrom(data, extensionRegistry); 1034 | } 1035 | public static com.slack.openalgot.MarketEventProtos.Trade parseFrom(byte[] data) 1036 | throws com.google.protobuf.InvalidProtocolBufferException { 1037 | return PARSER.parseFrom(data); 1038 | } 1039 | public static com.slack.openalgot.MarketEventProtos.Trade parseFrom( 1040 | byte[] data, 1041 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 1042 | throws com.google.protobuf.InvalidProtocolBufferException { 1043 | return PARSER.parseFrom(data, extensionRegistry); 1044 | } 1045 | public static com.slack.openalgot.MarketEventProtos.Trade parseFrom(java.io.InputStream input) 1046 | throws java.io.IOException { 1047 | return com.google.protobuf.GeneratedMessage 1048 | .parseWithIOException(PARSER, input); 1049 | } 1050 | public static com.slack.openalgot.MarketEventProtos.Trade parseFrom( 1051 | java.io.InputStream input, 1052 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 1053 | throws java.io.IOException { 1054 | return com.google.protobuf.GeneratedMessage 1055 | .parseWithIOException(PARSER, input, extensionRegistry); 1056 | } 1057 | public static com.slack.openalgot.MarketEventProtos.Trade parseDelimitedFrom(java.io.InputStream input) 1058 | throws java.io.IOException { 1059 | return com.google.protobuf.GeneratedMessage 1060 | .parseDelimitedWithIOException(PARSER, input); 1061 | } 1062 | public static com.slack.openalgot.MarketEventProtos.Trade parseDelimitedFrom( 1063 | java.io.InputStream input, 1064 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 1065 | throws java.io.IOException { 1066 | return com.google.protobuf.GeneratedMessage 1067 | .parseDelimitedWithIOException(PARSER, input, extensionRegistry); 1068 | } 1069 | public static com.slack.openalgot.MarketEventProtos.Trade parseFrom( 1070 | com.google.protobuf.CodedInputStream input) 1071 | throws java.io.IOException { 1072 | return com.google.protobuf.GeneratedMessage 1073 | .parseWithIOException(PARSER, input); 1074 | } 1075 | public static com.slack.openalgot.MarketEventProtos.Trade parseFrom( 1076 | com.google.protobuf.CodedInputStream input, 1077 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 1078 | throws java.io.IOException { 1079 | return com.google.protobuf.GeneratedMessage 1080 | .parseWithIOException(PARSER, input, extensionRegistry); 1081 | } 1082 | 1083 | public Builder newBuilderForType() { return newBuilder(); } 1084 | public static Builder newBuilder() { 1085 | return DEFAULT_INSTANCE.toBuilder(); 1086 | } 1087 | public static Builder newBuilder(com.slack.openalgot.MarketEventProtos.Trade prototype) { 1088 | return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); 1089 | } 1090 | public Builder toBuilder() { 1091 | return this == DEFAULT_INSTANCE 1092 | ? new Builder() : new Builder().mergeFrom(this); 1093 | } 1094 | 1095 | @java.lang.Override 1096 | protected Builder newBuilderForType( 1097 | com.google.protobuf.GeneratedMessage.BuilderParent parent) { 1098 | Builder builder = new Builder(parent); 1099 | return builder; 1100 | } 1101 | /** 1102 | * Protobuf type {@code go.srv.TickRecorder.Trade} 1103 | */ 1104 | public static final class Builder extends 1105 | com.google.protobuf.GeneratedMessage.Builder implements 1106 | // @@protoc_insertion_point(builder_implements:go.srv.TickRecorder.Trade) 1107 | com.slack.openalgot.MarketEventProtos.TradeOrBuilder { 1108 | public static final com.google.protobuf.Descriptors.Descriptor 1109 | getDescriptor() { 1110 | return com.slack.openalgot.MarketEventProtos.internal_static_go_srv_TickRecorder_Trade_descriptor; 1111 | } 1112 | 1113 | protected com.google.protobuf.GeneratedMessage.FieldAccessorTable 1114 | internalGetFieldAccessorTable() { 1115 | return com.slack.openalgot.MarketEventProtos.internal_static_go_srv_TickRecorder_Trade_fieldAccessorTable 1116 | .ensureFieldAccessorsInitialized( 1117 | com.slack.openalgot.MarketEventProtos.Trade.class, com.slack.openalgot.MarketEventProtos.Trade.Builder.class); 1118 | } 1119 | 1120 | // Construct using com.slack.openalgot.MarketEventProtos.Trade.newBuilder() 1121 | private Builder() { 1122 | maybeForceBuilderInitialization(); 1123 | } 1124 | 1125 | private Builder( 1126 | com.google.protobuf.GeneratedMessage.BuilderParent parent) { 1127 | super(parent); 1128 | maybeForceBuilderInitialization(); 1129 | } 1130 | private void maybeForceBuilderInitialization() { 1131 | if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { 1132 | } 1133 | } 1134 | public Builder clear() { 1135 | super.clear(); 1136 | time_ = 0L; 1137 | 1138 | price_ = 0D; 1139 | 1140 | amount_ = 0D; 1141 | 1142 | type_ = 0; 1143 | 1144 | return this; 1145 | } 1146 | 1147 | public com.google.protobuf.Descriptors.Descriptor 1148 | getDescriptorForType() { 1149 | return com.slack.openalgot.MarketEventProtos.internal_static_go_srv_TickRecorder_Trade_descriptor; 1150 | } 1151 | 1152 | public com.slack.openalgot.MarketEventProtos.Trade getDefaultInstanceForType() { 1153 | return com.slack.openalgot.MarketEventProtos.Trade.getDefaultInstance(); 1154 | } 1155 | 1156 | public com.slack.openalgot.MarketEventProtos.Trade build() { 1157 | com.slack.openalgot.MarketEventProtos.Trade result = buildPartial(); 1158 | if (!result.isInitialized()) { 1159 | throw newUninitializedMessageException(result); 1160 | } 1161 | return result; 1162 | } 1163 | 1164 | public com.slack.openalgot.MarketEventProtos.Trade buildPartial() { 1165 | com.slack.openalgot.MarketEventProtos.Trade result = new com.slack.openalgot.MarketEventProtos.Trade(this); 1166 | result.time_ = time_; 1167 | result.price_ = price_; 1168 | result.amount_ = amount_; 1169 | result.type_ = type_; 1170 | onBuilt(); 1171 | return result; 1172 | } 1173 | 1174 | public Builder mergeFrom(com.google.protobuf.Message other) { 1175 | if (other instanceof com.slack.openalgot.MarketEventProtos.Trade) { 1176 | return mergeFrom((com.slack.openalgot.MarketEventProtos.Trade)other); 1177 | } else { 1178 | super.mergeFrom(other); 1179 | return this; 1180 | } 1181 | } 1182 | 1183 | public Builder mergeFrom(com.slack.openalgot.MarketEventProtos.Trade other) { 1184 | if (other == com.slack.openalgot.MarketEventProtos.Trade.getDefaultInstance()) return this; 1185 | if (other.getTime() != 0L) { 1186 | setTime(other.getTime()); 1187 | } 1188 | if (other.getPrice() != 0D) { 1189 | setPrice(other.getPrice()); 1190 | } 1191 | if (other.getAmount() != 0D) { 1192 | setAmount(other.getAmount()); 1193 | } 1194 | if (other.getType() != 0) { 1195 | setType(other.getType()); 1196 | } 1197 | onChanged(); 1198 | return this; 1199 | } 1200 | 1201 | public final boolean isInitialized() { 1202 | return true; 1203 | } 1204 | 1205 | public Builder mergeFrom( 1206 | com.google.protobuf.CodedInputStream input, 1207 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 1208 | throws java.io.IOException { 1209 | com.slack.openalgot.MarketEventProtos.Trade parsedMessage = null; 1210 | try { 1211 | parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); 1212 | } catch (com.google.protobuf.InvalidProtocolBufferException e) { 1213 | parsedMessage = (com.slack.openalgot.MarketEventProtos.Trade) e.getUnfinishedMessage(); 1214 | throw e.unwrapIOException(); 1215 | } finally { 1216 | if (parsedMessage != null) { 1217 | mergeFrom(parsedMessage); 1218 | } 1219 | } 1220 | return this; 1221 | } 1222 | 1223 | private long time_ ; 1224 | /** 1225 | * optional int64 time = 1; 1226 | */ 1227 | public long getTime() { 1228 | return time_; 1229 | } 1230 | /** 1231 | * optional int64 time = 1; 1232 | */ 1233 | public Builder setTime(long value) { 1234 | 1235 | time_ = value; 1236 | onChanged(); 1237 | return this; 1238 | } 1239 | /** 1240 | * optional int64 time = 1; 1241 | */ 1242 | public Builder clearTime() { 1243 | 1244 | time_ = 0L; 1245 | onChanged(); 1246 | return this; 1247 | } 1248 | 1249 | private double price_ ; 1250 | /** 1251 | * optional double price = 2; 1252 | */ 1253 | public double getPrice() { 1254 | return price_; 1255 | } 1256 | /** 1257 | * optional double price = 2; 1258 | */ 1259 | public Builder setPrice(double value) { 1260 | 1261 | price_ = value; 1262 | onChanged(); 1263 | return this; 1264 | } 1265 | /** 1266 | * optional double price = 2; 1267 | */ 1268 | public Builder clearPrice() { 1269 | 1270 | price_ = 0D; 1271 | onChanged(); 1272 | return this; 1273 | } 1274 | 1275 | private double amount_ ; 1276 | /** 1277 | * optional double amount = 3; 1278 | */ 1279 | public double getAmount() { 1280 | return amount_; 1281 | } 1282 | /** 1283 | * optional double amount = 3; 1284 | */ 1285 | public Builder setAmount(double value) { 1286 | 1287 | amount_ = value; 1288 | onChanged(); 1289 | return this; 1290 | } 1291 | /** 1292 | * optional double amount = 3; 1293 | */ 1294 | public Builder clearAmount() { 1295 | 1296 | amount_ = 0D; 1297 | onChanged(); 1298 | return this; 1299 | } 1300 | 1301 | private int type_ ; 1302 | /** 1303 | * optional int32 type = 4; 1304 | */ 1305 | public int getType() { 1306 | return type_; 1307 | } 1308 | /** 1309 | * optional int32 type = 4; 1310 | */ 1311 | public Builder setType(int value) { 1312 | 1313 | type_ = value; 1314 | onChanged(); 1315 | return this; 1316 | } 1317 | /** 1318 | * optional int32 type = 4; 1319 | */ 1320 | public Builder clearType() { 1321 | 1322 | type_ = 0; 1323 | onChanged(); 1324 | return this; 1325 | } 1326 | public final Builder setUnknownFields( 1327 | final com.google.protobuf.UnknownFieldSet unknownFields) { 1328 | return this; 1329 | } 1330 | 1331 | public final Builder mergeUnknownFields( 1332 | final com.google.protobuf.UnknownFieldSet unknownFields) { 1333 | return this; 1334 | } 1335 | 1336 | 1337 | // @@protoc_insertion_point(builder_scope:go.srv.TickRecorder.Trade) 1338 | } 1339 | 1340 | // @@protoc_insertion_point(class_scope:go.srv.TickRecorder.Trade) 1341 | private static final com.slack.openalgot.MarketEventProtos.Trade DEFAULT_INSTANCE; 1342 | static { 1343 | DEFAULT_INSTANCE = new com.slack.openalgot.MarketEventProtos.Trade(); 1344 | } 1345 | 1346 | public static com.slack.openalgot.MarketEventProtos.Trade getDefaultInstance() { 1347 | return DEFAULT_INSTANCE; 1348 | } 1349 | 1350 | private static final com.google.protobuf.Parser 1351 | PARSER = new com.google.protobuf.AbstractParser() { 1352 | public Trade parsePartialFrom( 1353 | com.google.protobuf.CodedInputStream input, 1354 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 1355 | throws com.google.protobuf.InvalidProtocolBufferException { 1356 | return new Trade(input, extensionRegistry); 1357 | } 1358 | }; 1359 | 1360 | public static com.google.protobuf.Parser parser() { 1361 | return PARSER; 1362 | } 1363 | 1364 | @java.lang.Override 1365 | public com.google.protobuf.Parser getParserForType() { 1366 | return PARSER; 1367 | } 1368 | 1369 | public com.slack.openalgot.MarketEventProtos.Trade getDefaultInstanceForType() { 1370 | return DEFAULT_INSTANCE; 1371 | } 1372 | 1373 | } 1374 | 1375 | private static final com.google.protobuf.Descriptors.Descriptor 1376 | internal_static_go_srv_TickRecorder_Tick_descriptor; 1377 | private static final 1378 | com.google.protobuf.GeneratedMessage.FieldAccessorTable 1379 | internal_static_go_srv_TickRecorder_Tick_fieldAccessorTable; 1380 | private static final com.google.protobuf.Descriptors.Descriptor 1381 | internal_static_go_srv_TickRecorder_Trade_descriptor; 1382 | private static final 1383 | com.google.protobuf.GeneratedMessage.FieldAccessorTable 1384 | internal_static_go_srv_TickRecorder_Trade_fieldAccessorTable; 1385 | 1386 | public static com.google.protobuf.Descriptors.FileDescriptor 1387 | getDescriptor() { 1388 | return descriptor; 1389 | } 1390 | private static com.google.protobuf.Descriptors.FileDescriptor 1391 | descriptor; 1392 | static { 1393 | java.lang.String[] descriptorData = { 1394 | "\n\ntick.proto\022\023go.srv.TickRecorder\"Z\n\004Tic" + 1395 | "k\022\014\n\004time\030\001 \001(\003\022\013\n\003bid\030\002 \001(\001\022\013\n\003ask\030\003 \001(" + 1396 | "\001\022\014\n\004last\030\004 \001(\001\022\014\n\004pair\030\005 \001(\t\022\016\n\006broker\030" + 1397 | "\006 \001(\t\"B\n\005Trade\022\014\n\004time\030\001 \001(\003\022\r\n\005price\030\002 " + 1398 | "\001(\001\022\016\n\006amount\030\003 \001(\001\022\014\n\004type\030\004 \001(\005B(\n\023com" + 1399 | ".slack.openalgotB\021MarketEventProtosb\006pro" + 1400 | "to3" 1401 | }; 1402 | com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = 1403 | new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { 1404 | public com.google.protobuf.ExtensionRegistry assignDescriptors( 1405 | com.google.protobuf.Descriptors.FileDescriptor root) { 1406 | descriptor = root; 1407 | return null; 1408 | } 1409 | }; 1410 | com.google.protobuf.Descriptors.FileDescriptor 1411 | .internalBuildGeneratedFileFrom(descriptorData, 1412 | new com.google.protobuf.Descriptors.FileDescriptor[] { 1413 | }, assigner); 1414 | internal_static_go_srv_TickRecorder_Tick_descriptor = 1415 | getDescriptor().getMessageTypes().get(0); 1416 | internal_static_go_srv_TickRecorder_Tick_fieldAccessorTable = new 1417 | com.google.protobuf.GeneratedMessage.FieldAccessorTable( 1418 | internal_static_go_srv_TickRecorder_Tick_descriptor, 1419 | new java.lang.String[] { "Time", "Bid", "Ask", "Last", "Pair", "Broker", }); 1420 | internal_static_go_srv_TickRecorder_Trade_descriptor = 1421 | getDescriptor().getMessageTypes().get(1); 1422 | internal_static_go_srv_TickRecorder_Trade_fieldAccessorTable = new 1423 | com.google.protobuf.GeneratedMessage.FieldAccessorTable( 1424 | internal_static_go_srv_TickRecorder_Trade_descriptor, 1425 | new java.lang.String[] { "Time", "Price", "Amount", "Type", }); 1426 | } 1427 | 1428 | // @@protoc_insertion_point(outer_class_scope) 1429 | } 1430 | --------------------------------------------------------------------------------