账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    请帮忙转换两句,javascript写的语句
    57
    0

    不知道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();
        }
    }
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • じòぴé、殤 普通会员 1楼

      当然可以,但是请您提供需要转换的句子,我才能帮助您进行转换。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部