Skip to content

Commit

Permalink
Merge 236488b into 033f948
Browse files Browse the repository at this point in the history
  • Loading branch information
JunhaoWang committed Feb 1, 2018
2 parents 033f948 + 236488b commit a4f0493
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .cookiecutterrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ default_context:
c_extension_optional: 'no'
c_extension_support: 'no'
codacy: 'yes'
codeclimate: 'yes'
codeclimate: 'no'
codecov: 'no'
command_line_interface: 'click'
command_line_interface_bin_name: 'bittrade'
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ repos:
- id: autopep8-wrapper
- id: check-docstring-first
- id: check-json
- id: check-yaml
exclude: /template/
- id: debug-statements
- id: name-tests-test
args: [--django]
Expand All @@ -18,6 +16,8 @@ repos:
- id: check-ast
- id: fix-encoding-pragma
args: [--remove]
- id: check-added-large-files
args: ['--maxkb=1024']
- repo: https://github.com/asottile/reorder_python_imports.git
sha: v0.3.5
hooks:
Expand Down
4 changes: 4 additions & 0 deletions .pytest_cache/v/cache/lastfailed
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tests/test_bittrade.py": true,
"tests/test_google_client.py": true
}
15 changes: 0 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,9 @@ env:
- TOXENV=docs
matrix:
include:
- python: '2.7'
env:
- TOXENV=py27,report,coveralls
- python: '3.3'
env:
- TOXENV=py33,report,coveralls
- python: '3.4'
env:
- TOXENV=py34,report,coveralls
- python: '3.5'
env:
- TOXENV=py35,report,coveralls
- python: '3.6'
env:
- TOXENV=py36,report,coveralls
- python: 'pypy-5.4'
env:
- TOXENV=pypy,report,coveralls
before_install:
- python --version
- uname -a
Expand Down
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Authors
=======

* Junhao Wang - https://the-hao.com/
* Dongxu Li - https://leodongxu.wixsite.com/quant
6 changes: 4 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ include CONTRIBUTING.rst
include LICENSE
include README.rst

include tox.ini .travis.yml .pre-commit-config.yaml
include tox.ini .travis.yml .pre-commit-config.yaml pytest.ini requirements.txt

