PocketOptionAPI icon indicating copy to clipboard operation
PocketOptionAPI copied to clipboard

All retrieved OTC candles RED issue

Open singularcomplex opened this issue 1 year ago β€’ 34 comments

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())

singularcomplex avatar Jul 25 '25 13:07 singularcomplex

Bump.

singularcomplex avatar Jul 27 '25 17:07 singularcomplex

The latest API is BinaryOptionsToolsV2

theshadow76 avatar Jul 27 '25 17:07 theshadow76

BinaryOptionsToolsV2

Can you send me link, please?

singularcomplex avatar Jul 27 '25 18:07 singularcomplex

https://github.com/ChipaDevTeam/BinaryOptionsTools-v2

theshadow76 avatar Jul 27 '25 18:07 theshadow76

https://github.com/ChipaDevTeam/BinaryOptionsTools-v2

Finally got it to install. This is my script, and it's not working with my SSID. I did exactly as stated in your doc file to copy AUTH from WS at Network tab. Not sure what I'm doing wrong. Please check.

import asyncio
from BinaryOptionsToolsV2.pocketoption.asyncronous import PocketOptionAsync

SSID = '42["auth",{"session":"a:4:{s:10:\"session_id\";s:32:\"[REDACTED_SESSION_ID]\";s:10:\"ip_address\";s:12:\"[REDACTED_IP]\";s:10:\"user_agent\";s:111:\"[REDACTED_USER_AGENT]\";s:13:\"last_activity\";i:[REDACTED_TIMESTAMP];}[REDACTED_SIGNATURE]","isDemo":0,"uid":[REDACTED_UID],"platform":2,"isFastHistory":true,"isOptimized":true}]'

async def main():
    client = PocketOptionAsync(ssid=SSID)

    try:
        print("πŸ“‘ Fetching latest 10 candles for EURUSD_otc...")

        candles = await client.get_candles("EURUSD_otc", period=60, offset=10)

        print("πŸ•’ Historical 1-Minute Candles (Latest Last):\n")
        for c in candles:
            print(
                f"{c['time']} | Open: {c['open']} | High: {c['high']} | "
                f"Low: {c['low']} | Close: {c['close']}"
            )
    except Exception as e:
        print("❌ Error:", e)
    finally:
        await asyncio.sleep(1)
        print("βœ… Done.")


# Run the async main
if __name__ == "__main__":
    asyncio.run(main())

Traceback (most recent call last): File "C:\Users\user\PycharmProjects\G_Diego\test_ssid.py", line 29, in asyncio.run(main()) File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 650, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "C:\Users\user\PycharmProjects\G_Diego\test_ssid.py", line 7, in main client = PocketOptionAsync(ssid=SSID) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\PycharmProjects\G_Diego.venv\Lib\site-packages\BinaryOptionsToolsV2\pocketoption\asyncronous.py", line 21, in init self.client = RawPocketOption(ssid) ^^^^^^^^^^^^^^^^^^^^^ ValueError: PocketOptionError, Failed to parse SSID: expected , or } at line 1 column 24

singularcomplex avatar Jul 28 '25 16:07 singularcomplex

Try with the demo ssid, I think the format is incorrect of that ssid

theshadow76 avatar Jul 28 '25 16:07 theshadow76

Try with the demo ssid, I think the format is incorrect of that ssid

I want to try with real ssid for real trading. How should the format be?

Tried it with demo, doesn't work... Not sure what I'm doing wrong.

import asyncio
from BinaryOptionsToolsV2.pocketoption.asyncronous import PocketOptionAsync

SSID = '42["auth",{"session":"ogkoou7dd7ua8lio0hl4bhbjrk","isDemo":1,"uid":107249156,"platform":2,"isFastHistory":true,"isOptimized":true}]'

async def main():
    client = PocketOptionAsync(ssid=SSID)

    try:
        print("πŸ“‘ Fetching latest 10 candles for EURUSD_otc...")

        candles = await client.get_candles("EURUSD_otc", period=60, offset=10)

        print("πŸ•’ Historical 1-Minute Candles (Latest Last):\n")
        for c in candles:
            print(
                f"{c['time']} | Open: {c['open']} | High: {c['high']} | "
                f"Low: {c['low']} | Close: {c['close']}"
            )
    except Exception as e:
        print("❌ Error:", e)
    finally:
        await asyncio.sleep(1)
        print("βœ… Done.")


