Commit Graph

661 Commits (519d459dbe86114cfb0f2d04016c63799a112e42)

Author SHA1 Message Date
Konstantine Tsafatinos b21bbf5031 valdiate and ack order requests from ems 2022-03-06 15:17:26 -05:00
Konstantine Tsafatinos 66da58525d mock orders validated from kraken 2022-03-06 15:17:26 -05:00
Konstantine Tsafatinos b55debbe95 get basic order request loop receiving msgs 2022-03-06 15:17:26 -05:00
Konstantine Tsafatinos 1fe1f88806 added the bones for the handle_order_requests func 2022-03-06 15:17:26 -05:00
Konstantine Tsafatinos 3d2be3674e save progress on kraken to test out unit_select_fixes 2022-03-06 15:17:26 -05:00
Konstantine Tsafatinos 48c7b5262c get positions working for kraken 2022-03-06 15:17:26 -05:00
Konstantine Tsafatinos ef598444c4 get positions from trades 2022-03-06 15:17:26 -05:00
Konstantine Tsafatinos 0285a847d8 Store changes for rebase, positions prototype 2022-03-06 15:17:26 -05:00
Konstantine Tsafatinos 88061d8799 Add balance to the ledger 2022-03-06 15:17:26 -05:00
Konstantine Tsafatinos e12af8aa4c Add get_ledger function; parses raw ledger from kraken api 2022-03-06 15:17:26 -05:00
Konstantine Tsafatinos 184edb2a90 wrap api method calls with uri and nonce value 2022-03-06 15:17:26 -05:00
Konstantine Tsafatinos b88dd380a3 get kraken authentication and retrieve balances 2022-03-06 15:17:26 -05:00
Tyler Goodlet 01f5f2d015 Don't require a rt quote, increase client connect timeout 2022-03-03 17:49:21 -05:00
Tyler Goodlet 832e4c97d2 Drop shm: ShmArray` to `stream_quotes()` endpoint 2022-02-28 08:23:16 -05:00
Tyler Goodlet ca1c1cf415 Annoying doc strings 2022-02-11 10:30:30 -05:00
wattygetlood cc87508fd9 Only load 4 ib requests worth of bars on windows... 2022-02-10 10:26:52 -05:00
Tyler Goodlet e3c46a5d4d Add draft, commented tickbytick for ib 2022-02-07 12:53:30 -05:00
Tyler Goodlet 26b0071471 Subscribe for rate calcs from IB in default tick set 2022-02-07 12:53:30 -05:00
Tyler Goodlet 9bfad86c29 Drop timeout-cancel block 2022-02-07 09:49:45 -05:00
Tyler Goodlet a9d42b374f ib: Allow history backfilling even when markets are closed 2022-02-07 09:49:45 -05:00
Tyler Goodlet bb8fade16f Update `msgpub` import from `tractor.experimental` 2022-01-30 12:46:54 -05:00
Tyler Goodlet 95b31cbc0f Drop references to deprecated `tractor.msg.pub` 2022-01-29 12:44:45 -05:00
Tyler Goodlet 55cfe6082b Re-key ib's 'unreportable trades' (tick 48) as 2022-01-26 13:48:21 -05:00
Tyler Goodlet d27214621d Update some typing and add latency checks for binance 2022-01-25 07:57:01 -05:00
Tyler Goodlet 746db60e5b Increases IB api connect timeout to 1s 2022-01-23 18:18:10 -05:00
Tyler Goodlet fc3baf4bd1 Bump timeout up 2022-01-23 18:18:10 -05:00
Tyler Goodlet f1d61ac01b WIP ib: toying with showing history before first quote 2022-01-23 18:18:10 -05:00
Tyler Goodlet d69d3b319e Lengthen startup quote get timeout 2022-01-23 18:18:10 -05:00
Tyler Goodlet 0e4a7e3846 Only warn on slow quote query 2022-01-23 18:18:10 -05:00
Tyler Goodlet 24596022f9 Wait for a last price tick before delivering quote 2021-10-29 09:31:06 -04:00
Tyler Goodlet af0503956a Use `tractor.to_asyncio.open_channel_from()` in ib backend 2021-10-29 09:26:42 -04:00
Tyler Goodlet 1416d4e6ac Add actor wide client ignore set, increase history retreival to 24 requests 2021-10-29 09:25:41 -04:00
Tyler Goodlet eca9b14cd6 Add (list of) `hosts` support in config and better scan error msg 2021-10-29 09:20:52 -04:00
Tyler Goodlet b04645aa47 Expect `accounts: set[str]` startup msg through clearing system 2021-09-14 10:36:13 -04:00
Tyler Goodlet eb70baf161 Pass account names on wire: brokerd => emsd 2021-09-13 08:24:45 -04:00
Tyler Goodlet 6acfd6c38a Ugh, positions relay hotfix
Must have run into some confusion with data structures in `brokerd` vs.
`emsd`. This fixes the ems `relay.positions` state tracking to be
composed maps, vs. messages from `brokerd` should just be a sequence.
2021-09-12 19:30:43 -04:00
Tyler Goodlet d25aec53e3 Append pp values per account during startup on ib 2021-09-10 11:36:46 -04:00
Tyler Goodlet c53b8ec43c Make `ib` backend multi-client capable
This adds full support for a single `brokerd` managing multiple API
endpoint clients in tandem. Get the client scan loop correct and load
accounts from all discovered clients as specified in a user's
`broker.toml`. We now just always re-scan for all clients and if there's
a cache hit just skip a creation/connection logic.

Route orders with an account name to the correct client in the
`handle_order_requests()` endpoint and spawn an event relay task per
client for transmitting trade events back to `emsd`.
2021-09-09 08:07:11 -04:00
Tyler Goodlet dedfb27a3a Add per-account order entry for ib
Make the `handle_order_requests()` tasks now lookup the appropriate API
client for a given account (or error if it can't be found) and use it
for submission. Account names are loaded from the
`brokers.toml::accounts.ib` section both UI side and in the `brokerd`.
Change `_aio_get_client()` to a `load_aio_client()` which now tries to
scan and load api clients for all connections defined in the config as
well as deliver the client cache and account lookup tables.
2021-09-08 15:55:45 -04:00
Tyler Goodlet 2bc07ae05b Try explicit matches of symbol to our adhoc set for pp msgs 2021-09-07 09:22:56 -04:00
Tyler Goodlet 15025d6047 Move config module to top level 2021-09-06 21:26:28 -04:00
Tyler Goodlet c86c4218ce Allow blank accounts config 2021-09-06 09:28:11 -04:00
Tyler Goodlet 34d4d098d2 Add silver futes 2021-09-06 09:28:11 -04:00
Tyler Goodlet 28b6882725 Slapp in exchange suffix position msg key; avoid symbol aliasing on `in` check 2021-09-06 09:28:11 -04:00
Tyler Goodlet 15fc66f0a9 Add config account loader 2021-09-06 09:28:10 -04:00
Tyler Goodlet 6be6f25797 Add "crypto" type to binance and kraken symbols 2021-09-06 09:28:10 -04:00
Tyler Goodlet 908678da84 Add more futes, add in order status comments 2021-09-05 13:59:40 -04:00
Tyler Goodlet d3838c2a8b Use built-in type generics 2021-09-02 12:55:10 -04:00
Tyler Goodlet eb5762d912 Add adhoc-symbols search for ib
This gives us fast search over a known set of symbols you can't search
for with the api such as futures and commodities contracts.

Toss in a new client method to lookup contract details
`Client.con_deats()` and avoid calling it for now from `.search_stock()`
for speed; it seems originally we were doing the 2nd lookup due to weird
suffixes in the `.primaryExchange` which we can just discard.
2021-09-02 10:55:37 -04:00
Tyler Goodlet 3dad779c90 Add commented catch to skip backpressure errors wen debugging 2021-09-01 10:26:49 -04:00
Tyler Goodlet d940957455 Support account passthrough in `.submit_limit()` 2021-09-01 10:26:49 -04:00
Tyler Goodlet ffbfd187ad Raise cache miss on a disconnected ib client 2021-09-01 10:26:49 -04:00
Tyler Goodlet c6aa867c9b Add more futes, add in order status comments 2021-09-01 10:26:49 -04:00
Tyler Goodlet fe0d66e847 Drop removed module import 2021-08-26 17:04:59 -04:00
Tyler Goodlet 310d8f485e Add disclaimer to old data mod 2021-08-26 17:04:59 -04:00
Tyler Goodlet 68ce5b3550 Add lifo cache to new module; drop "utils", bleh 2021-08-26 17:04:59 -04:00
Tyler Goodlet a0660e553f Start top level cacheing apis module 2021-08-26 17:04:59 -04:00
Tyler Goodlet 89b2089562 Fixup missing ib section handling; drop `.api` subsection 2021-08-24 10:27:25 -04:00
Tyler Goodlet d5394ac677 Fix TWS triggered trades msg packing 2021-08-24 10:26:41 -04:00
Tyler Goodlet a10d20c041 Add ib config section support 2021-07-27 07:09:01 -04:00
Tyler Goodlet 9c24bb6480 Make json resp log debug level 2021-07-07 07:07:01 -04:00
Tyler Goodlet 588b5c317c Drop unseralizable "sec tag" for now 2021-06-14 00:02:23 -04:00
Tyler Goodlet 95f466b93d Fix to msg attr access 2021-06-10 12:02:26 -04:00
goodboy 689bc0cde0
Merge pull request #190 from pikers/ems_to_bidir_streaming
Ems to bidir streaming
2021-06-10 08:45:44 -04:00
Tyler Goodlet a9cbacd8aa Move details assignements to static declaration 2021-06-10 08:24:51 -04:00
Tyler Goodlet 8e8a005128 Fix attr accesses on msg type 2021-06-09 12:22:02 -04:00
Konstantine Tsafatinos 90e5a10a66 modify error string to format: <name>.<provider> 2021-06-09 12:02:05 -04:00
Tyler Goodlet db92683ede Port ib orders to new msgs and bidir streaming api 2021-06-08 14:33:41 -04:00
Tyler Goodlet 02459cd964 Use new top level portal import 2021-06-08 14:31:14 -04:00
Konstantine Tsafatinos 099bf260f5 fix unknown kraken symbol raised error 2021-06-01 18:01:45 -04:00
Tyler Goodlet 9792b9aa7d Drop search pause config; use default 2021-05-28 14:11:02 -04:00
Tyler Goodlet 51a8308105 Lower connection timeout duration 2021-05-28 14:11:02 -04:00
Tyler Goodlet ff856a6ee3 Woops, make unsub pairs a list 2021-05-28 14:11:02 -04:00
Tyler Goodlet 19711bf024 Reconnect slow binance conns instead of error 2021-05-28 14:11:02 -04:00
Tyler Goodlet d0e3f5a51c Port binance and kraken to "reliable" ws API 2021-05-28 14:11:02 -04:00
Tyler Goodlet 7fa9f3f542 Add `Client.search_symbols()` to all backends, use it in `piker search` 2021-05-28 12:29:58 -04:00
Tyler Goodlet e88e5b8ce2 Decrease binance search debounce period 2021-05-27 13:05:23 -04:00
Tyler Goodlet 3e39e9620c Add a no data available error 2021-05-27 13:05:23 -04:00
Tyler Goodlet 44f4fdf043 Type annot the internal symbol cache 2021-05-27 13:05:23 -04:00
Tyler Goodlet 27d704b32e To avoid feed breakage, just give up on history after too many throttles for now 2021-05-27 13:05:23 -04:00
Tyler Goodlet a4627c2b04 Send blank packet on no match to avoid blocking search stream 2021-05-27 13:05:23 -04:00
Tyler Goodlet ddc2c8975a Ignore whitespace patterns in ib search 2021-05-27 13:05:23 -04:00
Tyler Goodlet c9311dd7d0 Few more derivs symbols 2021-05-27 13:05:23 -04:00
Tyler Goodlet 6f3b799960 Skip ib exchanges we haven't tested yet 2021-05-27 13:05:23 -04:00
Tyler Goodlet fd8dc4f1a3 Make -b a multi-option for backends 2021-05-27 13:05:23 -04:00
Tyler Goodlet bbd5883e52 Add search pause configs to backends 2021-05-27 13:05:23 -04:00
Tyler Goodlet e5e9a7c582 Add symbol searching for ib backend
Obviously this only supports stocks to start, it looks like we might
actually have to hard code some of the futures/forex/cmdtys that don't
have a search.. so lame. Special throttling is added here since the api
will grog out at anything more then 1Hz.

Additionally, decouple the bar loading request error handling from the
shm pushing loop so that we can always recover from a historical bars
throttle-error even if it's on the first try for a new symbol.
2021-05-27 13:05:22 -04:00
Tyler Goodlet ef1b0911f3 Add symbol search to ib 2021-05-27 13:05:22 -04:00
Tyler Goodlet 82a8e0a7b6 Accept lower case sym requests in kraken backend 2021-05-27 13:05:22 -04:00
Tyler Goodlet ad494db213 Make search routine a tractor context 2021-05-27 13:05:22 -04:00
Tyler Goodlet 4b818ea2f2 Add initial symbol search api for kraken 2021-05-27 13:05:22 -04:00
Tyler Goodlet c26f4d9877 Add kraken fuzzy symbol search 2021-05-27 13:05:22 -04:00
Tyler Goodlet 27aed85404 Handle no matching symbols case 2021-05-27 13:05:22 -04:00
Tyler Goodlet 9cad59366f Extract min tick info from symbol data 2021-05-25 08:46:10 -04:00
Tyler Goodlet 165d6257fa Get symbol search working for binance 2021-05-25 08:46:04 -04:00
Tyler Goodlet 7b8c482719 Add reconnect logic help link 2021-05-24 12:16:49 -04:00
goodboy 372b0dbace
Merge pull request #170 from guilledk/binance_backend
Add Binance backend
2021-05-24 10:54:55 -04:00
Tyler Goodlet b6d8c300d4 Slap in brokers.toml template if none exists 2021-05-22 15:11:39 -04:00
Guillermo Rodriguez a0dfdd935f
Post @goodboy review commit 2021-05-21 22:23:35 -03:00
Tyler Goodlet 7b26bd45e2 Get binance OHLC history and quote format correct
This gets the binance provider meeting the data feed schema requirements
of both the OHLC sampling/charting machinery as well as proper
formatting of historical OHLC history.

Notably,
- spec a minimal ohlc dtype based on the kline endpoint
- use a dataclass to parse out OHLC bar datums and pack into np.ndarray/shm
- add the ``aggTrade`` endpoint to get last clearing (traded) prices,
  validate with ``pydantic`` and then normalize these into our tick-quote
  format for delivery over the feed stream api.
- a notable requirement is that the "first" quote from the feed must
  contain a 'last` field so the clearing system can start up correctly.
