Mida is a JavaScript framework by Reiryoku-Technologies that can be used with cTrader to trade financial assets such as stocks, crypto, forex or commodities, to create feature-rich web applications and analyze the markets.
A JavaScript framework to easily operate in global financial markets
There is a core Mida library that you need to download and then a plugin for it to work with cTrader.
The example code below shows how you can connect to a cTrader broker account, you will need to get a clientId, clientSecret and accessToken by creating an account on cTrader Open API.
const { Mida, MidaBroker, } = require("@reiryoku/mida");
// Use the Mida cTrader plugin
Mida.use(require("@reiryoku/mida-ctrader"));
// Login into any cTrader broker account
const myAccount = await MidaBroker.login("cTrader", {
clientId: "",
clientSecret: "",
accessToken: "",
cTraderBrokerAccountId: "",
});
To execute a short market order with no stop loss or take profit for EURUSD you can use the following code block.
const { MidaBrokerOrderDirection, } = require("@reiryoku/mida");
const myOrder = await myAccount.placeOrder({
symbol: "EURUSD",
direction: MidaBrokerOrderDirection.SELL,
volume: 0.1,
});
The following code block shows how you can submit a long market order with a take profit and stop loss.
const { MidaBrokerOrderDirection, } = require("@reiryoku/mida");
const symbol = "EURUSD";
const lastBid = await myAccount.getSymbolBid(symbol);
const myOrder = await myAccount.placeOrder({
symbol,
direction: MidaBrokerOrderDirection.BUY,
volume: 0.1,
protection: {
stopLoss: lastBid - 0.0010, // <= SL 10 pips
takeProfit: lastBid + 0.0030, // <= TP 30 pips
},
});
How to check the order submission status from the broker.
if (myOrder.isRejected) {
switch (myOrder.rejectionType) {
case MidaBrokerOrderRejectionType.MARKET_CLOSED: {
console.log("#AAPL market is closed!");
break;
}
case MidaBrokerOrderRejectionType.NOT_ENOUGH_MONEY: {
console.log("You don't have enough money in your account!");
break;
}
case MidaBrokerOrderRejectionType.INVALID_SYMBOL: {
console.log("Your broker account doesn't support trading Apple stocks!");
break;
}
}
}
The Apollo JavaScript library gets real-time economic declarations from investing.com such as inflation rates, unemployment rates & interest rates reported by governments and other entities.
Name | Id | Value type | Source/s |
---|---|---|---|
U.S. Non Farm Payrolls (MoM) | US/NonFarmPayrolls/MoM | Pure number | Investing.com |
U.S. Crude Oil Inventories (WoW) | US/CrudeOilInventories/WoW | Pure number | Investing.com |
Eurozone CPI (YoY) | Eurozone/CPI/YoY | Percentage | Investing.com |
Italy CPI (YoY) | Italy/CPI/YoY | Percentage | Investing.com |
Japan CPI (YoY) | Japan/CPI/YoY | Percentage | Investing.com |
Canada Interest Rate CPI (MoM) | Canada/InterestRate/MoM | Percentage | Investing.com |
This is a basic list of economic factors, it is possible to edit a file and add more to the list and customise it to your needs.
First, you have to choose an economic factor and then request its declarations.
const { ApolloEconomicFactor } = require("@reiryoku/apollo");
const japanInflationRate = ApolloEconomicFactor.getById("Japan/CPI/YoY");
const lastDeclaration = await japanInflationRate.getLastDeclaration();
console.log(`Japan inflation rate is ${lastDeclaration.actualValue}%`);
console.log(`The last declaration was made on ${lastDeclaration.date}`);
By using a Javascript framework to connect to a cTrader broker to submit and manage orders as well as get the account information, a person can create a simple or complex web page that will be accessible to anyone with a web browser.
The Real-Time Economic Rates library can be used to display on your web page real news events as they happen.
There are various levels of support for this framework, as it is still fairly new the amount of documentation is limited, but we hope that at ClickAlgo we can fill that gap to help.