tinkoff-invest-haskell
Haskell gRPC based SDK for Tinkoff Invest API V2
Preparations
Project dependency
The library is distributed via Hackage module. To use this SDK in your project you should add folowing line to dependencies block of package.yaml
dependencies:
- tinkoff-invest-sdk
API Token
Tinkoff Invest API requires access token for comunications. There is instructions of generating personal token.
Examples
Unary queries
getBaseShares :: GrpcClient -> GrpcIO [Share]
getBaseShares gc = shares gc (defMessage & I.instrumentStatus .~ INSTRUMENT_STATUS_BASE)
main :: IO ()
main = void . runExceptT $ initClient <#> getBaseShares #> (liftIO . print)
where initClient = initGrpcClient $ ClientConfig {
token = "your_token",
appName = Just "your_app_name"
}
Stream queries
main :: IO ()
main = do
let config = ClientConfig { token = "your_token", appName = Just "your_app_name" }
client <- runClient config
stream <- marketDataStream client
subscribeOrderBook stream "BBG004730RP0" 10 \resp -> case resp ^. MD.maybe'payload of
Just (MarketDataResponse'SubscribeOrderBookResponse r) -> logResponse r >> pure Next
Just (MarketDataResponse'Orderbook r) -> logResponse r >> pure Next
_ -> pure Break
wait stream
See more examples here
TODO
- Cyrillic encoding support
- More enhanced calculation monad
- Trading stratagies
Contribution
Build project steps
- Install Stack tool
- Install ProtoBuff Compiller
- Run
stack build
from project root directory