请帮忙转换两句,javascript写的语句

新手上路,请多包涵

不知道javascript语言写的代码怎么转换成python语言,请大神指点一下。

就是下面这两句代码不知道怎么用python写出来

 一、for(var i=0;i<20;i++){
 二、 for(var j=0; j<20; j++){

这下面是javascript原代码

//稍微改了一下,用了平台的容错函数_C(),和精度函数_N().
//取消全部订单
function CancelPendingOrders() {
    var orders = _C(exchange.GetOrders);
    for (var j = 0; j < orders.length; j++) {
          exchange.CancelOrder(orders[j].Id, orders[j]);}
}

//计算将要下单的价格
function GetPrice(Type) {
    var depth=_C(exchange.GetDepth);
    var amountBids=0;
    var amountAsks=0;
    //计算买价,获取累计深度达到预设的价格
    if(Type=="Buy"){
       for(var i=0;i<20;i++){
           amountBids+=depth.Bids[i].Amount;
           //floatamountbuy就是预设的累计买单深度
           if (amountBids>floatamountbuy){
               //稍微加0.01,使得订单排在前面
              return depth.Bids[i].Price+0.01;}
        }
    }
    //同理计算卖价
    if(Type=="Sell"){
       for(var j=0; j<20; j++){
           amountAsks+=depth.Asks[j].Amount;
            if (amountAsks>floatamountsell){
            return depth.Asks[j].Price-0.01;}
        }
    }
    //遍历了全部深度仍未满足需求,就返回一个价格,以免出现bug
    return depth.Asks[0].Price
}
 
function onTick() {
    var buyPrice = GetPrice("Buy");
    var sellPrice= GetPrice("Sell");
    //买卖价差如果小于预设值diffprice,就会挂一个相对更深的价格
    if ((sellPrice - buyPrice) <= diffprice){
            buyPrice-=10;
            sellPrice+=10;}
    //把原有的单子全部撤销,实际上经常出现新的价格和已挂单价格相同的情况,此时不需要撤销
    CancelPendingOrders() 
    //获取账户信息,确定目前账户存在多少钱和多少币
    var account=_C(exchange.GetAccount);
    //可买的比特币量
    var amountBuy = _N((account.Balance / buyPrice-0.1),2); 
    //可卖的比特币量,注意到没有仓位的限制,有多少就买卖多少,因为我当时的钱很少
    var amountSell = _N((account.Stocks),2); 
    if (amountSell > 0.02) {
        exchange.Sell(sellPrice,amountSell);}
    if (amountBuy > 0.02) {
        exchange.Buy(buyPrice, amountBuy);}
    //休眠,进入下一轮循环
    Sleep(sleeptime);
}
    
function main() {
    while (true) {
        onTick();
    }
}
阅读 1.5k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题