Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 29, 2025

OTC candles from get_candles() all appeared RED/DOJI because the parser assumed wrong field order. Server sends [timestamp, open, close, high, low], not [timestamp, open, low, high, close].

Changes

  • _parse_candles_data: Fixed field mapping to read close from index 2, high from 3, low from 4
  • _parse_stream_candles: Changed minimum length check from 6 to 5 elements for consistency

Before/After

# Server data: [1754529180, 0.92124, 0.92155, 0.92162, 0.92120]
# Indices:     [timestamp,  open,    close,   high,    low   ]

# Before: close=0.92120 (wrong - read from idx 4)
# After:  close=0.92155 (correct - read from idx 2)

Reference format confirmed via BinaryOptionsTools-v2 candle parser.

Original prompt

This section details on the original issue you should resolve

<issue_title>All retrieved OTC candles RED issue</issue_title>
<issue_description>The candles returned from get_candles("GBPJPY_otc", 60, 20) are not real.
They don’t reflect the actual chart — all are red or doji.

Looks like something is wrong with how OTC data is fetched or interpreted.

Please check.

2025-07-25 18:02:05.939 | SUCCESS | pocketoptionapi_async.client:_on_json_data:1027 - Candles data received: 96 candles for GBPJPY_otc
2025-07-25 18:02:05.940 | INFO | pocketoptionapi_async.client:get_candles:495 - Retrieved 96 candles for GBPJPY_otc
2025-07-25 18:02:05.947 | INFO | pocketoptionapi_async.client:disconnect:347 - Disconnecting from PocketOption...
2025-07-25 18:02:05.948 | INFO | pocketoptionapi_async.websocket_client:disconnect:296 - Disconnecting from WebSocket
2025-07-25 18:02:05.948 | DEBUG | pocketoptionapi_async.websocket_client:_process_message:565 - Received message: 451-["updateStream",{"_placeholder":true,"num":0}]
2025-07-25 18:02:05.948 | DEBUG | pocketoptionapi_async.client:_on_stream_update:1166 - 📡 Stream update: {'_placeholder': True, 'num': 0}
🟩🟥 Candle Colors (Oldest → Newest):

  1. 2025-07-25 18:22:00 | O: 207.84800, C: 207.78500 → Δ: -0.06300 (-0.03%) 🟥 RED
  2. 2025-07-25 18:23:00 | O: 207.99600, C: 207.99600 → Δ: +0.00000 (+0.00%) ⬛ DOJI
  3. 2025-07-25 18:24:00 | O: 208.17000, C: 208.02600 → Δ: -0.14400 (-0.07%) 🟥 RED
  4. 2025-07-25 18:25:00 | O: 208.32900, C: 208.31900 → Δ: -0.01000 (-0.00%) 🟥 RED
  5. 2025-07-25 18:26:00 | O: 208.47800, C: 208.44800 → Δ: -0.03000 (-0.01%) 🟥 RED
  6. 2025-07-25 18:27:00 | O: 208.67200, C: 208.66400 → Δ: -0.00800 (-0.00%) 🟥 RED
  7. 2025-07-25 18:28:00 | O: 208.75900, C: 208.72700 → Δ: -0.03200 (-0.02%) 🟥 RED
  8. 2025-07-25 18:29:00 | O: 208.89900, C: 208.71600 → Δ: -0.18300 (-0.09%) 🟥 RED
  9. 2025-07-25 18:30:00 | O: 208.71100, C: 208.61200 → Δ: -0.09900 (-0.05%) 🟥 RED
  10. 2025-07-25 18:31:00 | O: 208.77900, C: 208.69300 → Δ: -0.08600 (-0.04%) 🟥 RED
  11. 2025-07-25 18:32:00 | O: 208.87500, C: 208.78900 → Δ: -0.08600 (-0.04%) 🟥 RED
  12. 2025-07-25 18:33:00 | O: 208.89600, C: 208.68300 → Δ: -0.21300 (-0.10%) 🟥 RED
  13. 2025-07-25 18:34:00 | O: 208.71500, C: 208.58300 → Δ: -0.13200 (-0.06%) 🟥 RED
  14. 2025-07-25 18:35:00 | O: 208.58400, C: 208.40600 → Δ: -0.17800 (-0.09%) 🟥 RED
  15. 2025-07-25 18:36:00 | O: 208.45900, C: 208.23600 → Δ: -0.22300 (-0.11%) 🟥 RED
  16. 2025-07-25 18:37:00 | O: 208.23700, C: 208.09700 → Δ: -0.14000 (-0.07%) 🟥 RED
  17. 2025-07-25 18:38:00 | O: 208.14000, C: 208.06300 → Δ: -0.07700 (-0.04%) 🟥 RED
  18. 2025-07-25 18:39:00 | O: 208.19000, C: 208.19000 → Δ: +0.00000 (+0.00%) ⬛ DOJI
  19. 2025-07-25 18:40:00 | O: 208.24400, C: 208.03700 → Δ: -0.20700 (-0.10%) 🟥 RED
  20. 2025-07-25 18:41:00 | O: 208.05400, C: 207.98000 → Δ: -0.07400 (-0.04%) 🟥 RED

