Commit Graph

569 Commits (176b230a463c4b1eecee166a0d83741a7c31029e)

Author SHA1 Message Date
Konstantine Tsafatinos b1bff1be85 remove ws support for orders, use rest api instead for easy oid association 2022-03-06 15:17:26 -05:00
Konstantine Tsafatinos 46948e0a8b add order cancel support over websockets 2022-03-06 15:17:26 -05:00
Konstantine Tsafatinos d826a66c8c use a mapping from userref to oid for order ack 2022-03-06 15:17:26 -05:00
Konstantine Tsafatinos 6c54c81f01 get stashed changes 2022-03-06 15:17:26 -05:00
Tyler Goodlet 0122669dd4 Factor out ws msg hearbeat and error handling
Move the core ws message handling into `stream_messages()` and call that
from 2 new stream processors: `process_data_feed_msgs()` and
`process_order_msgs()`. Add comments for hints on how to implement the
order msg parsing as well as `pprint` received msgs to console for now.
2022-03-06 15:17:26 -05:00
Konstantine Tsafatinos 0c905920e2 connect to krakens openOrders websocket 2022-03-06 15:17:26 -05:00
Konstantine Tsafatinos 03d2eddce3 order submission and cancellation working 2022-03-06 15:17:26 -05:00
Konstantine Tsafatinos 96dd5c632f basic order submission and cancelling with kraken 2022-03-06 15:17:26 -05:00
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