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

Other Technicals or Indicators #7

Open
The-Sal opened this issue Sep 21, 2024 · 3 comments
Open

Other Technicals or Indicators #7

The-Sal opened this issue Sep 21, 2024 · 3 comments
Labels
feature request Used to request a feature good first issue

Comments

@The-Sal
Copy link

The-Sal commented Sep 21, 2024

Hi,

I was wondering if there was anyways to update the code to get things like RSI, MACD and other technicals that are based on the tick-by-tick prices and historic data. So get live RSI essentially.

Thanks!

@Hattorius
Copy link
Owner

Hattorius commented Sep 21, 2024

Isn't that something you could calculate yourself with the technical analysis library?
https://technical-analysis-library-in-python.readthedocs.io/en/latest/

@The-Sal
Copy link
Author

The-Sal commented Sep 21, 2024

So the issue say something like RSI on the 1m time frame, you need the last 14 periods (14 mins) to determine the current RSI. Say something like IBKR API (ibasync) they usually give data but it's delayed 15mins. So you cant calculate the current RSI since it's delayed by too much. So with this library we'd have the latest 'price' but not the other 14 periods to calculate RSI. Unless you buy market data from IBKR, or other brokers. You could technically wait 14 mins and wait for the data to populate from this library and then calculate it. But not live RSI straight away if that makes sense.

@Hattorius
Copy link
Owner

Ah, I guess that makes sense. I wanted so say that this was outside of the scope of this project. But some historical data for calculations would be useful. I'm not certain when I'll have the time to work on this, so I'll just write down how to make this work, and maybe someone would be as kind to implement this. Otherwise I'll pick it up when I have time.

For this data, you'd need to use the self.cs session, which is already initiated within the library. When initiating a ticker, the following message should be sent to the websocket:

{
    "m": "resolve_symbol",
    p: [
        self.cs,
        "sds_sym_3",
        "={\"adjustment\":\"splits\",\"currency-id\":\"USD\",\"session\":\"regular\",\"symbol\":\"BITSTAMP:BTCUSD\"}"
    ]
}

You have to change BITSTAMP:BTCUSD to whatever ticker you're interested in. From my testing it eventually responds with a message that has a length over 450k (might be more or less if you test it). This message has multiple partial messages, you have to look through them and find the timescale_update message. It will look like this:

{
  "m": "timescale_update",
  "p": [
    "cs_********",
    {
      "sds_1": {
        "node": "THIS DOESN'T MATTER",
        "s": [
          {
            "i": 0,
            "v": [
              1726761960,
              63248,
              63263,
              63217,
              63263,
              1.45475737
            ]
          },
          {
            "i": 1,
            "v": [
              1726762020,
              63276,
              63307,
              63269,
              63298,
              3.56578803
            ]
          },
          {
            "i": 2,
            "v": [
              1726762080,
              63298,
              63329,
              63298,
              63324,
              0.68806982
            ]
          },
          ...
        ]
      }
    }
  ]
}

The values are the following (in order): EPOCH timestamp, open, high, low, close, change. For the last value, I'd like to think it's change %, already displayed in %. So 0.68806982 really is 0.6%. But I'm not certain about that one.

Some important things for implementing this:

  • This should be optionally enabled, so a new class option called history should be added
  • If history is True it will send the extra message in the authenticate() function
  • There should be a separate handler function for the timescale_update messages (just like forTicker())
  • The handler function should be called from the parseMessage() function, like I did here before

Cool ˙ᵕ˙

@Hattorius Hattorius added feature request Used to request a feature good first issue labels Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Used to request a feature good first issue
Projects
None yet
Development

No branches or pull requests

2 participants