# Run the async main
if __name__ == "__main__":
    asyncio.run(main())

πŸ“‘ Fetching latest 10 candles for EURUSD_otc... Failded once trying again ❌ Error: PocketOptionError, BinaryOptionsToolsError, Failed to execute 'GetCandles' task before the maximum allowed time of '16s' βœ… Done.

singularcomplex avatar Jul 28 '25 16:07 singularcomplex

I think get candles does not work, you need to use the subscribe_symbol function

theshadow76 avatar Jul 28 '25 16:07 theshadow76

Like this: https://github.com/ChipaDevTeam/BinaryOptionsTools-v2/blob/master/examples%2Fpython%2Fasync%2Fsubscribe_symbol_timed.py

theshadow76 avatar Jul 28 '25 16:07 theshadow76

I think get candles does not work, you need to use the subscribe_symbol function

I need to get candles OHCL to determine if it's red/green - latest 10 candles. I do not want to subscribe to websocket. I hope I understood you clearly. I just want it to be like REST API - to query candlesticks.

singularcomplex avatar Jul 28 '25 17:07 singularcomplex

Sure, we'll, soon @Rick-29 will let you know once it starts working

theshadow76 avatar Jul 28 '25 17:07 theshadow76

Try passing the ssid as an input. Something like PocketOptionAsync(input("Enter ssid: "))

If that works then the error is on how python processes the strings.

Rick-29 avatar Jul 28 '25 17:07 Rick-29

Sure, we'll, soon @Rick-29 will let you know once it starts working

This doesn't work either. Tried demo SSID.

from BinaryOptionsToolsV2.pocketoption import PocketOptionAsync

import pandas as pd
import asyncio


# Main part of the code
async def main(ssid: str):
    # The api automatically detects if the 'ssid' is for real or demo account
    api = PocketOptionAsync(ssid)
    await asyncio.sleep(5)

    # Candles are returned in the format of a list of dictionaries
    candles = await api.history("EURUSD_otc", 3600)
    print(f"Raw Candles: {candles}")
    candles_pd = pd.DataFrame.from_dict(candles)
    print(f"Candles: {candles_pd}")


if __name__ == '__main__':
    ssid = input('Please enter your ssid: ')
    asyncio.run(main(ssid))

C:\Users\user\PycharmProjects\G_Diego.venv\Scripts\python.exe C:\Users\user\PycharmProjects\G_Diego\test_ssid2.py Please enter your ssid: 42["auth",{"session":"ogkoou7dd7ua8lio0hl4bhbjrk","isDemo":1,"uid":107249156,"platform":2,"isFastHistory":true,"isOptimized":true}] Failded once trying again Traceback (most recent call last): File "C:\Users\user\PycharmProjects\G_Diego\test_ssid2.py", line 22, in asyncio.run(main(ssid)) File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 650, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "C:\Users\user\PycharmProjects\G_Diego\test_ssid2.py", line 14, in main candles = await api.history("EURUSD_otc", 3600) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\PycharmProjects\G_Diego.venv\Lib\site-packages\BinaryOptionsToolsV2\pocketoption\asyncronous.py", line 117, in history return json.loads(await self.client.history(asset, period)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: PocketOptionError, BinaryOptionsToolsError, Failed to execute 'History' task before the maximum allowed time of '16s'

Process finished with exit code 1

singularcomplex avatar Jul 28 '25 17:07 singularcomplex

I think this issue is with the history function

theshadow76 avatar Jul 28 '25 17:07 theshadow76

the error is very simple to solve, the latest release on pypi is not working. check here for the latest wheels for windows https://github.com/ChipaDevTeam/BinaryOptionsTools-v2/tree/master/wheels

Rick-29 avatar Jul 28 '25 17:07 Rick-29

