-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
222 lines (178 loc) · 7.7 KB
/
main.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
//#############################################
//###### NODE JS SAMPLE CODE, By Using fcs_forex.js
//#############################################
const FCSForex = require('./fcs_forex.js');
async function main() {
// Instantiate FCSForex with your API key
const forexApi = new FCSForex('git_key');
try {
const latestPrice = await forexApi.getLatestPrice('GBP/USD');
console.log("Latest Price :", latestPrice);
} catch (error) {
console.error("Error fetching latest prices:", error);
}
/*
//########################
//### Examples of using other methods for forex and crypto API
//########################
//#####################
//###########Get symbols list
//#####################
try {
const symbolsList = await forexApi.getSymbolsList();
console.log("Symbols List:", symbolsList);
} catch (error) {
console.error("Error fetching symbols list:", error);
}
//#####################
//########### Get profile of a currency
//#####################
try {
const symbolProfile = await forexApi.getProfile("GBP");
console.log("Currency Profile :", symbolProfile);
const symbolProfileMulti = await forexApi.getProfile("EUR,USD,JPY");
console.log("Currency Profile:", symbolProfileMulti);
const symbolProfileId = await forexApi.getProfile("1,2,3,4");
console.log("Currency Profile:", symbolProfileId);
} catch (error) {
console.error("Error fetching currency profiles:", error);
}
//#####################
//########### Convert currency
//#####################
try {
const conversionResult = await forexApi.getConverter(200, 'EUR', 'USD');
console.log("Conversion Result (200 EUR to USD):", conversionResult);
const conversionResult1 = await forexApi.getConverter(200, 'EUR/USD');
console.log("Conversion Result (200 EUR/USD):", conversionResult1);
} catch (error) {
console.error("Error converting currency:", error);
}
//#####################
//########### Get Latest Price
//#####################
try {
const latestPriceAllForex = await forexApi.getLatestPrice("all_forex");
console.log("Latest Price for all_forex:", latestPriceAllForex);
const latestPrice = await forexApi.getLatestPrice('GBP/USD');
console.log("Latest Price :", latestPrice);
const latestPriceMultiple = await forexApi.getLatestPrice(["EUR/USD", "JPY/USD"]);
console.log("Latest Price for multiple currencies:", latestPriceMultiple);
const latestPriceById = await forexApi.getLatestPrice("40");
console.log("Latest Price by ID:", latestPriceById);
} catch (error) {
console.error("Error fetching latest prices:", error);
}
//#####################
//########### Get Base Prices
//#####################
try {
const basePricesEUR = await forexApi.getBasePrices("EUR");
console.log("Base Prices for EUR:", basePricesEUR);
const basePricesForex = await forexApi.getBasePrices('EUR', 'forex', true);
console.log("Base Prices for EUR with forex:", basePricesForex);
const basePricesCrypto = await forexApi.getBasePrices('EUR', 'crypto');
console.log("Base Prices for EUR and crypto:", basePricesCrypto);
} catch (error) {
console.error("Error fetching base prices:", error);
}
//#####################
//########### Get Last Candle
//#####################
try {
const lastCandle5m = await forexApi.getLastCandle("all_forex", '5m');
console.log("Last Candle for 5m:", lastCandle5m);
const lastCandle1h = await forexApi.getLastCandle("1", '1h', 'both');
console.log("Last Candle for 1h:", lastCandle1h);
const lastCandle1d = await forexApi.getLastCandle("all_forex", '1d');
console.log("Last Candle for 1d:", lastCandle1d);
const candleData = await forexApi.getLastCandle("1,2,3", '1h');
console.log("Candle Data for IDs:", candleData);
} catch (error) {
console.error("Error fetching candle data:", error);
}
//#####################
//########### Get Currency History
//#####################
try {
const historyData1 = await forexApi.getHistory({
id: '98',
period: '1d',
level: '10',
from: '2024-01-01',
to: '2024-10-31'
});
console.log("History Data for different currencies:", historyData1);
const historyData2 = await forexApi.getHistory({
id: '1',
period: '1h'
});
console.log("History Data for EURUSD:", historyData2);
} catch (error) {
console.error("Error fetching currency history:", error);
}
//#####################
//########### Get Pivot Points
//#####################
async function getPivotPoints() {
let pivotPoints = await forexApi.getPivotPoints('2', '1h');
console.log('Pivot Points:', pivotPoints);
console.log('Pivot Points1:', pivotPoints.response.pivot_point);
console.log('Pivot Points2:', pivotPoints.response.pivot_point.classic);
}
getPivotPoints();
try {
const pivotPointsEURUSD = await forexApi.getPivotPoints("EUR/USD", '1d');
console.log("Pivot Points for EUR/USD:", pivotPointsEURUSD);
const pivotPointsUSD = await forexApi.getPivotPoints('9', '1d');
console.log("Pivot Points for USD:", pivotPointsUSD.response.pivot_point);
} catch (error) {
console.error("Error fetching pivot points:", error);
}
//#####################
//########### Get Moving Averages
//#####################
try {
const movingAverages1 = await forexApi.getMovingAverages("1", '1d');
console.log("Moving Averages for 1:", movingAverages1);
const movingAveragesEURUSD = await forexApi.getMovingAverages('NZD/USD', '1h');
console.log("Moving Averages for EUR/USD:", movingAveragesEURUSD);
} catch (error) {
console.error("Error fetching moving averages:", error);
}
//#####################
//########### Get Technical Indicators
//#####################
try {
const indicators1 = await forexApi.getTechnicalIndicator("1", '1d');
console.log("Technical Indicators for 1:", indicators1);
const indicatorsEURUSD = await forexApi.getTechnicalIndicator("EUR/USD", '1d');
console.log("Technical Indicators for EUR/USD:", indicatorsEURUSD);
} catch (error) {
console.error("Error fetching technical indicators:", error);
}
//#####################
//########### Get Economy Calendar
//#####################
try {
const economyCalendarUSD = await forexApi.getEconomyCalendar("USD", '2024-01-01', '2024-10-31');
console.log("Economy Calendar for USD:", economyCalendarUSD);
const economyCalendarUSDJPY = await forexApi.getEconomyCalendar("USD,JPY");
console.log("Economy Calendar for USD and JPY:", economyCalendarUSDJPY);
} catch (error) {
console.error("Error fetching economy calendar:", error);
}
//#####################
//########### Search API
//#####################
try {
const searchResultsStrict0 = await forexApi.getSearchQuery("BTC Dollar", 0);
console.log("Search Results (strict=0):", searchResultsStrict0);
const searchResultsStrict1 = await forexApi.getSearchQuery("BTC Dollar", 1);
console.log("Search Results (strict=1):", searchResultsStrict1);
} catch (error) {
console.error("Error fetching search results:", error);
}
*/
}
main().catch(error => console.error("Error in main function:", error));