2021-05-21 15:35:36 -04:00
Tyler Goodlet 2ef5a52521 Fix broken import in ib backend 2021-05-20 19:34:45 -04:00
Guillermo Rodriguez 432bd96474
Added missing toml dependency to setup.py
Pinned qdarkstyle to 2.8.1
Updated arrow timestamp api used in kraken backend
2021-05-16 18:53:54 -03:00
Guillermo Rodriguez 604e195bc0
Got rid of websocket OHLC API, and added l1 tick streaming 2021-05-07 10:59:08 -03:00
Guillermo Rodriguez 7e493625f6
Finally backfilling is working, still need to work on realtime updates! 2021-05-05 10:17:52 -03:00
Guillermo Rodriguez d327584039
Rough translation of kraken backend to binance API, still missing some
important parts
2021-05-04 22:52:53 -03:00
Tyler Goodlet 3375735914 Port kivy monitor to new tractor stream api 2021-04-29 09:10:11 -04:00
Tyler Goodlet 7d6bc4d856 Move feed api(s) into new submodule
Also add a --pdb flag to chart app.
2021-04-15 10:43:29 -04:00
Tyler Goodlet ddae08493b Manage the send mem chan lifetime 2021-04-10 14:18:40 -04:00
Tyler Goodlet 5a970dad72 Port kraken backend to new data feed api 2021-04-10 14:18:40 -04:00
Tyler Goodlet 24bda8636e Port quest to new client api 2021-04-10 14:18:40 -04:00
Tyler Goodlet 1d013126b9 Fix type annot 2021-04-10 14:18:40 -04:00
Tyler Goodlet b2eacb85d4 Don't hold lock on initial client construction 2021-04-10 14:18:40 -04:00
Tyler Goodlet 5fc2aba3ed Drop some more old cruft 2021-04-10 14:18:40 -04:00
Tyler Goodlet a82f43e3a5 Rework data feed API to allow for caching streams
Move all feed/stream agnostic logic and shared mem writing into a new
set of routines inside the ``data`` sub-package. This lets us move
toward a more standard API for broker and data backends to provide
cache-able persistent streams to client apps.

The data layer now takes care of
- starting a single background brokerd task to start a stream for as
  symbol if none yet exists and register that stream for later lookups
- the existing broker backend actor is now always re-used if possible
  if it can be found in a service tree
- synchronization with the brokerd stream's startup sequence is now
  oriented around fast startup concurrency such that client code gets
  a handle to historical data and quote schema as fast as possible
- historical data loading is delegated to the backend more formally by
  starting a ``backfill_bars()`` task
- write shared mem in the brokerd task and only destruct it once requested
  either from the parent actor or further clients
- fully de-duplicate stream data by using a dynamic pub-sub strategy
  where new clients register for copies of the same quote set per symbol

This new API is entirely working with the IB backend; others will need
to be ported. That's to come shortly.
2021-04-10 14:18:40 -04:00
Tyler Goodlet f17a26c948 Don't mistakenly alias options to underlyingn for positions 2021-04-10 14:18:40 -04:00
Tyler Goodlet 0d4073dbd2 Move quote stream setup into a cacheing func 2021-04-10 14:18:40 -04:00
Tyler Goodlet aa61bf5a65 Use mem-chans for quote streams; clone for multiple consumers 2021-04-10 14:18:40 -04:00
Tyler Goodlet 6265ae8057 Add position event relay to ib broker backend 2021-03-11 21:38:31 -05:00
Tyler Goodlet 2cabe1831c Attempt to handle existing order updates with ib backend 2021-03-06 16:33:56 -05:00
Tyler Goodlet 8997b6029b Drop cruft 2021-03-01 12:02:07 -05:00
Tyler Goodlet 72c4a4366b Tag TWS trade events 2021-03-01 12:01:48 -05:00
Tyler Goodlet 1142a538ea Don't forward errors without an order id 2021-02-22 10:45:01 -05:00
Tyler Goodlet e6ea053d40 Get kivy/questrade shit working again 2021-02-21 12:32:40 -05:00
Tyler Goodlet add63734f1 Add an auto-reconnect websocket API 2021-02-19 18:42:50 -05:00
Tyler Goodlet bbd54e8f95 Report asset types, tick sizes, and order actions from ib 2021-02-19 17:23:37 -05:00
Tyler Goodlet 0c184b1b41 Port ib to new provide new tick size fields in symbol info 2021-02-06 14:37:24 -05:00
Tyler Goodlet 69df73afc3 Deliver symbol info from kraken; start using pydantic 2021-02-06 14:23:27 -05:00
Tyler Goodlet 708086cbcb Convert contractsto dicts on errors 2021-01-26 13:34:49 -05:00
Tyler Goodlet b4a4f12aa4 Send init message with kraken 2021-01-22 22:55:49 -05:00
Tyler Goodlet 10e47e349c Include symbol deats in feed init message from ib
Async spawn a deats getter task whenever we load a symbol data feed.
Pass these symbol details in the first message delivered by the feed at
open. Move stream loop into a new func.
2021-01-22 17:11:53 -05:00
Tyler Goodlet 794665db70 Drop log msg 2021-01-18 20:28:52 -05:00
Tyler Goodlet 2bf95d7ec7 Fix clients map typing annot 2021-01-15 21:10:08 -05:00
Tyler Goodlet bdc02010cf Finally, sanely normalize local trades event data 2021-01-15 21:10:08 -05:00
Tyler Goodlet c835cc10e0 Get "live" order mode mostly workin 2021-01-15 21:10:08 -05:00
Tyler Goodlet ee8caa80d4 Add order cancellation and error support 2021-01-15 21:10:08 -05:00
Tyler Goodlet 12aebcc89c Expose "proxy" api a little better 2021-01-15 21:10:08 -05:00
Tyler Goodlet 280739b51a Add trades data streaming support 2021-01-15 21:10:08 -05:00
Tyler Goodlet dba8457be9 Trigger kraken sample increment after startup 2021-01-07 12:17:10 -05:00
Tyler Goodlet 268f207a6c Shadow 'close' field with 'last' 2021-01-05 08:02:48 -05:00
Tyler Goodlet c7ff0804db Graph snap quote immediately on ib spin up 2021-01-04 14:43:59 -05:00
Tyler Goodlet 5fddb581ab Kill backfiller on "no history" error 2021-01-01 12:34:50 -05:00
Tyler Goodlet d7f80d8ddb Add note about shm limit 2020-12-29 18:05:36 -05:00
Tyler Goodlet 42761438f6 Pass backfiller explicit symbol str, don't require volume ticks 2020-12-26 18:04:32 -05:00
Tyler Goodlet f27d639552 Port kraken to declare "wap" field 2020-12-19 16:53:51 -05:00
Tyler Goodlet fda9fcbc55 Add historical backfilling to ib backend 2020-12-19 16:50:08 -05:00
Tyler Goodlet c1109ee3fb Add license headers to pertinent files 2020-11-06 12:23:14 -05:00
Tyler Goodlet be4a3df7ba Add L1 spread streaming to kraken 2020-11-06 11:35:40 -05:00
Tyler Goodlet 9c3850874d Add all L1 tick types for ib 2020-11-05 08:18:55 -05:00
Tyler Goodlet 987c13c584 Classify L1 tick types 2020-11-03 16:22:04 -05:00
Tyler Goodlet 1640906b09 Write shm volume (facepalm), update open=close on first volume 2020-11-03 08:14:37 -05:00
Tyler Goodlet 307c501763 Add symbol field to ib quotes 2020-10-29 17:21:41 -04:00
Tyler Goodlet da0789e184 Add symbol field to kraken quotes 2020-10-29 17:08:25 -04:00
Tyler Goodlet 454b445b4b Add better shared mem writer task checking
If you have a common broker feed daemon then likely you don't want to
create superfluous shared mem buffers for the same symbol. This adds an
ad hoc little context manger which keeps a bool state of whether
a buffer writer task currently is running in this process. Before we
were checking the shared array token cache and **not** clearing it when
the writer task exited, resulting in incorrect writer/loader logic on
the next entry..

