Skip to content

Commit 75b3de2

Browse files
Update Code.gs
1 parent 80ae653 commit 75b3de2

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

‎Code.gs‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ function sell(){
315315

316316

317317

318-
if(diffPercent <= 0){
318+
if(diffPercent <= 0 || market_value == 0){
319319
sheet.getRange("O"+parseFloat(9+i)).setValue("skipping...")
320320
targetSell = parseFloat(sheet.getRange("B4").getValue())*(qty/100)
321321

@@ -397,7 +397,7 @@ function rebalance(){
397397

398398

399399

400-
if(diffPercent <= 0){
400+
if(diffPercent <= 0 || market_value == 0){
401401
sheet.getRange("O"+parseFloat(9+i)).setValue("skipping...")
402402
continue;
403403

@@ -432,6 +432,11 @@ soldAmount += (parseFloat(getAccount().cash) - SpreadsheetApp.getActiveSpreadshe
432432
var diffPercent = parseFloat(getPosition(sym).market_value)/market_value - (qty)/100
433433
var targetBuy = 0.00;
434434
var position = getPosition(sym)
435+
if(position.message.includes("does not exist")){
436+
position = {
437+
"market_value": 0
438+
}
439+
}
435440

436441

437442
// if(percent) {
@@ -455,7 +460,7 @@ soldAmount += (parseFloat(getAccount().cash) - SpreadsheetApp.getActiveSpreadshe
455460
}
456461
else {
457462
var b_resp = submitOrder(sym,null,side,types.buy[i].toString().trim(),tifs.buy[i].toString().trim(),limits.buy[i].toString().trim(),stops.buy[i].toString().trim(),extendedHours,targetBuy)
458-
//console.log(b_resp)
463+
// console.log(b_resp)
459464

460465
soldAmount -= parseFloat(b_resp.notional);
461466
sheet.getRange("G"+parseFloat(9+i)).setValue(truncateJson(b_resp))
@@ -534,6 +539,7 @@ function getAccount() {
534539
});
535540
}
536541

542+
537543
function listOrders() {
538544
return _request("/v2/orders",{
539545
method: "GET",
@@ -554,6 +560,7 @@ function getPosition(sym) {
554560
muteHttpExceptions: true
555561
});
556562
}
563+
557564
// uses latest trades as price point
558565
function getPrice(sym) {
559566
return _request(("/v2/stocks/"+sym+"/trades/latest"), {

0 commit comments

Comments
 (0)