From ed67c9c810d7a9402cf109dc0addf23f3506c09b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 5 Mar 2018 17:53:33 +0100 Subject: [PATCH] Put Position Migrated --- .vs/AACloudPlatform/v15/.suo | Bin 61440 -> 59392 bytes ExchangeAPI.js | 89 +++++++++++++++++++++++++++++------ 2 files changed, 74 insertions(+), 15 deletions(-) diff --git a/.vs/AACloudPlatform/v15/.suo b/.vs/AACloudPlatform/v15/.suo index a15361a8fb1e9912bc2bcfc70ca59c8895505875..fa3a099cbfea4ab1c1b7b217ac2efd32cf24d9fb 100644 GIT binary patch delta 110 zcmZp8z}#?wd4ho~69W_oFfecdnan`^@Bjb*AW`OxzVb}04U_8A7HlqL`pwMRaNB6& n!p((jX6pq_KnkGX3y@aYykqNoc|l{C7?1`DGi=^*)k6pX*oYdw delta 134 zcmZp;z})bFd4j=Y0~bya0R{$61_lOZApZCN|9>FGz_`&@o{9Cr&6_XgZ7yW`&CJR$ z)yN6RWHVbYcm|{Z3Lb;#%{#WfmlxE6i2><}Ky0&l$5juZMJJdh7lf-#-mu?g@`c?h ToBJ*lF-~rI7O*+s$p&Tsa=j}( diff --git a/ExchangeAPI.js b/ExchangeAPI.js index 6e98b61ca..f23e1e508 100644 --- a/ExchangeAPI.js +++ b/ExchangeAPI.js @@ -13,8 +13,7 @@ initialize: initialize, getOpenPositions: getOpenPositions, getExecutedTrades: getExecutedTrades, - putBuyPosition: putBuyPosition, - putSellPosition: putSellPosition, + putPosition: putPosition, movePosition: movePosition }; @@ -239,24 +238,84 @@ } } - function putBuyPosition() { + function putPosition(pMarket, pType, pRate, pAmountA, pAmountB, callBackFunction) { try { + if (pType === "buy") { + poloniexApiClient.buy(pMarket.assetA, pMarket.assetB, pRate, pAmountB, onExchangeCallReturned); + } else { + poloniexApiClient.sell(pMarket.assetA, pMarket.assetB, pRate, pAmountB, onExchangeCallReturned); + } + + function onExchangeCallReturned(err, exchangeResponse) { + + try { + + if (err || exchangeResponse.error !== undefined) { + try { + + if (err.message.indexOf("ETIMEDOUT") > 0) { + + logger.write("[WARN] putPosition -> onExchangeCallReturned -> Timeout reached while trying to access the Exchange API. Requesting new execution later. : ERROR = " + err.message); + callBackFunction("Retry Later."); + return; + + } else { + + if (err.message.indexOf("ECONNRESET") > 0) { + + logger.write("[WARN] putPosition -> onExchangeCallReturned -> The exchange reseted the connection. Requesting new execution later. : ERROR = " + err.message); + callBackFunction("Retry Later."); + return; + + } else { + logger.write("[ERROR] putPosition -> onExchangeCallReturned -> Unexpected error trying to contact the Exchange. This will halt this bot process. : ERROR = " + err.message); + callBackFunction("Operation Failed."); + return; + } + } + + } catch (err) { + logger.write("[ERROR] putPosition -> onExchangeCallReturned -> exchangeResponse.error = " + exchangeResponse.error); + callBackFunction("Operation Failed."); + return; + } + + return; + + } else { + + /* + + This is what we can receive from the exchange. + + { + "orderNumber":31226040, + "resultingTrades": + [{ + "amount":"338.8732", + "date":"2014-10-18 23:03:21", + "rate":"0.00000173", + "total":"0.00058625", + "tradeID":"16164", + "type":"buy" + }] + } + + */ + + callBackFunction(null, exchangeResponse.orderNumber); + } + } + catch (err) { + logger.write("[ERROR] putPosition -> onExchangeCallReturned -> Error = " + err.message); + callBackFunction("Operation Failed."); + } + } } catch (err) { - logger.write("[ERROR] putBuyPosition -> err = " + err); - callBackFunction("Operation Failed."); - } - } - - function putSellPosition() { - - try { - - - } catch (err) { - logger.write("[ERROR] putSellPosition -> err = " + err); + logger.write("[ERROR] putPosition -> err = " + err); callBackFunction("Operation Failed."); } }