the error is very simple to solve, the latest release on pypi is not working. check here for the latest wheels for windows https://github.com/ChipaDevTeam/BinaryOptionsTools-v2/tree/master/wheels

Uninstalled, and installed a wheel for 3.11 python. 'history' error this time...

Re-tried the code:

from BinaryOptionsToolsV2.pocketoption import PocketOptionAsync

import pandas as pd
import asyncio


# Main part of the code
async def main(ssid: str):
    # The api automatically detects if the 'ssid' is for real or demo account
    api = PocketOptionAsync(ssid)
    await asyncio.sleep(5)

    # Candles are returned in the format of a list of dictionaries
    candles = await api.history("EURUSD_otc", 3600)
    print(f"Raw Candles: {candles}")
    candles_pd = pd.DataFrame.from_dict(candles)
    print(f"Candles: {candles_pd}")


if __name__ == '__main__':
    ssid = input('Please enter your ssid: ')
    asyncio.run(main(ssid))

Please enter your ssid: 42["auth",{"session":"ogkoou7dd7ua8lio0hl4bhbjrk","isDemo":1,"uid":107249156,"platform":2,"isFastHistory":true,"isOptimized":true}] Traceback (most recent call last): File "C:\Users\user\PycharmProjects\G_Diego\test_ssid2.py", line 22, in asyncio.run(main(ssid)) File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 650, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "C:\Users\user\PycharmProjects\G_Diego\test_ssid2.py", line 14, in main candles = await api.history("EURUSD_otc", 3600) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\PycharmProjects\G_Diego.venv\Lib\site-packages\BinaryOptionsToolsV2\pocketoption\asyncronous.py", line 307, in history raise NotImplementedError( NotImplementedError: The history method is not implemented in the PocketOptionAsync class.

singularcomplex avatar Jul 28 '25 17:07 singularcomplex

@Rick-29 does the get candles work?

theshadow76 avatar Jul 28 '25 18:07 theshadow76

It works but for the binaryoptionstoolsv2 library

Rick-29 avatar Jul 28 '25 19:07 Rick-29

The history function is not implemented

Rick-29 avatar Jul 28 '25 20:07 Rick-29

I'm trying to get latest last 1 min candles for EURUSD_OTC, but the charts do not match with PocketOption demo. Please tell me what's wrong. They're different candles.

from BinaryOptionsToolsV2.pocketoption import PocketOptionAsync
import pandas as pd
import asyncio
import mplfinance as mpf

async def main(ssid: str):
    print("πŸ“‘ Fetching latest 10 candles for EURUSD_otc...")
    api = PocketOptionAsync(ssid)
    await asyncio.sleep(5)

    try:
        # Get 10 x 1-min candles ending now (period = 60s * 10, offset = 60)
        candles = await api.get_candles("EURUSD_otc", period=60, offset=600)
        print(f"βœ… Candles received: {len(candles)}")

        if not candles or len(candles) < 10:
            print("⚠️ Not enough candle data received.")
            return

        df = pd.DataFrame(candles)

        # Fix for either 'time' or 'timestamp' key depending on server output
        ts_col = 'timestamp' if 'timestamp' in df.columns else 'time'
        df[ts_col] = pd.to_datetime(df[ts_col], unit='s')
        df.set_index(ts_col, inplace=True)

        df.rename(columns={
            'open': 'Open',
            'high': 'High',
            'low': 'Low',
            'close': 'Close'
        }, inplace=True)

        df.sort_index(inplace=True)
        df = df.tail(10)

        df.to_csv("latest_10_candles.csv")
        print("πŸ“ Saved to 'latest_10_candles.csv'")

        mpf.plot(
            df,
            type='candle',
            style='charles',
            title='EURUSD_otc - Last 10 1min Candles',
            ylabel='Price',
            volume=False
        )

    except Exception as e:
        print("❌ Error:", e)

if __name__ == '__main__':
    ssid = '42["auth",{"session":"ogkoou7dd7ua8lio0hl4bhbjrk","isDemo":1,"uid":107249156,"platform":2,"isFastHistory":true,"isOptimized":true}]'
    asyncio.run(main(ssid))

singularcomplex avatar Jul 29 '25 18:07 singularcomplex