Really, we need a better set of SC semantics around the shared mem stuff
presuming there's only ever one writer per shared buffer at given time.
Hopefully that will come soon!
2020-10-15 15:02:42 -04:00
Tyler Goodlet 2302e59f1d 3k bars for now, ignore rtTime 2020-10-02 12:13:50 -04:00
Tyler Goodlet bc65040601 Add shm support to kraken backend 2020-10-02 12:13:50 -04:00
Tyler Goodlet 47d4ec5985 Move _source under data package 2020-10-02 12:13:50 -04:00
Tyler Goodlet 155c3eef2a Convert timeit thing to use print() 2020-10-02 12:13:50 -04:00
Tyler Goodlet 8832804bab Sub each new symbol to shm incrementing 2020-10-02 12:13:50 -04:00
Tyler Goodlet d93ce84a99 Variety of IB backend improvements
- Move to new shared mem system only writing on the first (by process)
  entry to `stream_quotes()`.
- Deliver bars before first quote arrives so that chart can populate and
  then wait for initial arrival.
- Allow caching clients per actor.
- Load bars using the same (cached) client that starts the quote stream
  thus speeding up initialization.
2020-10-02 12:13:50 -04:00
Tyler Goodlet f872fbecf8 Hook IB up to shared memory system
Adjust the `data.open_feed()` api to take a shm token so the
broker-daemon can attach a previously created (by the parent actor) mem
buf and push real-time tick data. There's still some sloppiness here in
terms of ensuring only one mem buf per symbol (can be seen in
`stream_quotes()`) which should really managed at the data api level.
Add a bar incrementing stream-task which delivers increment msgs to any
consumers.
2020-10-02 12:13:50 -04:00
Tyler Goodlet 61e460a422 Start brokers.api module 2020-10-02 12:13:28 -04:00
Tyler Goodlet 241b2374e8 Port `DataFeed` api to broker specific normalizer routine 2020-10-02 12:13:28 -04:00
Tyler Goodlet 9bbf0e0d7a Add a normalizer routine which emits quote differentials/ticks 2020-10-02 12:13:28 -04:00
Tyler Goodlet 81fb327fe1 Add `services` cmd for monitoring actors 2020-10-02 12:13:28 -04:00
Tyler Goodlet cb8215c203 Also log the payload 2020-10-02 12:13:28 -04:00
Tyler Goodlet 46c804db0b Support the `stream_quotes()` api in questrade backend 2020-10-02 12:13:28 -04:00
Tyler Goodlet 88fb7a8951 Handle overloaded arg 2020-10-02 12:13:28 -04:00
Tyler Goodlet 1a1e768126 Port to new data apis 2020-10-02 12:13:28 -04:00
Tyler Goodlet 6802675637 Add kraken to backend list 2020-10-02 12:13:28 -04:00
Tyler Goodlet 4c753b5ee6 Add ib 2020-10-02 12:13:28 -04:00
Tyler Goodlet 7a660b335d Make search work with ib backend 2020-10-02 12:13:28 -04:00
Tyler Goodlet 99c18abfea Add symbol search to broker api 2020-10-02 12:13:28 -04:00
Tyler Goodlet 82a5daf91b Move all kivy ui components to subpackage 2020-10-02 12:13:28 -04:00
Tyler Goodlet f77a39ceb7 Add symbol-info command 2020-10-02 12:13:28 -04:00
Tyler Goodlet b670af484c Move UI spawning cmds to new module 2020-10-02 12:13:27 -04:00
Tyler Goodlet 2f8737af6a Fix PURE contracts lookup... 2020-09-29 17:06:28 -04:00
Tyler Goodlet 5bb11826f3 Drop unmarketable trades for now 2020-09-29 17:06:28 -04:00
Tyler Goodlet aad9cb2dd0 Support forex pair lookup on ib 2020-09-29 17:06:28 -04:00
Tyler Goodlet b499631d62 Drop to 1k bars on init load 2020-09-29 17:06:28 -04:00
Tyler Goodlet ad08cb7a66 Try to find cad stocks 2020-09-29 17:06:28 -04:00
Tyler Goodlet 103014aa58 Properly teardown data feed on cancel 2020-09-29 17:06:28 -04:00
Tyler Goodlet b7c924046a Begin to use `@tractor.msg.pub` throughout streaming API
Since the new FSP system will require time aligned data amongst actors,
it makes sense to share broker data feeds as much as possible on a local
system. There doesn't seem to be downside to this approach either since
if not fanning-out in our code, the broker (server) has to do it anyway
(and who knows how junk their implementation is) though with more
clients, sockets etc. in memory on our end. It also preps the code for
introducing a more "serious" pub-sub systems like zeromq/nanomessage.
2020-09-29 17:06:28 -04:00
Tyler Goodlet 0bf265a96f Future todo 2020-09-29 17:06:28 -04:00
Tyler Goodlet 482dc510fa Add normalization step for ticks
Start a draft normalization format for (sampled) tick data.
Ideally we move toward the dense tick format (DFT) enforced by
techtonicDB, but for now let's just get a dict of something simple
going: `{'type': 'trade', 'price': <price}` kind of thing. This
gets us started being able to real-time chart from all data feed
back-ends. Oh, and hack in support for XAUUSD..and get subactor
logging workin.
2020-09-29 17:06:28 -04:00
Tyler Goodlet aeb58c03e2 Add startup logic to handle market closure 2020-09-29 17:06:28 -04:00
Tyler Goodlet 4ce99e62e0 Override annoying stuff in ib_insync 2020-09-29 17:06:28 -04:00
Tyler Goodlet 41c6517a23 Port to new streaming api, yield whole tickers 2020-09-29 17:06:28 -04:00
Tyler Goodlet 450a39ce1c Add better contract search/lookup
Add a `Client.find_contract()` which internally takes
a <symbol>.<exchange> str as input and uses `IB.qualifyContractsAsync()`
internally to try and validate the most likely contract. Make the module
script call this using `asyncio.run()` for console testing.
2020-09-29 17:06:28 -04:00
Tyler Goodlet b8209cd506 Add a mostly actor aware API to IB backend
Infected `asyncio` support is being added to `tractor` in
goodboy/tractor#121 so delegate to all that new machinery.

