Exemplo n.º 1
0
 def CancelOrderFull(self, order_id):
     try:
         order_deals = self.GetOrderDeals(order_id)
         type = order_deals["type"]
         cur1 = order_deals["in_currency"]
         cur2 = order_deals["out_currency"]
         pair = self._ToPair(cur1, cur2) if type == "buy" else self._ToPair(cur2, cur1)
         for trade in order_deals["trades"]:
             if type == "buy":
                 if self.GetCurrentSellRate(pair) > float(trade["price"]):
                     sell_quantity = float(trade["quantity"])
                     sell_quantity -= sell_quantity - float(trade["commission_amount"])
                     self.CreateOrder_SellMarket(pair, sell_quantity)
                 else:
                     error = c_errors.CannotCreateBuyOrder()
                     error.SetDescription("current sell-rate is less than buy-rate for order-deal")
                     raise error
             elif type == "sell":
                 if self.GetCurrentBuyRate(pair) < float(trade["price"]):
                     buy_cost = float(trade["amount"])
                     buy_cost -= float(trade["commission_amount"])
                     self.CreateOrder_BuyMarketTotal(pair, buy_cost)
                 else:
                     error = c_errors.CannotCreateSellOrder()
                     error.SetDescription("current buy-rate is more than sell-rate for order-deal")
                     raise error
     except c_errors.OrderIsNotFoundByID:
         pass
     return common.ExecuteOrRepeat(common.Lambda(self._QueryPrivate, "order_cancel", order_id=order_id))
Exemplo n.º 2
0
Arquivo: ut.py Projeto: rvbb/pylearn
def main():
    b1 = b.Demo()
    b1.abc()

    print("multi is ", a1.multi(2, 3))

    # object2 = a2.Ob2()
    # print(object2.add(2,3))
    c1 = c.Common()
    # del c1
    c1.json()
    c.Common().json_dump()

    #list
    l = c.List()
    l.make_alist()
    l.remove_duplicate()

    #tuple
    t = c.Tuple()
    t.make()

    #set
    s = c.Set()
    s.make()

    #dict
    d = c.Dict()
    d.make()
    anyobject = c.AnyObject("A", "B")
    d.of(anyobject)

    #Operation
    o = c.Ops()
    s1 = o.make()
    print(s1)

    r1 = "abc"[::-1]
    print(r1)

    #Lambda
    lamb = c.Lambda()
    print(lamb.make(5))
Exemplo n.º 3
0
    def Query(cls, api_method, publick_key="STUMP", secret_key=bytes("STUMP", encoding="utf-8"), **params):
        connection.Wait.WaitingGlobal(1)
        def ComputeHash(data):
            """ computes hash-value from target https-request """
            hash = hmac.new(key=secret_key, digestmod=hashlib.sha512)
            hash.update(data.encode('utf-8'))
            return hash.hexdigest()

        params["nonce"] = int(round(time.time() * 1000))
        params = urllib.parse.urlencode(params)
        headers = {
            # type of data for sign
            "Content-type": "application/x-www-form-urlencoded",
            # publick-key for check data sign
            "Key": publick_key,
            # signed data for request
            "Sign": ComputeHash(params) # подписанные данные
        }
        conn = http.client.HTTPSConnection(cls.url)
        common.ExecuteOrRepeat(common.Lambda(conn.request, "POST", "/" + cls.api_version + "/" + api_method, params, headers))
        response = conn.getresponse().read()
        conn.close()
        result = json.loads(response.decode('utf-8'))
        if "error" in result and result["error"]:
            error_message = result["error"]
            error = None
            if "Error 50304" in error_message:
                error = c_errors.OrderIsNotFoundByID()
            elif "Error 50052" in error_message:
                error = c_errors.InsufficientFundsForOrder()
            elif "Error 40016" in error_message:
                error = c_errors.MaintenanceWorkInProgres()
                # NOTE: in this case it is reasonable to wait at least one minute
                time.sleep(60)
            else:
                error = c_errors.QueryError()
                error.SetDescription(error_message)
            raise error
        return result
Exemplo n.º 4
0
 def Update(self):
     self.Check()
     trueview = common.TryExecute(
         common.Lambda(self._GetOrderTrueview, self._id))
     self._ExecuteOne(self._sql["set_trueview"], trueview, self._id)
Exemplo n.º 5
0
 def GetUserDeals(self, pair, limit=100, offset=0):
     return common.ExecuteOrRepeat(common.Lambda(self._QueryPrivate, "user_trades", pair=pair, limit=limit, offset=offset))
Exemplo n.º 6
0
 def GetUserCancelledOrders(self, limit=100, offset=0):
     return common.ExecuteOrRepeat(common.Lambda(self._QueryPrivate, "user_cancelled_orders", limit=limit, offset=offset))
Exemplo n.º 7
0
 def GetUserOpenOrders(self):
     return common.ExecuteOrRepeat(common.Lambda(self._QueryPrivate, "user_open_orders"))
Exemplo n.º 8
0
 def GetUserInfo(self):
     return common.ExecuteOrRepeat(common.Lambda(self._QueryPrivate, "user_info"))
Exemplo n.º 9
0
 def _CreateOrder(self, **order_parameters):
     return common.ExecuteOrRepeat(common.Lambda(self._QueryPrivate, "order_create", **order_parameters))
Exemplo n.º 10
0
 def GetCurrencyList(cls):
     return common.ExecuteOrRepeat(common.Lambda(cls.Query, "currency"))
Exemplo n.º 11
0
 def GetPairSettings(cls):
     return common.ExecuteOrRepeat(common.Lambda(cls.Query, "pair_settings"))
Exemplo n.º 12
0
 def GetTicker(cls):
     return common.ExecuteOrRepeat(common.Lambda(cls.Query, "ticker"))
Exemplo n.º 13
0
 def GetOrderBook(cls, pair, limit=100):
     return common.ExecuteOrRepeat(common.Lambda(cls.Query, "order_book", pair=pair, limit=limit))
Exemplo n.º 14
0
 def GetTrades(cls, pair):
     return common.ExecuteOrRepeat(common.Lambda(cls.Query, "trades", pair=pair))
Exemplo n.º 15
0
 def CancelOrder(self, order_id):
     return common.ExecuteOrRepeat(common.Lambda(self._QueryPrivate, "order_cancel", order_id=order_id))