Commit Graph

661 Commits (519d459dbe86114cfb0f2d04016c63799a112e42)

Author SHA1 Message Date
Tyler Goodlet fcaeeae618 Acquire symbol data with daemon; push as first response 2018-05-09 18:09:04 -04:00
Tyler Goodlet 3d6b14ec3f Pass in the host addr 2018-05-08 15:07:13 -04:00
Tyler Goodlet a2c4f0c80b Don't recurse in Client.aiter_recv() 2018-04-22 12:48:35 -04:00
Tyler Goodlet 6a6f773477 Adjust some log levels 2018-04-20 13:18:35 -04:00
Tyler Goodlet 063dfad5b4 Make daemon registry cross-task 2018-04-20 13:18:35 -04:00
Tyler Goodlet 4f387ea2be Fix subscriptions and connection handling
Oh boy where to start.

- Handle broken streams in the `StreamQueue` gracefully; terminate the
  async generator.
- When a stream queue connection is unwritable discard its subscriptions
  inside the quoter task
- If all subscriptions are discarded for a broker then tear down its
  quoter task
- Use listener parent nursery for spawning quoter tasks
- Make broker subs data structures global/shared between conn
  handler tasks
- Register the `tickers2qs` entry *after* instantiating broker client(s)
  (avoids race condition when mulitple client connections are coming
  online simultaneously)
- Push smoke quotes to every client not just the first that connects
- Track quoter tasks in a cross-task set
- Handle unsubscriptions more correctly
2018-04-20 13:18:35 -04:00
Tyler Goodlet 90e8dd911c Daemon main doesn't require brokermod anymore 2018-04-20 13:18:35 -04:00
Tyler Goodlet 17feb17535 Add a reliable `Client` API
In order to start working toward a HA distributed
architecture make apps use a `Client` type to talk to daemons.
The `Client` provides fault-tolerance for connection failures such
that the app will continue running until a connection to the original
service can be made or the process is killed. This will make it easier
to simply spawn up new daemon child processes when faults are detected.
2018-04-20 13:18:35 -04:00
Tyler Goodlet 51b44cf236 Use msgpack for quote-packet serialization 2018-04-20 11:43:14 -04:00
Tyler Goodlet dd5e1e7ea7 Doh, set sleeptime after adjusting the rate limit 2018-04-20 11:43:14 -04:00
Tyler Goodlet 030ecdcce8 Filter symbols and push initial quote in stream handler
Filter out bad symbols by processing an initial batch quote and
pushing to the subscribing client before spawning a quoter task.
This also avoids exposing the quoter task to anything but the
broker module and a `get_quotes()` routine.
2018-04-20 11:43:14 -04:00
Tyler Goodlet 02a71c51ba Make <brokermod>.quoter() a simple factory func 2018-04-20 11:43:14 -04:00
Tyler Goodlet 0c7ecd383b Monkey patch broker mods with a name attr 2018-04-20 11:43:14 -04:00
Tyler Goodlet 6359623019 Allow broker specific subscriptions
Allow client connections to subscribe for quote streams from specific
brokers and spawn broker-client quoter tasks on-demand according
to client connection demands. Support multiple subscribers to a
single daemon process.
2018-04-20 11:43:14 -04:00
Tyler Goodlet f80735121c Use an async generator inside `StreamQueue`
Async generators are faster and less code. Handle segmented packets
which can happen during periods of high quote volume. Move per-broker
rate limit logic into daemon task.
2018-04-20 11:43:14 -04:00
Tyler Goodlet 23ae71089f Handle dynamic symbol subscriptions in QT backend 2018-04-20 11:42:59 -04:00
Tyler Goodlet d65bd78f5d Add a quote stream server task
Add a daemon-server task for delivering subscription based
quote streams via json serialized packets wrapped in a queue
interface.
2018-04-16 02:03:22 -04:00
Tyler Goodlet 0cccdd01b5 Only log when the network first goes down 2018-04-05 23:15:24 -04:00
Tyler Goodlet e246823f2d Add timeout handling to network poll loop 2018-04-02 14:51:38 -04:00
Tyler Goodlet 01cfbbdd64 Handle network outages
Quote queries will hang indefinitely when the network goes down.
Instead poll for network reestablishment such that roaming on
wifi is supported and real-time feeds will resume once the network is
back.
2018-03-31 12:02:22 -04:00
Tyler Goodlet 164d636c67 Handle defunct QT tickers and delays 2018-03-29 13:01:13 -04:00
Tyler Goodlet 823bd2ea29 Make payload a ticker dict 2018-03-29 13:00:48 -04:00
Tyler Goodlet 8544c22cdc Change `Client.symbols()` to `symbol_data()`
Make `symbol_data()` a common backend API method for looking up
auxiliary ticker/symbol data from brokers. It seems most have such
a call/endpoint.
2018-03-27 16:24:57 -04:00
Tyler Goodlet 8fc74c5085 Drop QT error 2018-03-27 16:16:31 -04:00
Tyler Goodlet 49d290d036 Add brokermod loader utils 2018-03-27 16:03:01 -04:00
Tyler Goodlet 29ddfe017c Use total time calc 2018-03-23 16:15:56 -04:00
Tyler Goodlet 200526da8a Query QT at most 3 quotes/sec to avoid rate limits 2018-03-21 17:28:26 -04:00
Tyler Goodlet 933fe980c1 Set default quote rate to 5/sec 2018-03-21 17:27:04 -04:00
Tyler Goodlet 6b47130c77 Move quote formatting to broker backends 2018-03-21 10:30:43 -04:00
Tyler Goodlet 48fe280e0c Return None on failed symbol lookups 2018-03-20 21:01:55 -04:00
Tyler Goodlet 04fa3c7ca4 Factor out QT quoting specifics into the backend 2018-03-20 15:39:49 -04:00
Tyler Goodlet e75f0718a5 Add a basic quotes-only robinhood backend
We need a yank to test the order system and other end points that
require auth.

