import time import urllib2 from lib.client import Client, get_api_path client = Client(access_key='your access key', secret_key='your secret key') #demo of GET APIs #get member info print client.get(get_api_path('members')) #get markets markets = client.get(get_api_path('markets')) print "markets:", markets #get tickers of each market #market should be specified in url print print "tickers in markets" for market in markets: print client.get(get_api_path('tickers') % market['id']) #get orders of each market #market should be specified in params print print "orders in markets" for market in markets: print client.get(get_api_path('orders'), {'market': market['id']}) #get order book print client.get(get_api_path('order_book'), params={'market': 'btcaud'})
import time import urllib2 from lib.client import Client, get_api_path client = Client(access_key='', secret_key='') #demo of GET APIs #get member info print client.get(get_api_path('members')) #get markets markets = client.get(get_api_path('markets')) print "markets:", markets #get tickers of each market #market should be specified in url print print "tickers in markets" for market in markets: print client.get(get_api_path('tickers') % market['id']) #get orders of each market #market should be specified in params print print "orders in markets" for market in markets: print client.get(get_api_path('orders'), {'market': market['id']}) #get order book print client.get(get_api_path('order_book'), params={'market': 'btccny'})
import time import urllib2 from lib.client import Client, get_api_path client = Client(access_key="your access key", secret_key="your secret key") # demo of GET APIs # get member info print client.get(get_api_path("members")) # get markets markets = client.get(get_api_path("markets")) print "markets:", markets # get tickers of each market # market should be specified in url print print "tickers in markets" for market in markets: print client.get(get_api_path("tickers") % market["id"]) # get orders of each market # market should be specified in params print print "orders in markets" for market in markets: print client.get(get_api_path("orders"), {"market": market["id"]}) # get order book print client.get(get_api_path("order_book"), params={"market": "btccny"})
import time import urllib.request from lib.client import Client, get_api_path client = Client(access_key='', secret_key='') #demo of GET APIs #get member info print(client.get(get_api_path('members'))) #get markets markets = client.get(get_api_path('markets')) print("markets:", markets) #get tickers of each market #market should be specified in url print() print("tickers in markets") # for market in markets: # print(market) # print(client.get(get_api_path('tickers') % market['id'])) print(client.public_get(get_api_path('tickers')%'btccny')) #get orders of each market #market should be specified in params # print () # print("orders in markets") # for market in markets: # print (client.get(get_api_path('orders'), {'market': market['id']}))
class Server: def __init__(self, address): self.client = Client(address) self.probe_name = socket.gethostname() self.services = None def register_probe(self, services: Dict[str, Service]) -> None: """ Register the probe on startup or reconfiguration. :param services: List of services that this probe is able to provide. """ self.services = services self.client.put("probe", json={ "name": self.probe_name, "services": [ { "name": service.name, "description": service.description, "options": [ { "identifier": option_identifier, "name": option["name"], "type": option["type"], "description": option.get("description", ""), "required": option.get("required", False), } for option_identifier, option in service.options.items() ], "thresholds": { reading: { "status": status, "min": values.get("min"), "max": values.get("max") } for reading, statuses in service.thresholds.items() for status, values in statuses.items() } } for service in services.values() ] }) def get_mapped_services(self) -> List[ServiceMapping]: """ Return list of mapped services. :return: """ mappings = self.client.get("services/%s" % (self.probe_name, ), params={ "show": ["id", "name", "service", "options.identifier", "options.value"] }) out = [] for mapping in mappings: if mapping["service"] in self.services: out.append(ServiceMapping( mapping["id"], self.services[mapping["service"]], { option["identifier"]: option["value"] for option in mapping["options"] if option["value"] is not None }, mapping["name"] )) return out def update(self, fetch_result: dict, time_point: datetime=None) -> None: """ Post new values fetched from services. :param fetch_result: Result of fetched services. :param time_point: Point in time when the fetch was taken. :return: """ logging.info("Update readings for %s:" % (time_point.strftime("%Y-%m-%d %H:%M:%S"))) # Build up readings to post to server. readings = [] for mapping, values in fetch_result.items(): for key, val in values.items(): readings.append({ "service": mapping, "reading": key, "value": int(val), "timestamp": time_point.isoformat() }) logging.debug(" Service %d %s=%s" % (mapping, key, val)) self.client.put("/readings/%s" % (self.probe_name, ), json=readings)
import time import urllib2 import sys import json from lib.client import Client, get_api_path client = Client(access_key='ZURvhizTAkcw2aYcnYQ9Jn3CYKNREeDcNdl1HXlp', secret_key='TYJeyNkXH1y7CD3xW64u6NbNsfgdIwJmlPfzsx58') #client = Client(access_key='E4xWabtFKMWrj2YAwIyg3LHIml0ACLP2Cr1', secret_key='3p33k2yF22lE0nHJxwr5lN8R1gu44cBC6JV') ##################### #get member info ######################### member = (client.get(get_api_path('members'))) print "Name:", member['name'] print "memo:", member['memo'] print "sn:", member['sn'] print "email:", member['email'] print "active:", member['activated'] print "Account:" for i in range(0, len(member['accounts'])): print " ", member['accounts'][i]['currency'], "Balance: ", member[ 'accounts'][i]['balance'], "Locked: ", member['accounts'][i]['locked'] print print ##################### #get markets ######################
import time import urllib.request import urllib.error import urllib from lib.client import Client, get_api_path client = Client(access_key='ACCESS_KEY', secret_key='SECRET_KEY') #demo of GET APIs #get member info print ("memo") print (client.get(get_api_path('members'),None, True)) #get markets markets = client.get(get_api_path('markets')) print ("markets:", markets) #get tickers of each market print ("tickers in markets") print (client.get(get_api_path('tickers') % 'btscny')) for market in markets: print(str(market["id"])) print (client.get(get_api_path('tickers') % market["id"])) print (client.get(get_api_path('orders'), {'market':'daocny'}, True)) #get orders of each market #market should be specified in params