Cross Platform Arbitrage Beginner Test
JavaScript strategy by cnxzcxy.
JavaScriptArbitrage
The original spec has no written description. Read the source below.
Parameters
| Name | Default | What it controls |
|---|---|---|
| minRate | 1.02 | Price difference ratio |
Source JavaScript
/*backtest
start: 2018-01-01 00:00:00
end: 2018-08-01 14:00:00
period: 1h
exchanges: [{"eid":"Bitfinex","currency":"ETH","balance":5000,"stocks":10},{"eid":"OKCoin_EN","currency":"ETH","balance":5000,"stocks":10}]
*/
var buyExchange;
var sellExchange;
function calc(sellExchange, buyExchange){
var date = _D();
sellDepth = sellExchange.GetDepth();
sellAccount = sellExchange.GetAccount();
sellPrice = sellDepth.Bids[1].Price;
sellAmount = sellDepth.Bids[1].Amount;
buyDepth = buyExchange.GetDepth();
buyAccount = buyExchange.GetAccount();
buyPrice = buyDepth.Asks[1].Price;
buyAmount = buyDepth.Asks[1].Amount;
amount = (sellAmount > buyAmount) ? buyAmount : sellAmount;
amount = (amount > sellAccount.Stocks) ? sellAccount.Stocks : amount;
amount = (amount > buyAccount.Balance / buyPrice) ? buyAccount.Balance / buyPrice : amount;
priceRate = sellPrice / buyPrice;
if(amount > 0){
if(priceRate >= minRate){
buyExchange.Buy(-1, amount);
sellExchange.Sell(-1, amount);
Log(date);
Log("sell:", sellExchange.GetName(), "Selling price:", sellPrice, "buy:", buyExchange.GetName(), " Buy price:", buyPrice, " Proportion:", priceRate, " Total:", amount);
Log('Statistics assets...');
Log('exchange:', exchanges[0].GetName(), ' Account:', exchanges[0].GetAccount());
Log('exchange:', exchanges[1].GetName(), ' Account:', exchanges[1].GetAccount());
}
}
}
function main(){
while(true){
calc(exchanges[0], exchanges[1]);
calc(exchanges[1], exchanges[0]);
}
}
Published by cnxzcxy on the FMZ strategy square · last modified 2018-09-12. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a spread arbitrage engine with WebSocket order routing and leg-risk controls from strategies/Cross-Platform-Arbitrage-Beginner-Test.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- OKEx Futures HedgingJavaScript · Arbitrage
- RSI Statistical Arbitrage StrategyJavaScript · Arbitrage
- Summary of Funding Rates Across Major ExchangesJavaScript · Arbitrage
- Triangular Arbitrage to Earn Small Coin Bid Ask SpreadJavaScript · Arbitrage
- Hedge_BTC ETH DemoJavaScript · Arbitrage
- Multi Platform Hedging Stable ArbitrageJavaScript · Arbitrage