---
# System prepended metadata

title: 網格profit_log分享
tags: [crypto]

---

###### tags: `crypto`

# 網格profit_log分享

## 參考來源
> 其他主要程式碼 請參考YK大的 FTX GAS機器人
https://yk-invest.notion.site/FTX-Google-Apps-Script-558c4f7f01c34361ad0b6d1a6641bb43

## 示意圖
![](https://i.imgur.com/Ty5b9dO.png)

## 參考程式碼
```javascript=
//想取得獲利相關資訊，請執行 profit_log
function profit_log() {
    str = "";
    grid_pct = settings.grid_pct / 100
    grid_volume = settings.grid_volume

    var market_name = user.baseCurrency + "/" + user.quoteCurrency;
    api_balances = APIGetBalances()
    market = APIGetSingleMarket(market_name)

    str += "\n現在時間: " + new Date(Date.now()).toLocaleString()
    str += "\n" + user.baseCurrency + "/" + user.quoteCurrency + "現價: " + market.price;

    orders = APIGetOrders(market_name);

    basetotal = GetBalances(user.baseCurrency).total
    quotetotal = GetBalances(user.quoteCurrency).total

    str += "\n目前掛單======= ";
    orders.forEach(element => {
        str += "\n" + element.side + ":" + element.price + " x " + element.size
    });

    str += "\n============ ";

    up_ratio = 1 + grid_pct
    down_ratio = 1 / up_ratio

    up_grids_num = Math.floor(basetotal / grid_volume);
    down_grids_num = Math.floor(Math.log(1 + quotetotal * (down_ratio - 1) / market.price / grid_volume) / Math.log(down_ratio));

    str += "\n總價值: " + Number(basetotal * market.price + quotetotal).toFixed(2);
    str += "\n" + user.baseCurrency + "餘額: " + Number(basetotal).toFixed(4);
    str += "\n" + user.quoteCurrency + "餘額: " + Number(quotetotal).toFixed(2);
    str += "\n上漲格數: " + up_grids_num;
    str += "\n下跌格數: " + down_grids_num;
    str += "\n網格上限: " + Number(market.price * Math.pow(up_ratio, up_grids_num)).toFixed(2);
    str += "\n網格下限: " + Number(market.price * Math.pow(down_ratio, down_grids_num)).toFixed(2);
    str += "\n============ ";
    str += "\n總計獲利: " + user.quoteCurrency + "$" + Number(user.profit).toFixed(3);
    str += "\n總計買入次數: " + user.fill_buy;
    str += "\n總計買入顆數: " + Number(user.size_buy).toFixed(3);
    str += "\n總計賣出次數: " + user.fill_sell;
    str += "\n總計賣出顆數: " + Number(user.size_sell).toFixed(3);
    Logger.log(str);
    return str
}
```