Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathstrategy_example.py
More file actions
Latest commit
64 lines (46 loc) · 1.75 KB
/
Copy pathstrategy_example.py
File metadata and controls
64 lines (46 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
importasyncio
importjson
importos
fromdotenvimportload_dotenv
fromBinaryOptionsToolsV2importPyBot, PyStrategy, RawPocketOption, start_tracing
load_dotenv()
classMyRSIStrategy(PyStrategy):
def__init__(self, rsi_period=14):
super().__init__()
self.rsi_period=rsi_period
self.prices= {}
self._tasks=set()
defon_start(self, _ctx):
print("Strategy started!")
defon_candle(self, ctx, asset, candle_json):
candle=json.loads(candle_json)
print(f"New candle for {asset}: {candle['close']}")
# Simple logic: if price ends in .5, buy (just for demo)
ifstr(candle["close"]).endswith("5"):
print(f"Signal detected on {asset}! Buying...")
# ctx.buy returns a future
task=asyncio.create_task(self.execute_trade(ctx, asset))
self._tasks.add(task)
task.add_done_callback(self._tasks.discard)
asyncdefexecute_trade(self, ctx, asset):
try:
result=awaitctx.buy(asset, 1.0, 60)
print(f"Trade executed: {result}")
exceptExceptionase:
print(f"Trade failed: {e}")
asyncdefmain():
start_tracing("info")
ssid=os.getenv("POCKET_OPTION_SSID")
ifnotssid:
print("Please set POCKET_OPTION_SSID in .env file")
return
print("Connecting to PocketOption...")
client=awaitRawPocketOption.create(ssid)
strategy=MyRSIStrategy()
bot=PyBot(client, strategy)
# Add assets to monitor (60s candles)
bot.add_asset("EURUSD_otc", 60)
print("Running bot... Press Ctrl+C to stop.")
awaitbot.run()
if__name__=="__main__":
asyncio.run(main())