My code:

import asyncio
import traceback
from pocketoptionapi_async import AsyncPocketOptionClient

async def check_otc_candle_colors():

    ssid = ''
    
    asset = "GBPJPY_otc"
    timeframe = 60  # 1-minute candles
    count = 10

    print(f"\n🔍 Fetching last {count} 1-minute candles for {asset.upper()}...\n")

    client = AsyncPocketOptionClient(
        ssid=ssid,
        is_demo=False,
        uid=107249156,
        platform=2,
        enable_logging=True
    )

    try:
        await client.connect()
        candles = await client.get_candles(asset, timeframe, count)

        if not candles:
            print("⚠️ No candle data received.")
            return

        # Reverse for proper order (oldest to newest)
        candles = list(reversed(candles))

        print("🟩🟥 Candle Colors (Oldest → Newest):")
        print("-" * 80)
        for i, candle in enumerate(candles, 1):
            o = candle.open
            c = candle.close
            delta = c - o
            pct = (delta / o * 100) if o else 0
            color = "🟩 GREEN" if c > o else "🟥 RED" if c < o else "⬛ DOJI"

            print(
                f"{i:>2}. {candle.timestamp.strftime('%Y-%m-%d %H:%M:%S')} | "
                f"O: {o:.5f}, C: {c:.5f} → Δ: {delta:+.5f} ({pct:+.2f}%) {color}"
            )

    except Exception as e:
        print("\n❌ Error occurred:")
        traceback.print_exc()
    finally:
        await client.disconnect()
        print("\n✅ Disconnected.")

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

```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@theshadow76</author><body>
The latest API is BinaryOptionsToolsV2 </body></comment_new>
<comment_new><author>@theshadow76</author><body>
https://github.com/ChipaDevTeam/BinaryOptionsTools-v2</body></comment_new>
<comment_new><author>@theshadow76</author><body>
Try with the demo ssid, I think the format is incorrect of ...

</details>

- Fixes ChipaDevTeam/PocketOptionAPI#36

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

@coderabbitai
Copy link

coderabbitai bot commented Nov 29, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI and others added 2 commits November 29, 2025 11:46
…open, close, high, low]

Co-authored-by: theshadow76 <59869868+theshadow76@users.noreply.github.com>
Co-authored-by: theshadow76 <59869868+theshadow76@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix all retrieved OTC candles to reflect actual data Fix OTC candle data parsing field order Nov 29, 2025
Copilot AI requested a review from theshadow76 November 29, 2025 11:51
@theshadow76 theshadow76 marked this pull request as ready for review November 29, 2025 12:22
Copilot AI review requested due to automatic review settings November 29, 2025 12:22
@theshadow76 theshadow76 merged commit de33747 into main Nov 29, 2025
1 check passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical bug in OTC candle data parsing where incorrect field order mapping caused all retrieved OTC candles to appear RED or DOJI. The server sends candle data as [timestamp, open, close, high, low], but the code was incorrectly parsing it as [timestamp, open, low, high, close], causing the close price to be read from the wrong index (4 instead of 2).

Key Changes

  • Corrected field mapping in _parse_candles_data to read close from index 2, high from index 3, and low from index 4
  • Updated _parse_stream_candles with the same correct field order and adjusted minimum length check from 6 to 5 elements for consistency
  • Removed unnecessary high/low swapping logic since the correct indices are now being used

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants