diff --git a/supernode/main.html b/supernode/main.html index 1c0fe9a..61226a4 100644 --- a/supernode/main.html +++ b/supernode/main.html @@ -6876,7 +6876,8 @@ var ninja = { wallets: {}, trade: {}, - keys_management: {} + keys_management: {}, + rpc:{} }; ninja.privateKey = { @@ -7333,23 +7334,125 @@ + + + }, + validate_order(order_type, product, currency, buy_price, buyer_public_key, buyer_key_signature, order_validator_public_key) { + if(this.valid_order_type.indexOf(order_type) >= 0) { + this.order_type = order_type; + } else { + this.errors.push("Inavlid trade type value."); + } + if(this.valid_product.indexOf(product)>=0) { + this.product = product; + } else { + this.errors.push("Invalid product."); + } + if(this.valid_currencies.indexOf(currency)>=0) { + this.currency = currency; + } else { + this.errors.push("Invalid currency."); + } + if(typeof buy_price == "number" && buy_price > 0) { + this.buy_price = buy_price; + } else { + this.errors.push("Invalid buying price. Please place a valid buy amount."); + } + if(buyer_public_key.length > 0) { + this.buyer_public_key = buyer_public_key; + } else { + this.errors.push("Invalid Buyer's public key."); + } + if(buyer_key_signature.length > 0) { + this.buyer_key_signature = buyer_key_signature; + } else { + this.errors.push("Invalid Buyer's key signature."); + } + if(order_validator_public_key.length > 0) { + this.order_validator_public_key = order_validator_public_key; + } else { + this.errors.push("Invalid Validator's key signature."); + } + if(this.errors.length > 0) { + return this.errors; + } + return true; + }, + place_order(order_type, product, currency, buy_price, buyer_public_key, buyer_key_signature, order_validator_public_key) { + var is_valid_order = this.validate_order(order_type, product, currency, buy_price, buyer_public_key, buyer_key_signature, order_validator_public_key); + if(is_valid_order === true) { + var orderRPC = new ninja.rpc(); + var sendOrder = orderRPC.send_rpc(this.order_type, this.product, this.currency, this.buy_price, this.buyer_public_key, this.buyer_key_signature, this.order_validator_public_key); + return sendOrder; + } else if(is_valid_order == "object") { + var err; + for(err=0; err + + \ No newline at end of file