From 3583a94c0a06afffb46faa1f22d634744b7e3cf4 Mon Sep 17 00:00:00 2001 From: Anton Osenenko <418868+a0s@users.noreply.github.com> Date: Mon, 24 Aug 2020 12:51:59 +0300 Subject: [PATCH] add path to files --- README.md | 63 +++++++++++++++++++++++++++++++-------------------- main.go | 2 +- main_scope.go | 52 ++++++++++++++++++++++-------------------- 3 files changed, 68 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index a50202a..9558787 100644 --- a/README.md +++ b/README.md @@ -15,15 +15,21 @@ Releases * docker image with amd64, arm64, armv6 and armv7 manifests: [a00s/tinkoff-invest-dumper](https://hub.docker.com/repository/docker/a00s/tinkoff-invest-dumper) -Run as binary -------------- +Options +------- ```shell script tinkoff-invest-dumper --help ruby-2.7.1 - -depth int - depth of orderbook (default 1) - -tickers string - list of tickers + -candle string + list of tickers to subscribe for candles + -candleInterval string + interval of candles: 1min,2min,3min,5min,10min,15min,30min,hour,2hour,4hour,day,week,month (default "1min") + -orderbook string + list of tickers to subscribe for orderbooks + -orderbook-depth int + depth of orderbook: from 1 to 20 (default 20) + -path string + path to storage dir (default ".") -token string your sandbox's token -version @@ -34,33 +40,42 @@ Run as Docker image ------------------- ```shell script -docker run --rm -it a00s/tinkoff-invest-dumper --help -Usage of /app/tinkoff-invest-dumper: - -depth int - depth of orderbook (default 1) - -tickers string - list of tickers - -token string - your sandbox's token - -version - show version info +docker run \ + --rm -it \ + --env TOKEN=$TINKOFF_SANDBOX \ + --volume `pwd`/data:/data \ + a00s/tinkoff-invest-dumper \ + --token "$TOKEN" \ + --path /data \ + --candle NVDA,MSFT,TSLA \ + --orderbook NVDA,MSFT,TSLA ``` Example ------- -`tinkoff-invest-dumper -token "$TINKOFF_SANDBOX" -tickers NVDA,MSFT,TSLA -depth 5` +`tinkoff-invest-dumper -token "$TINKOFF_SANDBOX" -candle NVDA,MSFT,TSLA -orderbook NVDA,MSFT,TSLA -orderbook-depth 2` ``` -2020/08/22 00:01:55 Subscribed MSFT BBG000BPH459 -2020/08/22 00:01:55 Subscribed TSLA BBG000N9MNX3 -2020/08/22 00:01:55 Subscribed NVDA BBG000BBJQV0 +2020/08/24 12:49:15 Subscribed to orderbook NVDA BBG000BBJQV0 +2020/08/24 12:49:15 Subscribed to orderbook MSFT BBG000BPH459 +2020/08/24 12:49:15 Subscribed to orderbook TSLA BBG000N9MNX3 +2020/08/24 12:49:15 Subscribed to candles NVDA BBG000BBJQV0 +2020/08/24 12:49:15 Subscribed to candles MSFT BBG000BPH459 +2020/08/24 12:49:15 Subscribed to candles TSLA BBG000N9MNX3 +``` + +`tail -f NVDA_orderbook` + +```json +{"a":[[514.31,75],[514.71,6]],"b":[[514.3,6],[514.25,10]],"figi":"BBG000BBJQV0","lt":"2020-08-24T12:49:24.866749+03:00","t":"2020-08-24T09:49:24.850272182Z","ticker":"NVDA"} +{"a":[[514.31,75],[514.71,6]],"b":[[514.3,6],[514.25,10]],"figi":"BBG000BBJQV0","lt":"2020-08-24T12:49:25.225449+03:00","t":"2020-08-24T09:49:25.26326835Z","ticker":"NVDA"} +{"a":[[514.31,75],[514.71,6]],"b":[[514.3,6],[514.25,10]],"figi":"BBG000BBJQV0","lt":"2020-08-24T12:49:25.480208+03:00","t":"2020-08-24T09:49:25.50689026Z","ticker":"NVDA"} ``` -`tail -f NVDA` +`tail -f NVDA_candles` ```json -{"event":{"event":"orderbook","time":"2020-08-21T21:00:53.397580821Z","payload":{"figi":"BBG000BBJQV0","depth":5,"bids":[[507,6],[506.84,53],[506.8,100],[506.75,75],[506.74,10]],"asks":[[507.19,196],[507.2,52],[507.28,75],[507.29,301],[507.35,10]]}},"ticker":"NVDA","time":"2020-08-22T00:00:53.384211+03:00"} -{"event":{"event":"orderbook","time":"2020-08-21T21:01:55.105348328Z","payload":{"figi":"BBG000BBJQV0","depth":5,"bids":[[507,6],[506.84,53],[506.8,100],[506.75,75],[506.74,10]],"asks":[[507.19,196],[507.2,15],[507.28,75],[507.29,301],[507.35,10]]}},"ticker":"NVDA","time":"2020-08-22T00:01:55.089803+03:00"} -{"event":{"event":"orderbook","time":"2020-08-21T21:02:50.885678541Z","payload":{"figi":"BBG000BBJQV0","depth":5,"bids":[[507,6],[506.84,53],[506.8,100],[506.75,75],[506.74,10]],"asks":[[507.19,196],[507.2,15],[507.28,75],[507.29,301],[507.35,10]]}},"ticker":"NVDA","time":"2020-08-22T00:02:50.869458+03:00"} +{"c":514.48,"figi":"BBG000BBJQV0","h":514.71,"i":"1min","l":514.48,"lt":"2020-08-24T12:49:15.203217+03:00","o":514.5,"t":"2020-08-24T09:49:15.241791397Z","ticker":"NVDA","ts":"2020-08-24T09:49:00Z","v":11} +{"c":514.48,"figi":"BBG000BBJQV0","h":514.71,"i":"1min","l":514.48,"lt":"2020-08-24T12:49:19.747036+03:00","o":514.5,"t":"2020-08-24T09:49:19.786563182Z","ticker":"NVDA","ts":"2020-08-24T09:49:00Z","v":13} ``` diff --git a/main.go b/main.go index 39ab074..aea3d7a 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ var ( path = flag.String("path", ".", "path to storage dir") orderbook = flag.String("orderbook", "", "list of tickers to subscribe for orderbooks") - orderbookDepth = flag.Int("orderbook-depth", 1, "depth of orderbook") + orderbookDepth = flag.Int("orderbook-depth", 20, "depth of orderbook: from 1 to 20") candle = flag.String("candle", "", "list of tickers to subscribe for candles") candleInterval = flag.String("candleInterval", "1min", "interval of candles: 1min,2min,3min,5min,10min,15min,30min,hour,2hour,4hour,day,week,month") diff --git a/main_scope.go b/main_scope.go index f054b4a..9d4a270 100644 --- a/main_scope.go +++ b/main_scope.go @@ -181,12 +181,13 @@ func (s *mainScope) orderbookWriter(ch eventChannel, filePath string) { for wrappedEvent := range ch { event := wrappedEvent.event.(sdk.OrderBookEvent) row := map[string]interface{}{ - "ticker": wrappedEvent.ticker, - "figi": figi(event.OrderBook.FIGI), - "time": event.Time, - "local_time": wrappedEvent.time.Format(time.RFC3339Nano), - "bids": event.OrderBook.Bids, - "asks": event.OrderBook.Asks, + "ticker": wrappedEvent.ticker, + "figi": figi(event.OrderBook.FIGI), + + "t": event.Time, + "lt": wrappedEvent.time.Format(time.RFC3339Nano), + "b": event.OrderBook.Bids, + "a": event.OrderBook.Asks, } jsonBytes, err := json.Marshal(row) @@ -216,18 +217,18 @@ func (s *mainScope) candleWriter(ch eventChannel, filePath string) { for wrappedEvent := range ch { event := wrappedEvent.event.(sdk.CandleEvent) row := map[string]interface{}{ - "ticker": wrappedEvent.ticker, - "figi": figi(event.Candle.FIGI), - "time": event.Time, - "local_time": wrappedEvent.time.Format(time.RFC3339Nano), - - "o": event.Candle.OpenPrice, - "c": event.Candle.ClosePrice, - "h": event.Candle.HighPrice, - "l": event.Candle.LowPrice, - "v": event.Candle.Volume, - "time2": event.Candle.TS, - "i": event.Candle.Interval, + "ticker": wrappedEvent.ticker, + "figi": figi(event.Candle.FIGI), + + "t": event.Time, + "lt": wrappedEvent.time.Format(time.RFC3339Nano), + "o": event.Candle.OpenPrice, + "c": event.Candle.ClosePrice, + "h": event.Candle.HighPrice, + "l": event.Candle.LowPrice, + "v": event.Candle.Volume, + "ts": event.Candle.TS, + "i": event.Candle.Interval, } jsonBytes, err := json.Marshal(row) @@ -249,7 +250,7 @@ func (s *mainScope) initDiskWriters() { figi := figi(instrument.FIGI) if _, ok := findTicker(s.orderbookTickers, ticker); ok { - filePath, err := filepath.Abs(filepath.Join(*path, string(ticker), "_orderbook")) + filePath, err := filepath.Abs(filepath.Join(*path, fmt.Sprintf("%s%s", string(ticker), "_orderbook"))) if err != nil { s.logger.Fatalln(err) } @@ -258,7 +259,7 @@ func (s *mainScope) initDiskWriters() { } if _, ok := findTicker(s.candleTickers, ticker); ok { - filePath, err := filepath.Abs(filepath.Join(*path, string(ticker), "_candles")) + filePath, err := filepath.Abs(filepath.Join(*path, fmt.Sprintf("%s%s", string(ticker), "_candles"))) if err != nil { s.logger.Fatalln(err) } @@ -286,10 +287,13 @@ func (s *mainScope) allTickers() []ticker { return keys } -func listToTickers(flag string) (tickers []ticker) { - flagArr := strings.Split(flag, ",") - for _, str := range flagArr { - tickers = append(tickers, ticker(str)) +func listToTickers(flag string) []ticker { + var tickers []ticker + flags := strings.Split(flag, ",") + for _, f := range flags { + if f != "" { + tickers = append(tickers, ticker(f)) + } } return tickers }