Alchemy API

Alchemy API service Logo.













You will find below the documentation of the Quotek Alchemy API client. With it you will be able to perform on text content advanced sentiment analysis, categorization or relations finding, these tools being the key factors for accurately analysing financial news. You can register for a free API key at the following URL: http://www.alchemyapi.com/api/register.html



class quotek::nlp::alchemy

alchemy is a class which aims to help quotek strategies interract with Alchemy API NLP service. Alchemy API Service contains some very useful functionalities like sentiment analysis, etc..

Note: Only the API calls which are most useful to algo-trading are added here.

Public Functions

alchemy(std::string key, std::string endpoint)

alchemy class constructor.

Parameters
  • key -

    Alchemy API Key.

  • host -

    Alchemy host endpoint.

~alchemy()

alchemy object destructor.

quotek::nlp::sentiment sentiment(std::string payload, std::string target, std::string format)

Sentiment Analysis method. The payload text/url passed as argument is sent to the API for further analysis. The detected sentiment is then returned as a quotek::nlp::sentiment object.

Return
sentiment of text computed by Alchemy.
Parameters
  • payload -

    Text or URL of text to analyse.

  • target -

    tells for which target sentiment must be processed. Target is optional and therefore can be an empty string.

  • format -

    tells wether payload is text, html, or url.

std::vector<quotek::nlp::relation> relations(std::string payload, std::string format)

relations is able to summerize a text and basically return it under a “Who doest what” form.

Return
a vector quotek::nlp::relations
Parameters
  • payload -

    Text or URL of text to analyse relashionships for.

  • format -

    tells wether payload is text, html, or url.

std::vector<quotek::nlp::category> taxonomy(std::string payload, std::string format)

taxonomy categorizes a text corpus in a pre-existing category-tree. You can get the full category-tree at http://www.alchemyapi.com/sites/default/files/taxonomyCategories.zip

Parameters
  • payload -

    Text or URL of text to get taxonomy for.

  • format -

    tells wether payload is text, html, or url.

std::string language(std::string payload, std::string format)

language function guesses the language used to write the text passed as argument.

Return
Detect Language string.
Parameters
  • payload -

    Text or URL of text to analyse.

  • format -

    tells wether payload is text, html, or url.

std::string raw(std::string call, std::map<std::string, std::string> parameters)

Since alchemy binding is only partially supported, raw() allows to perform an API call by letting the user choose which call to use and also which parameters to pass it. It will then return the Alchemy server response in raw form (no parsing). Note about API calls: You can find the whole list of Alchemy API Calls and full documentation here: http://www.alchemyapi.com/api Note about call parameters: You are not required to add apikey in the parameters list, since raw() will append it for you.

Return
ALchemy server response as raw text.
Parameters
  • call -

    name of the Alchemy API call (without URI format prefix).

  • parameters -

    POST parameters to send with the call.

Example

You will find below and sample source code about how to use the alchemy API client for sentiment analysis.

#include <quotek/quotek.hpp>
#include <quotek/alchemy.hpp>
using namespace quotek::ml;

int main(int argc, char** argv) {

  //we declare a text corpus for analysis

  std::string txt = "Before you knew it, it was an all-out Eastern USD reserve liquidation party, leading some to ask what effect the drawdowns would ultimately have on UST yields because all else equal, FX reserve selling is just QE in reverse.";

  //We create a new alchemy object
  alchemy al("JSKJS-09304832-SJ0390S");

  //We ask Alchemy API an sentiment analysis on text txt
  sentiment sent = al.sentiment(txt,"text");

  //We display sentiment on standard output.
  std::cout << "TEXT SENTIMENT:" << sent.sentimentstr << std::endl;

}