Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix put item in StoreStream with _remove (#181) #182

Merged

Conversation

ko0hi
Copy link
Contributor

@ko0hi ko0hi commented Aug 19, 2022

修正後、以下のテストコードがパスすることを確認しました(修正前はok_deleteがTrueにならず assert task.done()でエラーとなります)。

import pybotters
import asyncio


async def watch_position(store):
    ok_insert, ok_delete = False, False
    with store.positions.watch() as stream:
        async for msg in stream:
            if msg.operation == "insert":
                ok_insert = True
            if msg.operation == "delete":
                ok_delete = True

            if ok_insert and ok_delete:
                break


async def main():
    async with pybotters.Client(
        {
              "bitflyer": [
                "XXX",
                "XXX"
            ]
        }, base_url="https://api.bitflyer.com"
    ) as client:
        store = pybotters.bitFlyerDataStore()

        await client.ws_connect(
            "wss://ws.lightstream.bitflyer.com/json-rpc",
            send_json=[
                {
                    "method": "subscribe",
                    "params": {"channel": "lightning_executions_FX_BTC_JPY"},
                    "id": 1,
                },
                {
                    "method": "subscribe",
                    "params": {"channel": "child_order_events"},
                    "id": 2,
                },
            ],
            hdlr_json=store.onmessage,
        )

        task = asyncio.create_task(watch_position(store))

        await asyncio.sleep(3)

        entry_resp = await client.post(
            "/v1/me/sendchildorder",
            data={
                "product_code": "FX_BTC_JPY",
                "side": "BUY",
                "size": "0.01",
                "child_order_type": "MARKET",
            },
        )
        entry_data = await entry_resp.json()

        await store.positions.wait()

        positions = store.positions.find()
        assert len(positions) == 1

        exit_resp = await client.post(
            "/v1/me/sendchildorder",
            data={
                "product_code": "FX_BTC_JPY",
                "side": "SELL",
                "size": "0.01",
                "child_order_type": "MARKET",
            },
        )

        await store.positions.wait()
        positions = store.positions.find()
        assert len(positions) == 0


        assert task.done()


if __name__ == "__main__":
    asyncio.run(main())

Close #181

@MtkN1
Copy link
Member

MtkN1 commented Aug 20, 2022

PRありがとうごとうございます!
数日多忙なのでレビューはもう暫くお待ち下さい🙏

Copy link
Member

@MtkN1 MtkN1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MtkN1 MtkN1 merged commit 3fe30f6 into pybotters:main Aug 26, 2022
@ko0hi ko0hi deleted the fix/put-item-in-store-stream-with-remove branch October 30, 2022 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataStore._removeでdelete情報が配信されない
2 participants