itolosa/orionx-api-client

AttributeError: 'module' object has no attribute 'Session'

Closed this issue · 2 comments

Hi

I tried to run this code from inside node (using python-shell), also tried to execute using terminal as a python file:

from orionxapi import client
from pygql import gql
from pygql.dsl import DSLSchema

api_key = '***'
secret_key = '***'
client = client(api_key, secret_key)

ds = DSLSchema(client)

query_dsl = ds.Query.marketStats.args(
                marketCode="CHACLP",
                aggregation="h1"
              ).select(ds.MarketStatsPoint.open)

print(ds.query(query_dsl))

# marketOrderBook
query = gql('''
  query getOrderBook($marketCode: ID!) {
    orderBook: marketOrderBook(marketCode: $marketCode, limit: 50) {
      buy {
        limitPrice
        amount
        __typename
      }
      sell {
        limitPrice
        amount
        __typename
      }
      spread
      __typename
    }
  }
''')

params = {
  "marketCode": "CHACLP"
}

operation_name = "getOrderBook"

print(client.execute(query, variable_values=params))

In both cases the following error happens

Traceback (most recent call last):
  File "/Users/orion/NODE/crypto_fire/functions/python/my.py", line 14, in <module>
    client = client(api_key, secret_key)
  File "/Users/orion/NODE/crypto_fire/functions/python/orionxapi/client.py", line 23, in client
    timeout=timeout
  File "/Users/orion/NODE/crypto_fire/functions/python/orionxapi/transport.py", line 86, in __init__
    super(CustomSessionTransport, self).__init__(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/pygql/transport/session_transport.py", line 16, in __init__
    self.session = requests.Session()
AttributeError: 'module' object has no attribute 'Session'

I am kind of noob in both python and graphql.

It would be awesome if you create a node module for this.
Thanks

also tried using graphql-request(a node module ) to get data from Orionx api.

Code :

let GraphQLClient = require('graphql-request').GraphQLClient;

const client = new GraphQLClient('https://api2.orionx.io/graphql', {
    headers: {
        "x-orionx-apikey": "***",
        "x-orionx-apisecret": "***"
    },
});
const query = `{
personalApiKey()
  market(code: "BTCCLP") {
    code
    name
    lastTrade {
      _id
      amount
      price
      totalCost
      date
    }
  }
}`;

client.request(query).then(data => console.log(data)).catch(err => console.log(err));

Which returns:

{ Error: Aprende a usar el api de orionx en https://orionx.com/developers [noContext]: {"response":{"errors":[{"message":"Aprende a usar el api de orionx en https://orionx.com/developers [noContext]"}],"status":200},"request":{"query":"{\npersonalApiKey()\n  market(code: \"BTCCLP\") {\n    code\n    name\n    lastTrade {\n      _id\n      amount\n      price\n      totalCost\n      date\n    }\n  }\n}"}}
    at GraphQLClient.<anonymous> (/Users/orion/NODE/crypto_fire/functions/node_modules/graphql-request/dist/src/index.js:115:35)
    at step (/Users/orion/NODE/crypto_fire/functions/node_modules/graphql-request/dist/src/index.js:40:23)
    at Object.next (/Users/orion/NODE/crypto_fire/functions/node_modules/graphql-request/dist/src/index.js:21:53)
    at fulfilled (/Users/orion/NODE/crypto_fire/functions/node_modules/graphql-request/dist/src/index.js:12:58)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:160:7)
  response: { errors: [ [Object] ], status: 200 },
  request: 
   { query: '{\npersonalApiKey()\n  market(code: "BTCCLP") {\n    code\n    name\n    lastTrade {\n      _id\n      amount\n      price\n      totalCost\n      date\n    }\n  }\n}',
     variables: undefined } }

But everything is in Spanish so, I am lost :p

nvm, I found the node tutorial for this.