Tinkoff / invest-python

Tinkoff Invest Python gRPC client
https://tinkoff.github.io/invest-python/
Apache License 2.0
313 stars 90 forks source link

ValueError: 8 is not a valid SubscriptionStatus #138

Closed ZeniT21 closed 1 year ago

ZeniT21 commented 1 year ago

Что случилось?

ValueError: 8 is not a valid SubscriptionStatus - в момент перебора объектов на подписанные бумаги

Воспроизведение

No response

Tinkoff Invest Version

0.2.0-beta40

Python Version

3.10

OS

Linux

Логи

MarketDataResponse(subscribe_candles_response=None, subscribe_order_book_response=SubscribeOrderBookResponse(tracking_id='6350f1e49420bbaa3178b0fde20257be', order_book_subscriptions=[OrderBookSubscription(figi='BBG003981NS4', depth=1, subscription_status=<SubscriptionStatus.SUBSCRIPTION_STATUS_SUCCESS: 1>)]), subscribe_trades_response=None, subscribe_info_response=None, candle=None, trade=None, orderbook=None, trading_status=None, ping=None, subscribe_last_price_response=None, last_price=None)
Traceback (most recent call last):
  File "/home/app/server/api/scanner_weekends/1.py", line 105, in <module>
    main()
  File "/home/app/server/api/scanner_weekends/1.py", line 71, in main
    for marketdata in market_data_stream:
  File "/home/app/myvenv/lib/python3.10/site-packages/tinkoff/invest/market_data_stream/market_data_stream_manager.py", line 78, in __next__
    return next(self._market_data_stream)
  File "/home/app/myvenv/lib/python3.10/site-packages/tinkoff/invest/_errors.py", line 43, in wrapper
    yield from func(*args, **kwargs)
  File "/home/app/myvenv/lib/python3.10/site-packages/tinkoff/invest/services.py", line 823, in market_data_stream
    yield _grpc_helpers.protobuf_to_dataclass(response, MarketDataResponse)
  File "/home/app/myvenv/lib/python3.10/site-packages/tinkoff/invest/_grpc_helpers.py", line 269, in protobuf_to_dataclass
    field_value = protobuf_to_dataclass(pb_value, field_type)
  File "/home/app/myvenv/lib/python3.10/site-packages/tinkoff/invest/_grpc_helpers.py", line 278, in protobuf_to_dataclass
    field_value = [
  File "/home/app/myvenv/lib/python3.10/site-packages/tinkoff/invest/_grpc_helpers.py", line 279, in <listcomp>
    protobuf_to_dataclass(item, first_arg) for item in pb_value
  File "/home/app/myvenv/lib/python3.10/site-packages/tinkoff/invest/_grpc_helpers.py", line 271, in protobuf_to_dataclass
    field_value = field_type(pb_value)
  File "/usr/lib/python3.10/enum.py", line 385, in __call__
    return cls.__new__(cls, value)
  File "/usr/lib/python3.10/enum.py", line 710, in __new__
    raise ve_exc
ValueError: 8 is not a valid SubscriptionStatus
irusland commented 1 year ago

Будьте добры прикрепить код воспроизводящий проблему, гляну.

ZeniT21 commented 1 year ago
       headers = {
  "Authorization": "Bearer "+secret_key,
}

payload = {
           "instrumentStatus": "INSTRUMENT_STATUS_UNSPECIFIED",
           "classCode": "string",
            "id": "string"
}
url = 'https://invest-public-api.tinkoff.ru/rest/tinkoff.public.invest.api.contract.v1.InstrumentsService/Shares'
response = requests.post(url,  json = payload, headers=headers)
response = json.loads(response.text)
Ti_Instruments = []
        with Client(secret_key) as client:
            market_data_stream: MarketDataStreamManager = client.create_market_data_stream()
            i = 0
            for ticker in response['instruments']:
                i += 1
                if i % 99 == 0:
                    sleep(60)

                market_data_stream.order_book.subscribe(
                    [
                        OrderBookInstrument(
                            figi=ticker['figi'],
                            depth=1
                        )
                    ]
                )

            price = {}
            print('subscibe end')

            while True:
                print('start cycle')

                for marketdata in market_data_stream:
                    print(marketdata.subscribe_order_book_response)
irusland commented 1 year ago

Не смог воспроизвести. У вас точно версия библиотеки 0.2.0-beta40?

ZeniT21 commented 1 year ago

Да, была другая версия :( в 0.2.0-beta40 все ок