Resolves #2
2018-03-20 13:26:12 -04:00
Tyler Goodlet bd7eb16ab2 Move core tasks to separate module
Begin abstracting out broker backends by moving core data query tasks
into a module which requires and calls a broker backend API.
2018-03-20 13:13:07 -04:00
K0nstantine 61206f5903 Fix issue where config dir was not created by default
Fixes #15
2018-03-05 19:15:10 -05:00
Tyler Goodlet 80ee1bfc19 Poll at 3 r/s and add more detailed timing logs 2018-03-02 21:24:09 -05:00
Tyler Goodlet 13e4389c9f Handle expired tokens more reliably; trace log json data 2018-02-22 18:44:46 -05:00
Tyler Goodlet ff437ce9e1 Handle out of process token refreshes 2018-02-15 16:40:33 -05:00
Tyler Goodlet b41b262b7d Raise any unexpected error 2018-02-14 18:49:58 -05:00
Tyler Goodlet 29be7f58c9 Push every new change; not just the last trade 2018-02-13 15:57:12 -05:00
Tyler Goodlet 62bac7b2cd Don't sleep on less than zero delay 2018-02-13 12:13:27 -05:00
Tyler Goodlet b7b7abbc1f Only push new quotes to the queue at 5 per sec 2018-02-12 14:03:31 -05:00
Tyler Goodlet 488f3988ea Handle weekend errors 2018-02-10 19:44:41 -05:00
Tyler Goodlet e220e9b658 Move cli mod to top level package 2018-02-09 03:01:58 -05:00
Tyler Goodlet 17c4ac3b8c Adjust cli to new api 2018-02-08 19:15:21 -05:00
Tyler Goodlet 224451f44a Make ticker stream caching optional
Push all ticker quotes to the queue regardless of duplicate
content. That is, don't worry about only pushing new quote changes
(turns out it is useful when coloring a watchlist where multiple
of the same quote may indicate multiple similar trades and we only
want to quickly "pulse" color changes on value changes).
If it is desired to only push new changes, the ``cache`` flag enables
the old behaviour.

Also add `Client.symbols()` for returning symbol data from a sequence of
tickers.
2018-02-08 19:10:17 -05:00
Tyler Goodlet 6781a23850 Add a `quote` subcommand
Add `piker quote <tickerA> <tickerB> <tickerC>` command for easily
dumping quote data to the console. With `-df` will dump as a pandas data
frame. Add key filtering to `piker api` calls.
2018-02-08 02:39:18 -05:00
Tyler Goodlet adecc082ac Save `brokers.ini` in the user config dir using click 2018-02-08 02:39:18 -05:00
Tyler Goodlet 151e7bf4fa More client enhancements
- Extend the qt api to include candles (not working yet), balances, positions.
- Add a `quote()` method to the `Client` for batch ticker quotes and expose
  it through a CLI subcommand.
- Make `poll_tickers` push new quotes to a `trio.Queue`
2018-02-08 02:39:18 -05:00
Tyler Goodlet 797efedf6a Add quote polling; pseudo-streaming
Add a ``poll_tickers`` coro which can be used to "stream" quotes at
a requested rate. Expose through a cli subcommand `piker stream`.
Drop the `pikerd` command for now.
2018-01-29 12:45:48 -05:00
Tyler Goodlet 66441d15e8 Complain when kwargs are missing but required 2018-01-27 01:52:00 -05:00
Tyler Goodlet 1b93a4c02a Add an `api` cli subcommand for console testing
Add `piker api <method> <kwargs>` for easy testing of the
underlying broker api from the console.
2018-01-26 14:31:15 -05:00
Tyler Goodlet 27a39ac3ad More client improvements
- colorize json response data in logs
- support ``refresh_token`` retrieval from user if the token for some
  reason expires while the client is live
- extend api method support for markets, search, symbols, and quotes
- support "proxying" through api calls via an ``api`` coro for one off
  client queries (useful for cli testing)
2018-01-26 14:25:53 -05:00
Tyler Goodlet 9e8ed392d4 Add token refresher task 2018-01-25 21:53:55 -05:00
Tyler Goodlet 4e1c64a7fb Import broker backend by name 2018-01-25 21:08:49 -05:00
Tyler Goodlet 5c4996873a Start using click for cli 2018-01-25 20:56:57 -05:00
Tyler Goodlet 1b0269e51a Drop `Client.from_config()` factory - more cleanups 2018-01-25 20:56:57 -05:00
Tyler Goodlet e45cdf92f0 Log entire access config on exit 2018-01-25 20:56:57 -05:00
Tyler Goodlet 570d879146 Save tokens locally for use across runs
Store tokens in a local config file avoiding any refresh delay
unless necessary when the current access token expires.

Summary:
- move draft main routine into the `brokers` package mod
- start an api wrapper type
- always write the current access tokens to the config on teardown
2018-01-22 22:05:42 -05:00
Tyler Goodlet e312fb6525 Add config for saving access creds between runs 2018-01-22 22:05:42 -05:00
Tyler Goodlet 9745e16cf2 Drop userdata; use a dict 2018-01-22 22:05:42 -05:00
Tyler Goodlet 5a6b7510f8 Initial user account access using trio + asks 2018-01-22 22:05:42 -05:00