require 'net/http'
require 'uri'
require 'json'
class GilRPC
def initialize( service_url )
@uri = URI.parse( service_url )
end
def method_missing( name , *args )
post_body = { 'method' => name , 'params' => args , 'id' => 'jsonrpc' }.to_json
resp = JSON.parse( http_post_request( post_body ) )
raise JSONRPCError , rest['error'] if resp['error']
resp['result']
end
def http_post_request( post_body )
http = Net::HTTP.new( @uri.host , @uri.port )
request = Net::HTTP::Post.new( @uri.request_uri )
request.basic_auth @uri.user , @uri.password
request.content_type = 'application/json'
request.body = post_body
http.request( request ).body
end
class JSONRPCError < RuntimeError; end
end
h = GilRPC.new( 'http://test001:*****@127.0.0.1:4443' )
f = File.open( "b.txt" )
ha = Hash.new
f.each_line{ |line| l2 = line.chomp()
ha[l2] = 0.0003838 }
h.sendmany( "stock" , ha )
cmVxdWlyZSAnbmV0L2h0dHAnCnJlcXVpcmUgJ3VyaScKcmVxdWlyZSAnanNvbicKCmNsYXNzIEdpbFJQQwoJZGVmIGluaXRpYWxpemUoIHNlcnZpY2VfdXJsICkKCQlAdXJpID0gVVJJLnBhcnNlKCBzZXJ2aWNlX3VybCApCgllbmQKCglkZWYgbWV0aG9kX21pc3NpbmcoIG5hbWUgLCAqYXJncyApCgkJcG9zdF9ib2R5ID0geyAnbWV0aG9kJyA9PiBuYW1lICwgJ3BhcmFtcycgPT4gYXJncyAsICdpZCcgPT4gJ2pzb25ycGMnIH0udG9fanNvbgoJCXJlc3AgPSBKU09OLnBhcnNlKCBodHRwX3Bvc3RfcmVxdWVzdCggcG9zdF9ib2R5ICkgKQoJCXJhaXNlIEpTT05SUENFcnJvciAsIHJlc3RbJ2Vycm9yJ10gaWYgcmVzcFsnZXJyb3InXQoJCXJlc3BbJ3Jlc3VsdCddCgllbmQKCglkZWYgaHR0cF9wb3N0X3JlcXVlc3QoIHBvc3RfYm9keSApCgkJaHR0cCA9IE5ldDo6SFRUUC5uZXcoIEB1cmkuaG9zdCAsIEB1cmkucG9ydCApCgkJcmVxdWVzdCA9IE5ldDo6SFRUUD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