Git Product home page Git Product logo

stocklook's Introduction

stocklook

A collection of utilities for working with cryptocurrency APIs.

Goal: Painless automated spread and target trading, account management, and data analysis.

APIs:

  • BitMex (stocklook.crypto.bitmex): trading, account management, websocket feed
  • Bittrex (stocklook.crypto.bittrex): account management, buy/sell
  • blockchain.io (stocklook.crypto.bitcoin): BTC blockchain stats
  • blockcypher.com (stocklook.crypto.etherium): ETH blockchain stats
  • CoinBase (stocklook.crypto.coinbase_api): account management, buy/sell
  • CoinMarketCap (stocklook.crypto.coinmarketcap): price history, market stats
  • Cryptopia (stocklook.crypto.cryptopia): price history, buy/sell, market stats
  • Gdax (stocklook.crypto.gdax): trading, account management, price history, websocket feed
  • Poloniex (stocklook.crypto.poloniex): price history
  • Twitter (stocklook.apis.twitah): tweet scanning
  • Yahoo Finance (broken): price history

Examples

Accessing Coinbase to view accounts:

from stocklook.crypto.coinbase_api import CoinbaseClient

c = CoinbaseClient()

# method 1 - access accounts via coinbase library
obj = c.get_accounts()
accounts = obj.response.json['data']
for account in accounts:
    print("{}: {}".format(account['currency']: account['id'])

# method 2 - parses accounts into dictionary upon access.
usd_account = c.accounts['USD']

Accessing Gdax to buy some coin:

from stocklook.crypto.gdax import Gdax, GdaxOrder

g = Gdax()
g.deposit_from_coinbase('USD', 100)

o = GdaxOrder(g, 'LTC-USD', order_type='market', amount=100)
o.post()

Market making spreads on Gdax:

from stocklook.crypto.gdax.market_maker import GdaxMarketMaker

m = GdaxMarketMaker(product_id='ETH-USD',
                    min_spread=0.10,
                    max_spread=0.30,
                    max_buy_orders=10,
                    max_sell_orders=30,)
m.run()

Accessing Poloniex chart data:

# In progress

Configuration:

Configuration variables are stored in global variable stocklook.config.config(dict). User input may be required on Object initialization to figure out credentials unless they've been previously cached or added to this dictionary. Passwords & secrets are always cached safely using the keyring library.

Update os.environ with the following credentials to have them auto-update config:

  • coinbase: COINBASE_KEY
  • poloniex: POLONIEX_KEY
  • GDAX: GDAX_KEY
  • GMAIL: STOCKLOOK_EMAIL

You can update global configuration like so:

from stocklook.config import update_config, config
my_config = {
    'DATA_DIRECTORY': 'C:/Users/me/stocklook_data'
    'COINBASE_KEY': 'mycoinbasekey',
    'COINBASE_SECRET': 'mycoinbasesecret',
    'GDAX_KEY': 'mygdaxkey',
    'GDAX_SECRET': 'mygdaxsecret',
    'GDAX_PASSPHRASE': 'mygdaxpassphrase',
    'GMAIL_EMAIL': '[email protected]',
    'GMAIL_PASSWORD': 'mygmailpassword',
    'LOG_LEVEL': logging.DEBUG,
    'PYTZ_TIMEZONE': 'US/Pacific',

    # SQLAlchemy URL kwargs
    'GDAX_FEED_URL_KWARGS': {
                            'drivername': 'mysql+pymysql',
                            'host': 'localhost',
                            'port': None,
                            'username': 'dbuser',
                            'password': 'dbpass',
                            'database': 'dbname'
                           },
}

# method 1
update_config(my_config)

# method 2 (same as method 1)
config.update(my_config)

To-do List:

  • [] Add tests for gdax, coinbase
  • [] fix yahoo api
  • [] add Poloniex account management code

stocklook's People

Contributors

zbarge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stocklook's Issues

OHLC alerts

Would like to alert user(s) when OHLC criteria have been hit. RSI, MACD, volume/price, etc.

make market maker order placement more efficient

need to ensure that placing a GdaxMMOrder requires 1 call to API (the post) and that we can efficiently grab (or ascertain) our order status from the GdaxBookFeed with limited/no extra calls to API.

Update Gdax API for CoinbasePRO

I don't know what on the API has changed but this issue will be open until it's confirmed that the Gdax API still runs properly.

Cross-exchange OHLC management

We need to read, write, analyze, and assign tasks based on OHLC data.

Fields

  • Open
  • High
  • Low
  • Close
  • Volume
  • Time
  • ExchangeID

I/O Formats

  • API (json) (in only)
  • .csv
  • sqlalchemy

Timeframes
Ideal scenario is making the root data set 5 minute candles that can flexibly transform to 15, 1hr, 4hr, daily candles. Most exchanges have downtime so we'd need to be able to smooth over gaps in time between candles using this scenario.

2nd scenario is downloading separate sets of data from API for each time frame, then updating the data source(s) with new data as it became available. On an interval we'd check what data we have, request new data to get us current, then update data.

Abstraction

  • Make hook system for exchange objects to register formats and methods.
    • Time Conversion to UTC integer
    • Method to request new data (as pandas.dataframe)
    • Field name mapping to 'open', 'high', 'low', 'close', 'volume'
    • Max span of 5 minute candles that can be requested at once
    • Number of requests allowed per second.

Task Management
A user should be able to register OTask objects to the OHLC management system.

OTask object requirements:

  1. Be able to run concurrently with other tasks.
  2. Accept OHLC data in a pandas.DataFrame for one or more product/exchanges
  3. Carry properties to store last run and trigger timestamps
  4. Generate signals when triggered

Example Task:
Calculate 5min, 1min, 4hr RSI and moving averages
If any indicator falls within a certain threshold send an alert to an email address.

Example Process Flow

  1. Check data storage for newest data
    • If no data: begin a data accumulation process going back X (3-6?) months.
    • If data is current: do nothing
    • If some data missing - request new data for missing timespan
  2. Format new data and append to data storage(s)
  3. Process registered tasks on data

Universal Exchange Object

We need to have a Universal Exchange Object with methods to access exchange data and operations universally. This isn't a new problem so I will likely borrow ideas or code from another project...

Requirements

  1. Defined standards for product names. BTC-USD on gdax may be BTC_USDT on poloniex so each exchange will need to register supported product names to a universal name like BTC_USD.
  2. Standardized methods to buy/sell/cancel, check balance, retrieve OHLC data

OHLC database storage

Design a good database storage system for OHLC.

key features:

  • All time series data stored in 5min timeframe
  • Smoothing over missing time stamps
  • Indicators to the latest bar (I notice RSI is blank going back X periods and we need RSI of NOW)
  • Times stored as UTC integer but accessible with timestamps

GdaxMarketMaker: make customizeable order targets

currently aggressive spreads quote the minimum spread considering other prices.

Even aggressively the current logic misses out on many opportunities to trade very tight spreads.
0.01 - .05 on ETH for example may generate multiple trades in seconds. In low volatility market environments this this trade could be repeated over and over while deeper trades could follow standard minimum spreads considering other order prices. This will in theory increase profitability especially when there are bid or ask walls with small ranges that are inside of the GdaxMarketMaker minimum spread.

We need carefully planned logic for the above.

  • We should only have 1-2 trades within a tightened range and using a larger account size than normal.

  • These trades need specific buy and sell targets that do not change... so the order needs to be locked at the price. (maybe) An order can be unlocked and changed only when a wall has moved in front of the price but it should maintain a 0.01 minimum profit.

  • The GdaxMarketMaker.handle_fill method should recognize and quickly place opposite orders in the tightened spread range...

  • This method should probably exist on the GdaxMMOrder in case multiple methods need to re-use the logic and most of the work happens on the GdaxMMOrder.price and the GdaxMarketMaker.ticker_price.

  • This method needs to consider market volatility before determining prices. There are times when ETH has a .30+ spread so we need to really act based on the closest bid and ask on the most recent data every time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.