Start building out an "actor-aware" api which takes care of all the
`trio`-`asyncio` interaction for data streaming and request handling.
Add a little (shudder) method proxy system which can be used to invoke
client methods from another actor. Start on a streaming api in
preparation for real-time charting.
2020-09-29 17:06:28 -04:00
Tyler Goodlet 1abadeb506 Add initial IB broker backend using ib_insync
Start working towards meeting the backend client api.
Infect `asyncio` using `trio`'s new guest mode and demonstrate
real-time ticker streaming to console.
2020-09-29 17:06:28 -04:00
Tyler Goodlet 14a5d047c3 Copy forward stupid kraken zeroed vwaps 2020-09-29 16:42:28 -04:00
Tyler Goodlet b13da849d0 Include vwap in kraken historical bars 2020-09-29 16:42:06 -04:00
Tyler Goodlet 0b42ac1420 Normalize kraken quotes for latency tracking 2020-09-26 11:31:57 -04:00
Tyler Goodlet ea8205968c Begin to use `@tractor.msg.pub` throughout streaming API
Since the new FSP system will require time aligned data amongst actors,
it makes sense to share broker data feeds as much as possible on a local
system. There doesn't seem to be downside to this approach either since
if not fanning-out in our code, the broker (server) has to do it anyway
(and who knows how junk their implementation is) though with more
clients, sockets etc. in memory on our end. It also preps the code for
introducing a more "serious" pub-sub systems like zeromq/nanomessage.
2020-09-26 11:31:57 -04:00
Tyler Goodlet 44010abf4d Handle (far end forced) disconnects 2020-09-26 11:31:57 -04:00
Tyler Goodlet 03c5c7d2ba Trigger connection reset on slowed heartbeat 2020-09-26 11:31:57 -04:00
Tyler Goodlet e92abd376a Trace log the heartbeat 2020-09-26 11:31:57 -04:00
Tyler Goodlet bf9a0136df Make ws loop restart on connection failures 2020-09-26 11:31:57 -04:00
Tyler Goodlet d976f3d074 Generate tick data correctly using .etime 2020-09-26 11:31:57 -04:00
Tyler Goodlet ad92188703 Support new normalized ticks format with kraken
Generate tick datums in a list under a `ticks` field in each quote
kinda like how IB does it.
2020-09-26 11:31:57 -04:00
Tyler Goodlet 9976bc3a3b Fix typo 2020-09-26 11:31:57 -04:00
Tyler Goodlet 3655e449d6 Raise errors, fix module script entry 2020-09-26 11:31:57 -04:00
Tyler Goodlet ffe47acf1d Add historical bars retreival 2020-09-26 11:31:57 -04:00
Tyler Goodlet 7bccfc7b10 Convert to stream, parse into dataclass 2020-09-26 11:31:57 -04:00
Tyler Goodlet 2738b54851 Start kraken backend 2020-09-26 11:31:57 -04:00
Tyler Goodlet 702c63f607 Define "packetizer" in specific broker mod
Allows for formatting published quotes using a broker specific
formatting callback.
2020-09-02 00:36:19 -04:00
Tyler Goodlet 312169e790 Support the `stream_quotes()` api in questrade backend 2020-09-01 20:55:24 -04:00
Tyler Goodlet 60b74ad7d1 Use new method name 2020-09-01 20:53:45 -04:00
Tyler Goodlet a6de623147 Add search command to cli 2020-09-01 20:53:27 -04:00
Tyler Goodlet 75f98276cc Add symbol search to broker api 2020-09-01 20:53:04 -04:00
Tyler Goodlet 519712e128 Add stocks search to qt client 2020-09-01 20:52:01 -04:00
Tyler Goodlet 934108a024 Add symbol-info command 2020-09-01 20:51:09 -04:00
Tyler Goodlet dcb0a30ad6 Move UI spawning cmds to new module 2020-09-01 20:47:24 -04:00
Tyler Goodlet 78784a4bf3 Port to new data apis 2020-09-01 18:30:55 -04:00
Tyler Goodlet acd32341e2 Fix assignment out of order 2020-09-01 13:25:41 -04:00
Tyler Goodlet d66cfb8fa0 Push only new key value pairs over quote streams
This is something I've been meaning to try for a while and will likely
make writing tick data to a db more straight forward (filling in NaN
values is more matter of fact) plus it should minimize bandwidth usage.
Note, it'll require stream consumers to be considerate of non-full
quotes arriving and thus using the first "full" quote message to fill
out dynamically formatted systems or displays.
2020-09-01 13:25:41 -04:00
Tyler Goodlet 335cee63b2 Make stock quote formatter work with diff streams 2020-09-01 13:25:41 -04:00
Tyler Goodlet 2c93bb0302 Drop use of deprecated `trio.Event.clear()` 2020-06-02 10:33:57 -04:00
Tyler Goodlet 882f4a28d1 Add privacy note 2020-06-01 14:43:39 -04:00
Tyler Goodlet 64993666fa Pull 100 bars by default 2020-05-26 14:49:50 -04:00
Tyler Goodlet 5f200b8db1 Always delay bars 15m; rename to volume 2020-05-26 14:49:50 -04:00
Tyler Goodlet a7f7de32b4 Docstring tweaks 2020-05-26 14:49:50 -04:00
Tyler Goodlet ffd8bdac5f Fix imports 2020-05-26 14:49:50 -04:00
Tyler Goodlet f798d13038 Reord watchlist cmds into new package 2020-05-26 14:49:50 -04:00
Tyler Goodlet ff843372a1 Add `piker bars` command
For easy testing of questrade historical data from cli.
Re-org the common cli components into a new package to avoid having all
commands defined in a top-level module.
2020-05-26 14:49:50 -04:00
Tyler Goodlet c11946988e Implement candles retrieval from Questrade
There's some expected limitations with the number of sticks allowed in
a single query (they say 2k but I've been able to pull 20k). Also note
without a paid data sub there's a 15m delay on 1m sticks (we'll hack
around that shortly, don't worry).
2020-05-26 14:49:50 -04:00
Tyler Goodlet 595f79c632 Add symbol not found 2020-05-26 14:49:50 -04:00
Tyler Goodlet 837e30ff68 use >1 asks session connections
Gets us better throughput when polling multiple endpoints (eg. option
and stock quotes simultaneously) since slower round trip request won't
block faster ones when using multiple connections.
2020-02-18 16:13:20 -05:00
Tyler Goodlet 49d612de49 Port to new @tractor.stream API 2019-04-26 00:27:01 -04:00
Tyler Goodlet 884fcaa88e A slew of tiny pager improvements
- stop displaying search bar widget on <ctrl-c>
- if there's existing search bar content highlight it automatically
  to allow user to start typing new content right away
- when activated allow search bar to insert its own set of keybinding
  controls; restore prior bindings on exit
2019-03-21 22:01:50 -04:00
Tyler Goodlet 3a439fc99d Fix ask use logic for testing/CI 2019-03-17 23:03:45 -04:00
Tyler Goodlet 6a50049af7 Use toml instead of ini for broker config 2019-03-15 19:37:04 -04:00
Tyler Goodlet 5e9c38039c Move brokerd spawner to `brokers.core` 2019-02-25 22:29:48 -05:00
Tyler Goodlet 77548d2ee6 Add token-from-user toggles to token auth methods 2019-02-25 20:11:45 -05:00
Tyler Goodlet 130553b8df Accept a path arg to `write()` 2019-02-25 19:29:54 -05:00
Tyler Goodlet 295ccbbe64 Name the data what it is 2019-02-24 10:55:52 -05:00
Tyler Goodlet 462c419970 Add basic practice account support 2019-02-21 17:24:50 -05:00
Tyler Goodlet 435b2a56e8 Remove stream opening lock on `DataFeed`
Fixes to `tractor` that resolve issues with async generators being
non-task safe make the need for the mutex lock in
`DataFeed.open_stream()` unnecessary. Also, don't bother pushing empty
quotes from the publisher; avoids hitting the network when possible.
2019-02-20 21:39:57 -05:00
Tyler Goodlet 3a6efd451d Don't bother ensuring all symbols in data 2019-02-10 19:09:54 -05:00
Tyler Goodlet 395f0c8e4a Synchronize Questrade token refreshing per client
Questrade's API is half baked and can't handle concurrency.
It allows multiple concurrent requests to most endpoints *except*
for the auth endpoint used to refresh tokens:

    https://www.questrade.com/api/documentation/security

I've gone through extensive dialogue with their API team and despite
making what I think are very good arguments for doing the request
serialization on the server side, they decided that I should instead
do the "locking" on the client side. Frankly it doesn't seem like they
have that competent an engineering department as it took me a long time
to explain the issue even though it's rather trivial and probably not
that hard to fix; maybe it's better this way.

This adds a few things to ensure more reliable token refreshes on
expiry:

- add a `@refresh_token_on_err` decorator which can be used on `_API`
  methods that should refresh tokens on failure
- decorate most endpoints with this *except* for the auth ep
- add locking logic for the troublesome scenario as follows:
  * every time a request is sent out set a "request in progress" event
    variable that can be used to determine when no requests are currently
    outstanding
  * every time the auth end point is hit in order to refresh tokens set
    an event that locks out other tasks from making requests
  * only allow hitting the auth endpoint when there are no "requests in
    progress" using the first event
  * mutex all auth endpoint requests; there can only be one outstanding

- don't hit the accounts endpoint at client startup; we want to
  eventually support keys from multiple accounts and you can disable
  account info per key and just share the market data function
2019-02-09 21:39:22 -05:00
Tyler Goodlet f6230dd6df Add a `DataFeed.call_client()` method
Allows for calling an actor local broker client's methods from a remote
actor.
2019-02-09 21:38:00 -05:00
Tyler Goodlet 026b015627 Allow passing a config path for broker testing in CI 2019-02-04 00:17:11 -05:00
Tyler Goodlet 5dac8fa44d Note the RH auth/account requirements for usage 2019-02-04 00:15:10 -05:00
Tyler Goodlet e91a50a1ba Make `get_cached_feed()` an asynccontextmanager
Adjust feed locking around internal manager `yields` to make this work.

Also, change quote publisher to deliver a list of quotes for each
retrieved batch. This was actually broken for option streaming since
each quote was being overwritten due to a common `key` value for all
expiries. Asjust the `packetizer` function accordingly to work for
both options and stocks.
2019-02-03 23:40:51 -05:00
Tyler Goodlet 2514843fc1 Port to the new `@tractor.msg.pub` decorator API
The pub-sub data feed system was factored into `tractor` as an
experimental api / subsystem. Move to using that which greatly
simplifies the data feed architecture.
2019-01-27 14:50:04 -05:00
Tyler Goodlet 22670afe58 Generalize the publisher/fan-out system
Start working toward a more general (on-demand) pub-sub system which
can be brought into ``tractor``. Right now this just means making
the code in the `fan_out_to_ctxs()` less specific but, eventually
I think this function should be coupled with a decorator and shipped
as a standard "message pattern".

Additionally,
- try out making `BrokerFeed` a `@dataclass`
- strip out all the `trio.Event` / uneeded nursery / extra task crap
  from `start_quote_stream()`
2019-01-14 21:23:49 -05:00
Tyler Goodlet a4501bb0e0 Factor `DataFeed` client API into `brokers.data` 2019-01-05 19:08:27 -05:00
Tyler Goodlet 7f8c88be0c Drop open/close prices for now; never really use them 2019-01-02 21:24:42 -05:00
Tyler Goodlet b4fad3f6a9 Logic factoring 2018-12-29 16:00:18 -05:00
Tyler Goodlet 1866dd1812 Fix for adjusted contracts subscription bug
If quotes are pushed using the adjusted contract symbol (i.e. with
trailing '-1' suffix) the subscriber won't receive them under the
normal symbol. The logic was wrong for determining whether to add
a suffix (was failing for any symbol with an exchange suffix)
which was causing normal data feed subscriptions to fail to match
in every case.

I did some testing of the `optionsIds` parameter to the option quote
endpoint and found that it limits you to 100 symbols so it's not
practical for real-time "all-strike"" chain updating; we have to stick
to filters for now. The only real downside of this is that it seems
multiple filters across multiple symbols is quite latent. I need to
toy with it more to be sure it's not something slow on the client side.
Oh, and store option contract to ids in a `dict` for now as we may want
to try the `optionsIds` thing again down the road as I coordinate with
the QT tech team.
2018-12-29 15:44:32 -05:00
Tyler Goodlet dc581d0bdc Handle "adjusted contract" chains per root 2018-12-26 13:30:50 -05:00
Tyler Goodlet de4fab873b Ids should be allowed without contracts 2018-12-23 21:25:56 -05:00
Tyler Goodlet eb8c9e1a99 Symbol subs must be cid specific 2018-12-23 20:48:06 -05:00
Tyler Goodlet d4e36b1e55 Jeeze, don't overwrite the payload for each channel... 2018-12-17 19:15:29 -05:00
Tyler Goodlet 5af90c044f Drop contracts cache; that wasn't the bottleneck
This also fixes a bug where option subscriptions weren't actually being
changed when a new call was made..
2018-12-16 23:56:03 -05:00
Tyler Goodlet 721e3803b2 Shorter title of IV: implied volatility 2018-12-15 16:27:41 -05:00
Tyler Goodlet 70435e3b15 Always push an option smoke quote for UI init 2018-12-15 16:26:54 -05:00
Tyler Goodlet 948ee3cadf Cache contracts lookup once at startup 2018-12-13 13:11:07 -05:00
Tyler Goodlet 743ca6bfe3 Log quotes even without caching 2018-12-11 17:09:59 -05:00
Tyler Goodlet 7b5c73bb45 Use pythonic sequence splitting with `zip()` 2018-12-11 17:09:36 -05:00
Tyler Goodlet 66ecb4c0cb Use a `trio.Event` to guarantee respawning of data feed task 2018-12-11 15:21:12 -05:00
Tyler Goodlet 01c0551a7f Don't display greeks besides delta for now 2018-12-11 15:20:24 -05:00
Tyler Goodlet 20778b02b5 Format numerical option fields 2018-12-10 01:50:00 -05:00
Tyler Goodlet 54261ecc4c Refer to async exit stack via feed 2018-12-10 01:49:19 -05:00
Tyler Goodlet fb47ea2e5a Define option field structure
Add some extra fields to each quote that QT should already be
providing (instead of hiding them in the symbol and request contract
info); namely, the expiry and contact type (i.e. put or call).
Define the base set of fields to be displayed in an option chain
UI and add a quote formatter.
2018-12-09 13:40:26 -05:00
Tyler Goodlet 9c7ca84fef Include strike and expiry in option quotes 2018-12-09 13:40:26 -05:00
Tyler Goodlet b8815cde4a Set statespace defaults in `get_cached_feed()` 2018-12-09 13:30:34 -05:00
Tyler Goodlet 7378a16b90 s/tickers/symbols 2018-12-01 16:12:46 -05:00
Tyler Goodlet 2915e83324 Warn about missing symbols at CLI level 2018-12-01 16:11:38 -05:00
Tyler Goodlet 61294c6c44 Adhere to the same non-found-symbol behaviour as QT 2018-12-01 16:09:41 -05:00
Tyler Goodlet f35671cc88 Handle bad symbol names 2018-12-01 16:08:03 -05:00
Tyler Goodlet cabc616b85 Port option api to new backend broker api 2018-11-30 08:14:36 -05:00
Tyler Goodlet c7cf0cde9c Add options streaming
Well that was a doozy; had to rejig pretty much all of it.

The deats:
- Track broker components in a new `DataFeed` namedtuple
- port to new list based batch quotes (not dicts any more)
- lock access to cached broker-client / data-feed instantiation
- respawn tasks that fail due to the network
2018-11-30 08:13:30 -05:00
Tyler Goodlet cd7d8d024d Add option quoter support for streaming
So much changed to get this working for both stocks and options:
- Index contracts by a new `ContractsKey` named tuple
- Move to pushing lists of quotes instead of dicts since option
  subscriptions are often not identified by their "symbol" key and
  this makes it difficult at fan out time to know how a quote should
  be indexed and delivered. Instead add a special `key` entry to each
  quote dict which is the quote's subscription key.
2018-11-30 00:33:40 -05:00
Tyler Goodlet 75d22c6058 An explicit name is prolly better 2018-11-25 19:23:07 -05:00
Tyler Goodlet 714c203c3e Cache symbol ids where possible
Cache both in the client and at the function call level inside the
quoter context using a `@afifo_cache`.
2018-11-25 15:00:08 -05:00
Tyler Goodlet c23982393d Allow recording data feeds to disk
Add a couple functions for storing and retrieving live json data feed
recordings to disk using a very rudimentary character + newline delimited
format.

Also, split out the pub-sub logic from `stream_quotes()` into a new
func, `fan_out_to_chans()`. Eventually I want to formalize this pattern
into a decorator exposed through `tractor`.
2018-11-22 15:56:02 -05:00
Tyler Goodlet f038fdd42f Add a `contracts()` query
Makes it easy to request all the option contracts for a particular symbol.
Also, let `option_chain()` accept a `date` arg which can be used to only
retrieve quotes for a single expiry date (much faster then getting all
of them).
2018-11-22 15:53:00 -05:00
Tyler Goodlet 247bcb48c0 Tweak options query API method names 2018-11-22 09:19:04 -05:00
Tyler Goodlet 8fe0c40dde Move data feed machinery to separate module 2018-11-14 22:58:12 -05:00
Tyler Goodlet 0c3bfb9e9e Stack the mktcap + volumes 2018-11-13 18:41:58 -05:00
Tyler Goodlet d145a5a219 Rejig option chain schema to capture all contracts 2018-11-13 12:57:21 -05:00
Tyler Goodlet 2b1818ba33 Drop old stream test, rename stock quote func 2018-11-11 21:45:11 -05:00
Tyler Goodlet a5afa0f1c3 Fix typo 2018-11-11 21:06:25 -05:00
Tyler Goodlet f9d9d7c1ba Add option chain quote support! 2018-11-11 21:05:30 -05:00
Tyler Goodlet 421cc4731f Face palm - fix mktcap sorting
Yuh think maybe the default "null" value shouldn't be a string...?

Fixes #46
2018-08-22 23:02:08 -04:00
Tyler Goodlet 96b17e16ac Handle stale token case on network outage reconnect 2018-08-22 23:01:14 -04:00
Tyler Goodlet 6c977cfb7b Port broker core to tractor; fix chan unsub bug 2018-07-06 17:25:40 -04:00
goodboy 6ff871ff7d
Merge pull request #50 from pikers/tractor_draft
Introducing "tractor"
2018-07-05 15:52:53 -04:00
Tyler Goodlet e395845ddb Every ticker-chan subscription must include a caller id 2018-07-05 15:23:38 -04:00
Tyler Goodlet 23830d51d1 Log either kwarg 2018-06-27 11:59:02 -04:00
Tyler Goodlet 8019296c67 Port broker daemon to tractor
Drop all channel/connection handling from the core and break up all the
start up steps into compact and useful functions. The main difference is
the daemon now only needs to worry about spawning per broker streaming
tasks and handling symbol list subscription requests.
2018-06-26 17:55:52 -04:00
Tyler Goodlet fa8418f97f Port stream_quotes to tractor ipc protocol 2018-06-23 14:57:02 -04:00
Tyler Goodlet fa0aefff4d Take that QT nulls 2018-06-12 15:33:11 -04:00
Tyler Goodlet f71f986dae Use new IPC apis throughout core
Move to using `Channel` throughout instead of the `StreamQueue`
and add a very basic function for upcoming actor model testing.
2018-06-07 00:23:11 -04:00
Tyler Goodlet 485aa76ff6 Move ipc types into separate module 2018-05-30 12:36:23 -04:00
Tyler Goodlet 186befc704 Only run 'startup sequence' on reconnect
When a client loses a connection it will currently need to re-subscribe
for symbols and receive a symbol data summary as a first quote response.
Only run the provided coroutine on reconnect and call the kwarg
`on_reconnect`. The client consuming code is entirely expected at this
point to know how the symbol registration protocol works.
2018-05-16 19:15:43 -04:00
Tyler Goodlet bcaef70612 Pack null results without raising 2018-05-09 18:09:04 -04:00
Tyler Goodlet fd1fe0816e Don't call formatting func on None values 2018-05-09 18:09:04 -04:00
Tyler Goodlet 3646fb4a23 Filter out bad symbols before adding client subscription
Event if a broker client is already spawned new clients should still
receive a detailed symbol data packet as the first response. Avoid
exposing the new client's queue to the broker (i.e. subscribing it for
quotes) until after first pushing this packet with all bad symbols
filtered out.
2018-05-09 18:09:04 -04:00
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