tinkoff-invest-sdk

Haskell gRPC based SDK for Tinkoff Invest API V2


Keywords
library, mit, Propose Tags , , tinkoff-invest-sdk-0.1.1.1.tar.gz, browse, Package description, Package maintainers, mi11er, edit package information
License
MIT
Install
cabal install tinkoff-invest-sdk-0.1.1.1

Documentation

Haskell LISENCE

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

  1. Install Stack tool
  2. Install ProtoBuff Compiller
  3. Run stack build from project root directory