admin

Guideline to call App function in strategy script

How it work


Dear all users, we are pleased to announced that ALGOGENE cloud environment now supports calling app functions from ALGOGENE App Store.


As an example, suppose we are interested to use the Fourier Predictor as an indicator for trade decision making.

First of all, we need to create our API key. If you haven't done so, you can simply create from [Settings] > [User Profile] > [System Info]

Generate API Key

Next, according to the app's technical implementation,

  • Endpoint is https://algogene.com/rest/v1/bot/15/fourier.predict
  • 3 input parameters
    • instrument
    • numForc
    • timestamp

Then, the app function can be initiated under "def start" as follows.

From self.evt.app_init(), we specify the app's endpoint and our API key information. Here, we name the app function variable as "self.app1".

1
2
3
4
5
6
7
    def start(self, mEvt):
        self.evt = AlgoAPI_Backtest.AlgoEvtHandler(self, mEvt)

        headers = {"user":"xxx", "apikey":"xxx"}
        self.app1 = self.evt.app_init("https://algogene.com/rest/v1/bot/15/fourier.predict", headers=headers)

        self.evt.start()

After that, we can call the app function in the backtest or live script using "self.evt.app_call()".

Refer to line #20-21 below,

  • the first input is the app function variable
  • the second input is the parameter set required for the app
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from AlgoAPI import AlgoAPIUtil, AlgoAPI_Backtest
from datetime import datetime, timedelta

class AlgoEvent:
    def __init__(self):
        self.timer = datetime(1970,1,1)

    def start(self, mEvt):
        self.evt = AlgoAPI_Backtest.AlgoEvtHandler(self, mEvt)

        headers = {"user":"xxx", "apikey":"xxx"}
        self.app1 = self.evt.app_init("https://algogene.com/rest/v1/bot/15/fourier.predict", headers=headers)

        self.evt.start()

    def on_marketdatafeed(self, md, ab):
        if md.timestamp >= self.timer+timedelta(hours=24):
            self.timer = md.timestamp

            params = {"instrument":"AAPL", "numForc":14, "timestamp":md.timestamp}
            res = self.evt.app_call(self.app1, params)

            self.evt.consoleLog(res)

Running above backtest script, we can get the result from 'console' section.

console

See, we can successfully get the expected JSON result as mentioned in the technical document!

1
2
3
4
{
    "upper": 143.74,
    "lower": 133.67
  }


Now, you know how to call an app function in your strategy script. It might provides new investment insights and indicators for improving your strategy performance! Time to try it yourself now!

Happy Trading! :)


 
Kelvin Yeung
How does it charge if I call other apps in my script? 
 
admin
Original Posted by - b'Kelvin Yeung': How does it charge if I call other apps in my script? 
The price for different apps are varying. Please check out App Store for details. 

When you call the app function in a script, it will charge from your algogene wallet for every 100 requests. 
If your wallet has insufficient amount, the request will return errors.