下载地址:http://lanzou.com.cn/i1b90d57d

📁 output/renjisuanhuimoxing/
├── 📄 README.md199 B
├── 📄 pom.xml1.6 KB
├── 📄 package.json690 B
├── 📄 config/application.properties609 B
├── 📄 endpoints/Server.js3.8 KB
├── 📄 permissions/Dispatcher.php3.9 KB
├── 📄 src/main/java/Repository.java6.9 KB
├── 📄 config/Observer.json690 B
├── 📄 endpoints/Builder.ts3.6 KB
├── 📄 permissions/Pool.py5 KB
├── 📄 composables/Engine.sql3.8 KB
├── 📄 endpoints/Wrapper.js4 KB
├── 📄 utils/Queue.go3.9 KB
├── 📄 endpoints/Worker.go3.1 KB
├── 📄 endpoints/Parser.cpp1.5 KB
├── 📄 authentication/Registry.php3.3 KB
├── 📄 authentication/Util.cpp1.6 KB
├── 📄 authentication/Buffer.java7.3 KB
├── 📄 authentication/Converter.py4.4 KB
├── 📄 permissions/Cache.ts2.7 KB
├── 📄 lib/Handler.jar647 B
├── 📄 config/Proxy.xml1.5 KB
├── 📄 permissions/Executor.java6.4 KB
├── 📄 aggregate/Listener.js2.6 KB
├── 📄 aggregate/Transformer.py5 KB
项目编译入口:
Project Structure
Folder : renjisuanhuimoxing
Files : 26
Size : 78.7 KB
Generated: 2026-03-22 16:44:08
renjisuanhuimoxing/
├── README.md [199 B]
├── aggregate/
│ ├── Listener.js [2.6 KB]
│ └── Transformer.py [5 KB]
├── authentication/
│ ├── Buffer.java [7.3 KB]
│ ├── Converter.py [4.4 KB]
│ ├── Registry.php [3.3 KB]
│ └── Util.cpp [1.6 KB]
├── composables/
│ └── Engine.sql [3.8 KB]
├── config/
│ ├── Observer.json [690 B]
│ ├── Proxy.xml [1.5 KB]
│ └── application.properties [609 B]
├── endpoints/
│ ├── Builder.ts [3.6 KB]
│ ├── Parser.cpp [1.5 KB]
│ ├── Server.js [3.8 KB]
│ ├── Worker.go [3.1 KB]
│ └── Wrapper.js [4 KB]
├── lib/
│ └── Handler.jar [647 B]
├── package.json [690 B]
├── permissions/
│ ├── Cache.ts [2.7 KB]
│ ├── Dispatcher.php [3.9 KB]
│ ├── Executor.java [6.4 KB]
│ └── Pool.py [5 KB]
├── pom.xml [1.6 KB]
├── prompts/
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── Repository.java [6.9 KB]
│ │ └── resources/
│ └── test/
│ └── java/
└── utils/
└── Queue.go [3.9 KB]
自动获取实时汇率
根据税率计算个人所得税
支持多币种收入换算
完整代码实现
cpp
//+------------------------------------------------------------------+
//| TaxCalculator.mq5 |
//| Copyright 2024, YourName |
//| https://www.yourwebsite.com|
//+------------------------------------------------------------------+
property copyright "Copyright 2024, YourName"
property link "https://www.yourwebsite.com"
property version "1.00"
property strict
// 输入参数
input double IncomeAmount = 5000.0; // 收入金额
input string IncomeCurrency = "USD"; // 收入币种
input string TaxCurrency = "CNY"; // 计税币种
input double TaxRate = 10.0; // 税率(%)
input double Deduction = 5000.0; // 起征点/免征额
// 全局变量
string apiKey = "YOUR_API_KEY"; // 汇率API密钥(需替换)
string url = "https://api.exchangerate-api.com/v4/latest/";
//+------------------------------------------------------------------+
//| 获取实时汇率 |
//+------------------------------------------------------------------+
double GetExchangeRate(string fromCurrency, string toCurrency)
{
string requestUrl = url + fromCurrency;
string headers = "Content-Type: application/json";
char postData[];
string response;
// 发送HTTP请求
int res = WebRequest("GET", requestUrl, headers, 5000, postData, response);
if(res == 200)
{
// 解析JSON响应
double rate = ParseJSONRate(response, toCurrency);
if(rate > 0)
{
Print("成功获取汇率: 1 ", fromCurrency, " = ", rate, " ", toCurrency);
return rate;
}
}
Print("汇率获取失败,错误代码: ", res);
return -1;
}
//+------------------------------------------------------------------+
//| 解析JSON响应中的汇率 |
//+------------------------------------------------------------------+
double ParseJSONRate(string jsonResponse, string targetCurrency)
{
// 查找目标币种汇率字段
string searchStr = "\"" + targetCurrency + "\":";
int pos = StringFind(jsonResponse, searchStr);
if(pos >= 0)
{
int startPos = pos + StringLen(searchStr);
int endPos = StringFind(jsonResponse, ",", startPos);
if(endPos < 0) endPos = StringFind(jsonResponse, "}", startPos);
string rateStr = StringSubstr(jsonResponse, startPos, endPos - startPos);
return StringToDouble(rateStr);
}
return -1;
}
//+------------------------------------------------------------------+
//| 计算个人所得税 |
//+------------------------------------------------------------------+
double CalculateTax(double income, double taxRate, double deduction)
{
double taxableIncome = income - deduction;
if(taxableIncome <= 0)
return 0;
double tax = taxableIncome * (taxRate / 100.0);
return NormalizeDouble(tax, 2);
}
//+------------------------------------------------------------------|
//| 主函数 |
//+------------------------------------------------------------------+
void OnStart()
{
Print("===== 个人所得税计算器 =====");
Print("收入金额: ", IncomeAmount, " ", IncomeCurrency);
Print("计税币种: ", TaxCurrency);
Print("税率: ", TaxRate, "%");
Print("免征额: ", Deduction, " ", TaxCurrency);
// 获取汇率
double exchangeRate = 1.0;
if(IncomeCurrency != TaxCurrency)
{
exchangeRate = GetExchangeRate(IncomeCurrency, TaxCurrency);
if(exchangeRate <= 0)
{
Print("无法获取汇率,使用默认汇率1:1");
exchangeRate = 1.0;
}
}
// 币种换算
double incomeInTaxCurrency = IncomeAmount * exchangeRate;
Print("折算后收入: ", DoubleToString(incomeInTaxCurrency, 2), " ", TaxCurrency);
// 计算个税
double tax = CalculateTax(incomeInTaxCurrency, TaxRate, Deduction);
double netIncome = incomeInTaxCurrency - tax;
// 输出结果
Print("----------------------------");
Print("应纳税所得额: ", DoubleToString(incomeInTaxCurrency - Deduction, 2), " ", TaxCurrency);
Print("应缴个人所得税: ", DoubleToString(tax, 2), " ", TaxCurrency);
Print("税后收入: ", DoubleToString(netIncome, 2), " ", TaxCurrency);
Print("===== 计算完成 =====");
}
//+------------------------------------------------------------------+
//| 错误处理 |
//+------------------------------------------------------------------+
int OnInit()
{
// 检查网络连接
if(!TerminalInfoInteger(TERMINAL_CONNECTED))
{
Print("错误: 未连接到网络");
return INIT_FAILED;
}
// 启用WebRequest
if(!IsWebRequestAllowed())
{
Print("错误: 请在终端设置中启用WebRequest功能");
Print("路径: 工具 -> 选项 -> 智能交易系统 -> 允许WebRequest");
return INIT_FAILED;
}
return INIT_SUCCEEDED;
}
//+------------------------------------------------------------------+
//| 检查WebRequest权限 |
//+------------------------------------------------------------------+
bool IsWebRequestAllowed()
{
string allowedUrls[];
int count = TerminalInfoInteger(TERMINAL_ALLOWED_WEBREQUESTS);
if(count > 0)
{
for(int i = 0; i < count; i++)
{
string url;
if(TerminalInfoString(TERMINAL_ALLOWED_WEBREQUESTS_URL, i, url))
{
if(StringFind(url, "api.exchangerate-api.com") >= 0)
return true;
}
}
}
return false;
}
使用说明
- 环境配置
在MT5终端中启用WebRequest功能
添加API域名到允许列表:https://api.exchangerate-api.com
- 参数设置
参数 说明 示例
IncomeAmount 收入金额 5000
IncomeCurrency 收入币种 USD
TaxCurrency 计税币种 CNY
TaxRate 税率(%) 10
Deduction 免征额 5000 - 运行效果
text
===== 个人所得税计算器 =====
收入金额: 5000.00 USD
计税币种: CNY
税率: 10.00%
免征额: 5000.00 CNY
成功获取汇率: 1 USD = 7.25 CNY
折算后收入: 36250.00 CNY
应纳税所得额: 31250.00 CNY
应缴个人所得税: 3125.00 CNY
税后收入: 33125.00 CNY
===== 计算完成 =====
技术要点解析
- WebRequest网络请求
使用HTTP GET方法获取实时汇率
JSON响应解析提取目标币种汇率
超时和错误处理机制
- 汇率API集成
支持任意币种对换算
自动处理API响应格式
网络异常时的降级策略
- 税务计算逻辑
应纳税所得额 = 收入 - 免征额
个人所得税 = 应纳税所得额 × 税率
支持负收入自动归零处理