global-exclude *.py[cod] __pycache__ *.so *.dylib *.html *.md *.css *.eot *.ico *.js *.map *.png *.svg *.ttf *.woff *.xml site site/*
global-include src src/*.py

global-exclude *.py[cod] __pycache__ *.so *.dylib *.html *.md *.css *.eot *.ico *.js *.map *.png *.svg *.ttf *.woff *.xml site site/* .pytest_cache .pytest_cache/*
6 changes: 1 addition & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Overview
* - tests
- | |travis| |requires|
| |coveralls|
| |codacy| |codeclimate|
| |codacy|
* - package
- | |version| |wheel| |supported-versions| |supported-implementations|
| |commits-since|
Expand All @@ -37,10 +37,6 @@ Overview
:target: https://www.codacy.com/app/JunhaoWang/bittrade?utm_source=github.com&utm_medium=referral&utm_content=JunhaoWang/bittrade&utm_campaign=Badge_Grade
:alt: Codacy Code Quality Status

.. |codeclimate| image:: https://codeclimate.com/github/JunhaoWang/bittrade/badges/gpa.svg
:target: https://codeclimate.com/github/JunhaoWang/bittrade
:alt: CodeClimate Quality Status

.. |version| image:: https://img.shields.io/pypi/v/bittrade.svg
:alt: PyPI Package latest release
:target: https://pypi.python.org/pypi/bittrade
Expand Down
51 changes: 0 additions & 51 deletions ci/templates/appveyor.yml

This file was deleted.

2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = --doctest-modules
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
click
pandas
requests
16 changes: 3 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,16 @@ def read(*names, **kwargs):
'Operating System :: Unix',
'Operating System :: POSIX',
'Operating System :: Microsoft :: Windows',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
# uncomment if you test on these interpreters:
# 'Programming Language :: Python :: Implementation :: IronPython',
# 'Programming Language :: Python :: Implementation :: Jython',
# 'Programming Language :: Python :: Implementation :: Stackless',
'Topic :: Utilities',
],
keywords=[
# eg: 'keyword1', 'keyword2', 'keyword3',
'crpto', 'ai',
],
install_requires=[
'click',
'pandas',
'requests',
# eg: 'aspectlib==1.1.1', 'six>=1.7',
],
extras_require={
Expand Down
Empty file added src/bittrade/data/__init__.py
Empty file.
101 changes: 101 additions & 0 deletions src/bittrade/data/google_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
"""Module to retrieves Google Finance data.
This module contains various price for stocks and crypto.
Todo:
* EMPTY
* You have to also use ``sphinx.ext.todo`` extension
"""
from datetime import datetime

import pandas as pd
import requests


def get_price_data(query):
"""
Use Google Finance to get data.
Args:
query (str): EMPTY
Returns:
pandas.DataFrame: EMPTY
"""
r = requests.get(
"https://finance.google.com/finance/getprices", params=query,
)
lines = r.text.splitlines()
data = []
index = []
basetime = 0
for price in lines:
cols = price.split(",")
if cols[0][0] == 'a':
basetime = int(cols[0][1:])
index.append(datetime.fromtimestamp(basetime))
data.append([
float(cols[4]), float(cols[2]), float(
cols[3],
), float(cols[1]), int(cols[5]),
])
elif cols[0][0].isdigit():
date = basetime + (int(cols[0])*int(query['i']))
index.append(datetime.fromtimestamp(date))
data.append([
float(cols[4]), float(cols[2]), float(
cols[3],
), float(cols[1]), int(cols[5]),
])
return pd.DataFrame(data, index=index, columns=['Open', 'High', 'Low', 'Close', 'Volume'])


def get_close_price(target, period='1Y'):
"""
Get the close price, for every target ticker.
Args:
target (EMPTY): EMPTY
period (str): EMPTY
Returns:
EMPTY: EMPTY
"""
market, ticker = target.split(':')
param = {
'q': ticker, # Bitcoin price in USD
'i': "86400", # Interval size in seconds ("86400" = 1 day intervals)
'x': market,
'p': period, # Period (Ex: "4Y" = 4 year)
}
df = get_price_data(param)
price = df[['Close']]
price = price.reset_index()
price['index'] = price['index'].apply(lambda x: x.date())
price.columns = ['Date', ticker]
return price


def get_close_price_table(targetList, interpolation=True, period='1Y'):
"""
EMPTY
"""
df_table = pd.DataFrame()
for target in targetList:
price = get_close_price(target, period)
if (df_table.shape == (0, 0)):
df_table = price
else:
df_table = pd.merge(df_table, price, how='outer', on='Date')
if (not interpolation):
return df_table
else:
priceTable = df_table
# linear interpolation is applied.
priceTable['Date'] = pd.to_datetime(priceTable.Date)
priceTable = priceTable.sort_values(by='Date')
priceTable = priceTable.interpolate(
method='linear', axis=0,
).ffill().bfill()
priceTable = priceTable.set_index('Date')
return priceTable
51 changes: 51 additions & 0 deletions tests/test_google_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from bittrade.data.google_client import get_close_price_table


def test_get_close_price_table():
"""
Getting the date we need from google finance API.
currencyTicker represents the bitcoin price, and the most tradable currency include Japanese Yen, Swiss Franc,
Australian Dollar, Canadian Dollar, Indian Rupee, Euro. The price data for these currency are all quoted in dollar.
24 Most Liquid ETFs:
SPDR S&P 500 (SPY)
Financial Select Sector SPDR (XLF)
Russell 2000 Index Fund Profile (IWM)
MSCI Emerging Markets Index Fund (EEM)
PowerShares QQQ (QQQ)
Vanguard MSCI Emerging Markets ETF (VWO)
MSCI EAFE Index Fund (EFA)
FTSE China 25 Index Fund (FXI)
Industrial Select Sector SPDR Fund (XLI)
Daily Small Cap Bear 3X Shares Fundamentals (TZA)
Energy Select Sector SPDR Fund (XLE)
UltraShort S&P500 (SDS)
Silver Trust ETF (SLV)
Direxion Daily Financial Bear 3x Shares (FAZ)
Market Vectors TR Gold Miners ETF (GDX)
MSCI Japan Index Fund (EWJ)
UltraPro Short S&P500 (SPXU)
MSCI Brazil Index Fund (EWZ)
Daily Financial Bull 3X Shares (FAS)
VelocityShares Daily 2x VIX Short-Term ETN (TVIX)
United States Oil Fund (USO)
SPDR Gold Shares (GLD)
UltraShort Barclays 20+ Year Treasury (TBT)
United States Natural Gas Fund (UNG)
"""
currencyTickers = [
"CURRENCY:BTCUSD", "CURRENCY:GBPUSD", "CURRENCY:JPYUSD", "CURRENCY:CHFUSD",
"CURRENCY:AUDUSD", "CURRENCY:CADUSD", "CURRENCY:INRUSD", "CURRENCY:EURUSD",
]
etfTickers = [
"NYSEARCA:XLF", "NYSEARCA:IWM", "NYSEARCA:EEM", "NASDAQ:QQQ", "NYSEARCA:VWO", "NYSEARCA:EFA",
"NYSEARCA:FXI", "NYSEARCA:XLI", "NYSEARCA:TZA", "NYSEARCA:XLE", "NYSEARCA:SDS", "NYSEARCA:SLV",
"NYSEARCA:FAZ", "NYSEARCA:GDX", "NYSEARCA:EWJ", "NYSEARCA:SPXU", "NYSEARCA:EWZ", "NYSEARCA:FAS",
"NASDAQ:TVIX", "NYSEARCA:USO", "NYSEARCA:GLD", "NYSEARCA:TBT", "NYSEARCA:UNG",
]
table = get_close_price_table(
currencyTickers + etfTickers, interpolation=True, period='1Y',
)
print(table.head())
assert(len(table) > 0)
8 changes: 2 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@
envlist =
clean,
check,
{py27,py33,py34,py35,py36,pypy},
{py36},
report,
docs
skip_missing_interpreters = True

[testenv]
basepython =
pypy: {env:TOXPYTHON:pypy}
{py27,docs,spell}: {env:TOXPYTHON:python2.7}
py33: {env:TOXPYTHON:python3.3}
py34: {env:TOXPYTHON:python3.4}
py35: {env:TOXPYTHON:python3.5}
py36: {env:TOXPYTHON:python3.6}
{bootstrap,clean,check,report,coveralls,codecov}: {env:TOXPYTHON:python3}
setenv =
Expand All @@ -25,6 +20,7 @@ passenv =
*
usedevelop = false
deps =
-r{toxinidir}/requirements.txt
pytest
pytest-travis-fold
pytest-cov
Expand Down

0 comments on commit a4f0493

Please sign in to comment.