Comments (2)
Hi the api variable determines whether we are connecting to the public or private endpoint.
The function async def private_api(self, request):
returns the variable containing the data for a private api connection and
async def public_api(self, request):
returns the variable containing the data for a public api connection
I hope this makes sense, if you bear with me I will put an example together showing how to retrive market data.
from deribit_websocket_v2.
A quick example of a single script that will fetch the index prices of test net eth / btc, hope this helps. Let me know if your still struggling or want an example doing for a particular end point.
import asyncio
import websockets
import json
client_id = 'enter_client_id_here'
client_secret = 'enter_client_secret_here'
client_url = 'wss://test.deribit.com/ws/api/v2'
# create a websocket object
class WS_Client(object):
def __init__(self, client_id=None, client_secret=None):
self.client_id = client_id
self.client_secret = client_secret
self.client_url = client_url
self.json = {
"jsonrpc" : "2.0",
"id" : 1,
"method" : None,
}
# send a public method request
async def public_api(self, request):
async with websockets.connect(self.client_url) as websocket:
await websocket.send(request)
response = await websocket.recv()
response = json.loads(response)
return response
# create an asyncio event loop
def loop(self, api, request):
response = asyncio.get_event_loop().run_until_complete(
api(json.dumps(request)))
return response
# example get index function https://docs.deribit.com/?python#public-get_index
def index(self, currency):
options = {"currency" : currency}
self.json["method"] = "public/get_index"
self.json["params"] = options
return self.loop(self.public_api, self.json)
client = WS_Client(client_id, client_secret)
btc_index = client.index('BTC')
eth_index = client.index('ETH')
print(btc_index)
print(eth_index)
from deribit_websocket_v2.
Related Issues (10)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deribit_websocket_v2.