Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add "1Sec" to queryable timeframe list #201

Merged
merged 4 commits into from
Mar 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion executor/rewriteBuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ inline void getTimeFromTicks(uint32_t intervalStart, int64_t intervalsPerDay,
fractionalSeconds += 1;
}
ept->epoch = intStart + fractionalSeconds;
ept->nanos = subseconds;
// round the subseconds after the decimal point to minimize the cancellation error of subseconds
// round( subseconds ) = (int32_t)(subseconds + 0.5)
ept->nanos = subseconds + 0.5;
}
9 changes: 6 additions & 3 deletions tests/integ/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
# Commands to automate integration tests
################################################################################

LATEST_TAG ?= $(shell bin/dockertags alpacamarkets/marketstore | tail -1)
IMAGE_NAME ?= alpacamarkets/marketstore:${LATEST_TAG}
IMAGE_NAME ?= alpacahq/integrationtests.marketstore
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this pull request, integration test was being run to the latest marketstore image that was already pushed.
In order to run the integration test to the code written in the pull request, we need to create docker image of marketstore every time a pull request is created

CONTAINER_NAME = integration_tests_mstore
MARKETSTORE_DEV_DB_URL = https://s3.amazonaws.com/dev.alpaca.markets/gobroker/mktsdb.tar.gz
MARKETSTORE_DEV_DB_TMPFILE = /tmp/mktsdb.tgz

# User targets
################################################################################

# build marketstore docker container for integration test
build_mstore:
docker build -t ${IMAGE_NAME} ../..

# start a marketstore docker container and check if ListSymbols API can be consumed
.PHONY: connect
connect: run
Expand Down Expand Up @@ -44,7 +47,7 @@ clean: stop
# Utils
################################################################################
.PHONY: _init
_init:
_init: build_mstore
@if [ ! -d data/mktsdb ]; then \
rm -rf data; \
$(MAKE) _get_data; \
Expand Down
992 changes: 496 additions & 496 deletions tests/integ/bin/ticks-example-1-output.csv

Large diffs are not rendered by default.

992 changes: 496 additions & 496 deletions tests/integ/bin/ticks-example-2-output.csv

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/integ/dockerfiles/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ DOCKER_OPTS_STANDALONE=\
DOCKER_OPTS=\
$(DOCKER_OPTS_STANDALONE)

# build pymarketstore docker container for integration test
build:
docker build -t $(IMAGE_NAME) .

Expand Down
61 changes: 61 additions & 0 deletions tests/integ/tests/test_1sec_timeframe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

"""
Integration Test for 1Sec timeframe
"""
import pytest

import numpy as np
import pandas as pd

import pymarketstore as pymkts

# Constants
DATA_TYPE_TICK = [('Epoch', 'i8'), ('Bid', 'f4'), ('Ask', 'f4'), ('Nanoseconds', 'i4')]
DATA_TYPE_CANDLE = [('Epoch', 'i8'), ('Open', 'f8'), ('High', 'f8'), ('Low', 'f8'), ('Close', 'f8'), ('Volume', 'f8')]
MARKETSTORE_HOST = "localhost"
MARKETSTORE_PORT = 5993

client = pymkts.Client('http://localhost:5993/rpc')


def timestamp(datestr):
return int(pd.Timestamp(datestr).value / 10 ** 9)


@pytest.mark.parametrize('symbol, data', [
('TEST_SIMPLE_TICK', [(timestamp('2019-01-01 00:00:00'), 1, 2, 3), # epoch, ask, bid, nanosecond
(timestamp('2019-01-01 00:00:01'), 4, 5, 6),
(timestamp('2019-12-31 23:59:59'), 7, 8, 9)]),
('TEST_MULTIPLE_TICK_IN_TIMEFRAME', [(timestamp('2019-01-01 18:00:00'), 1, 1, 1000),
(timestamp('2019-01-01 18:00:00'), 2, 2, 2000)]),
('TEST_DUPLICATE_INDEX', [(timestamp('2019-01-01 12:00:00'), 1, 1, 3),
(timestamp('2019-01-01 12:00:00'), 2, 2, 3)])
])
def test_1sec_tf_tick(symbol, data):
# ---- given ----
client.write(np.array(data, dtype=DATA_TYPE_TICK), "{}/1Sec/TICK".format(symbol), isvariablelength=True)

# ---- when ----
reply = client.query(pymkts.Params(symbol, '1Sec', 'TICK', limit=10))

# ---- then ----
data_without_epochs = [record[1:] for record in data]
assert (reply.first().df().values == data_without_epochs).all()


@pytest.mark.parametrize('symbol, data', [
('TEST_SIMPLE_OHLCV', [(timestamp('2019-01-01 00:00:00'), 1.0, 2.0, 3.0, 4.0, 5.0 ), # epoch, Open, High, Low, Close, Volume
(timestamp('2019-01-01 00:00:01'), 1.0, 2.0, 3.0, 4.0, 5.0 ),
(timestamp('2019-12-31 23:59:59'), 6.0, 7.0, 8.0, 9.0, 10.0)]),
])
def test_1sec_tf_candle(symbol, data):
# ---- given ----
print("aaaa")
print(client.write(np.array(data, dtype=DATA_TYPE_CANDLE), "{}/1Sec/OHLCV".format(symbol), isvariablelength=False))

# ---- when ----
reply = client.query(pymkts.Params(symbol, '1Sec', 'OHLCV', limit=10))

# ---- then ----
data_without_epochs = [record[1:] for record in data]
assert (reply.first().df().values == data_without_epochs).all()
1 change: 1 addition & 0 deletions utils/timeframe.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var timeframeDefs = []Timeframe{
}

var Timeframes = []*Timeframe{
{"1Sec", time.Second},
{"1Min", time.Minute},
{"5Min", 5 * time.Minute},
{"15Min", 15 * time.Minute},
Expand Down