When I am trying to run the below subscription code I am getting the error:
TypeError: Invalid or incomplete introspection result. Ensure that you are > passing the 'data' attribute of an introspection response and no 'errors' > were returned alongside: None.
What can I do to correct this?
from operator import concat
from gql import Client, gql
from gql.transport.aiohttp import AIOHTTPTransport
from graphql import get_introspection_query
import pandas as pd
from gql.transport.websockets import WebsocketsTransport
# Select your transport with a defined url endpoint
count =0
transport = WebsocketsTransport(url='wss://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2')
# Create a GraphQL client using the defined transport
client = Client(
transport=transport,
fetch_schema_from_transport=True
)
# Provide a GraphQL query
lastID=""
query = gql(
"""
subscription swaps{
swaps(orderBy: timestamp, orderDirection: desc) {
id
timestamp
amount0In
amount1In
amount0Out
amount1Out
pair {
token0 {
id
symbol
}
token1 {
id
symbol
}
}
}
}
"""
)
for result in client.subscribe(query):
print (result)
Related
I have this below soap envelope where I have send string array.
<apiKey xsi:type="xsd:string">Ab12-Ab12-Ab12-Ab12</apiKey>ยง
<baseScheduleRollout xsi:type="flex:baseScheduleRollout" xmlns:flex="http://app.quinyx.com/soap/FlexForce">
<badgeNos xsi:type="flex:ArrayOfString" soapenc:arrayType="xsd:string[]">
<item1>1022</item1>
<item2>1030</item2>
<item2>10112330</item2>
</badgeNos>
<fromDateTime xsi:type="xsd:dateTime">2020-11-05T00:00:00</fromDateTime>
<toDateTime xsi:type="xsd:dateTime">2020-11-24T00:00:00</toDateTime>
I know how to send a soap request and my complextype is okay. But I think my string array passing system is wrong. Though I tried to use anyObject but still not working
from zeep import Client
from zeep import xsd
import datetime
from requests import Session
from requests.auth import HTTPBasicAuth
from zeep.transports import Transport
wsdl = "https://api.quinyx.com/FlexForceWebServices.php?wsdl"
session = Session()
session.auth = HTTPBasicAuth('username', 'password')
client = Client(wsdl, transport=Transport(session=session))
ArrayOfString = client.get_element('ns0:ArrayOfObject')
badgeNo = ArrayOfString(['146223'])
data = { "apiKey" : "apikey" ,
"baseScheduleRollout" :{
"badgeNos":badgeNo,
"fromDateTime":xsd.SkipValue,
"toDateTime":xsd.SkipValue
}
}
result = client.service.wsdlGetBaseScheduleRolledoutHours(**data)
result
Error
LookupError: No element 'ArrayOfObject' in namespace https://api.quinyx.com/soap/FlexForce. Available elements are: -
I've been using KuCoin API with python for a while now, but stuck trying to get advanced orders form the API. For reference, 'advanced orders' are what stop limit orders are called within KuCoin dash.
I've used the endpoint: api/v1/orders
. I've experimented with this but it only shows 'normal' orders or the order history if 'status' is set to 'done'. Ref: https://docs.kucoin.com/#list-orders
I'm wondering if instead I should use: /api/v1/limit/orders. This endpoint has an option to return stop_limit orders. But when I try, I get response:
{"code":"400007","msg":"Access denied, require more permission."}'
I checked my API permissions and its 'General' permission is set to 'read only' which is the only option. Read only would be fine for me because I only want to get the list of all 'Advanced orders'
See https://docs.kucoin.com/#recent-orders
Does anyone know how to get all open limit orders please? The reason I want this is I have placed many limit orders. I want to collect the orderid's of all stop limit orders so I can clean out just the ones not associated to an active trade.
my code is as follows:
import requests
import json
import hmac
import hashlib
import base64
from urllib.parse import urlencode
import time
from urllib.request import urlretrieve
'''working code to get active orders'''
api_key = 'api_key'
api_secret = 'api_secret'
api_passphrase = 'api_passphrase' # this is NOT trading password
base_uri = 'https://api.kucoin.com'
def get_headers(method, endpoint):
now = int(time.time() * 1000)
str_to_sign = str(now) + method + endpoint
signature = base64.b64encode(hmac.new(api_secret.encode(), str_to_sign.encode(), hashlib.sha256).digest()).decode()
passphrase = base64.b64encode(hmac.new(api_secret.encode(), api_passphrase.encode(), hashlib.sha256).digest()).decode()
return {'KC-API-KEY': api_key,
'KC-API-KEY-VERSION': '2',
'KC-API-PASSPHRASE': passphrase,
'KC-API-SIGN': signature,
'KC-API-TIMESTAMP': str(now)
}
#List Orders
method = 'GET'
endpoint = '/api/v1/limit/orders/' # main
# params = {'type': 'stop_limit'}
params = {}
# # if params :
qstr = '?' + urlencode(params)if params else ''
active_orders = requests.get(url=base_uri+endpoint+qstr, headers=get_headers(method,endpoint+qstr))
Using the ibm-watson Python SDK version 5.3.0 with the following code example:
from ibm_watson import DiscoveryV2, ApiException
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
import json
url = 'https://api.eu-de.discovery.watson.cloud.ibm.com'
version = '2020-08-30'
apikey = '...'
project = '...'
collection = '...'
authenticator = IAMAuthenticator(apikey)
discovery = DiscoveryV2(version=version, authenticator=authenticator)
discovery.set_service_url(url)
try:
result = discovery.query(
project_id=project,
collection_ids=collection,
query='text:searchterm',
table_results=True
).get_result()
print(json.dumps(result, indent=2))
except ApiException as ex:
print(f'Failed. Status code {ex.code}: {ex.message}')
Returns the following error from the server.
Failed. Status code 400: Failed to translate JSON in request: Cannot
deserialize value of type
`scala.collection.immutable.List<java.lang.String>` from String value
(token `JsonToken.VALUE_STRING`)
The error only occurs if collections_ids or table_results is specified.
The server is telling you that the JSON sent to it doesn't match what it expects to process.
The collections_ids and table_results are incorrectly formatted for the API request.
As per the API documentation.
collections_ids must be a list. So change to collections_ids=[collections]
table_results expects an object. To correct use table_results={ 'enabled': True }
I found, that sending JSON, which has entry which starts with "function" produces invalid JSON.
Example:
#Grab('org.codehaus.groovy.modules.http-builder:http-builder:0.7.1')
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.JSON
def jsonSlurper = new JsonSlurper()
// if you replace `function` on next line to any other word - it will work correctly
String baseContextJSON = '{ "afterResponse": "function (getParam, setParam, genInfo) { }" }'
def baseContext = jsonSlurper.parseText(baseContextJSON)
println JsonOutput.prettyPrint(JsonOutput.toJson(baseContext))
RESTClient http = new RESTClient('https://requestinspector.com')
http.post(
path: "/inspect/01dh7rs82be884ke89jcny061e",
body: baseContext, // if I use baseContextJSON here - correct JSON would be sent
query: null,
requestContentType: JSON
)
This code sends this payload:
{"afterResponse":function(getParam,setParam,genInfo){}}
That's invalid JSON - note missing quote around function.
You can see actual received payloads at https://requestinspector.com/p/01dh7rs82be884ke89jcny061e (until it expires, or you can generate you own)
I can't even figure out:
- is it bug in HTTPBuilder?
- is it bug in how Groovy handles and convert Map to JSON?
Any idea what can I do to pin root cause?
I'm trying to learn graphene-python, and have a very simple api set up to GET "hello" or "goodbye" Message graphene.Fields to all users or a specified user. I want each Message to have a field which is another Metadata, another graphene.Field. But when I make API calls which request Metadata, I get a None response from my API. The more general question is, how can I have a custom graphene.Field, which itself has variables that are graphene.Fields, and how do I resolve these variables?
Here is my sample API code:
import graphene
from uuid import uuid4
import time
users = ['A', 'B',' C']
# describes message metadata
class Metadata(graphene.ObjectType):
time_sent = graphene.Int()
uuid = graphene.String()
def resolve_timeSent(parent, info):
return int(time.time())
def resolve_uuid(parent, info):
return uuid4().hex
# basic message model
# contains message content and metadata
class Message(graphene.ObjectType):
content = graphene.String()
metadata = graphene.Field(Metadata)
def resolve_metadata(parent, info):
return Metadata()
# query schema
class Query(graphene.ObjectType):
# Return a list of message objects
helloTo = graphene.Field(Message, user=graphene.String(required=True))
helloAll = graphene.List(Message)
goodbyeTo = graphene.Field(Message, user=graphene.String(required=True))
goodbyeAll = graphene.List(Message)
###
# resolvers
###
def resolve_helloTo(self, info, user):
data = Message(f"hello, {user}", int(time.time()))
return data
def resolve_helloAll(self, info):
data = [Message(f"hello, {u}!", int(time.time())) for u in users]
return data
def resolve_goodbyeTo(self, info, user):
data = Message(f"goodbye, {user}", int(time.time()))
return data
def resolve_goodbyeAll(self, info):
data = [Message(f"goodbye, {u}!", int(time.time())) for u in users]
return data
schema = graphene.Schema(query=Query)
The query
query {
helloTo(user: "STRANGER") {
content
}
}
Returns a proper response of
{
"helloTo": {
"content": "hello, STRANGER"
}
}
But the queries
query {
helloTo(user: "jack wolf") {
content
metadata
}
}
and
query {
helloTo(user: "jack wolf") {
content
metadata {
time_sent
uuid
}
}
}
Both return None.
How can I fix this? Thank you!