Can't listen to FTX filled orders in-stream by using FtxWebsocketClient - cryptocurrency

guys
I want to listen to someone's FTX future orders in-stream and I try this
from client import FtxWebsocketClient
import time
wsm_client = FtxWebsocketClient()
while True:
if wsm_client.get_fills() != []:
print(wsm_client.get_fills())
if wsm_client.get_orders() != {}:
print(wsm_client.get_orders())
time.sleep(0.25)
But it always returns an empty string but there are orders get filled.
Any ideas?
Thank you

Related

How to select for multiple conditions to return one object that matches those conditions

I am creating a test, and am trying to create a method that pulls a specific job posting ID when it matches the job posting title, the job type and the description, just in case that the case that there are more than one job posting with the same title.
I cannot get the select statement to pull the job posting ID out of the instance variable. Debugging shows that there is indeed the ID nested in the instance variable, but my conditions aren't being met because I am not doing it correctly.
#job_posting is the instance variable that contains the ID that I need, but I need my parameters in select to match so I can subsequently return the ID.
whenever I ONLY use posting title,such as:
target_postings = #job_postings.select{|posting|posting[:posting_title]}
it works and returns the ID I need, however I cannot do this:
def get_specific_posting_id_for_posting(posting_title, job_type, description)
expect(#job_postings.length > 0)
target_postings = #job_postings.select {|posting| posting[:posting_title] == posting_title; posting[:job_type] == job_type; posting[:description] == description}
expect(target_postings.length == 1)
target_posting = target_postings[0]
posting_id = target_posting[:posting_id]
posting_id
end
It looks like
target_postings = #job_postings.select {|posting| posting[:posting_title] == posting_title; posting[:job_type] == job_type; posting[:description] == description}
should probably be
target_postings = #job_postings.select do |posting|
posting[:posting_title] == posting_title
&& posting[:job_type] == job_type
&& posting[:description] == description
end
Your version has three separate checks, the first two of which do nothing, only the last statement in the block is actually being used to determine whether the item matches.
As an aside, since it looks like you only want the single first element that matches your conditions, you might want to consider using find instead of select. It works the same except it will stop iterating and return as soon as it finds the first matching item.

Is there a way to use/get the value from a current entry window

I'm trying to get the variable that's entered in an entry widget on the Return key pressed event, but struggling a bit. What I have tried has always produced a blank result.
This code may look messy and hap-hazard, but it's only going to be a template that I'll be using on a current project!
I've tried that many things to get it to work, I can't remember what I have tried!
from collections import OrderedDict
try:
import tkinter as tk
except:
import Tkinter as tk
root = tk.Tk()
labelLIST = OrderedDict([
('Temp ID', 'tempID'),
('PO Number', "poNumber"),
('Reference', "reference"),
('Cut/Sample Date', "csDate"),
('Cut Number', "cut")
])
i = 0
e_loops = len(labelLIST)
print (e_loops)
def bval1(event=None):
for i in range(e_loops):
print (entries[i].get())
entries[0].delete(0, tk.END)
entries[0].insert(0, 'DISABLED')
entries[0].configure(state='disabled')
def bval2():
entries[0].configure(state='normal')
for i in range(e_loops):
entries[i].delete(0, tk.END)
entries[0].focus()
def onClick(event):
ent = event.widget # event.widget is the widget that called the event
print(ent.cget("text")) # Print the text for the selected button
event.widget.tk_focusNext().focus()
def enterEV(event):
# print(entries[].get())
event.widget.tk_focusNext().focus()
entries = []
for key, value in labelLIST.items():
label = tk.Label(root, text=key)
label.grid(row=i, column=0, sticky="ew", padx=1, pady=1)
entry = tk.Entry(root, width=10)
entry.grid(row=i, column=1, sticky="ew", padx=5, pady=5)
if value == "cut":
entry.bind('<Return>', bval1)
else:
# entry.bind('<Return>', enterEV)
entry.bind('<Return>', onClick)
entries.append(entry)
i = i+1
button = tk.Button(root, text="Submit", command=bval1)
button.grid(row=0, column=2, columnspan=9, sticky="ew")
button = tk.Button(root, text="Clear", command=bval2)
button.grid(row=1, column=2, columnspan=9, sticky="ew")
entries[0].focus()
tk.mainloop()
When enter/return is pressed, I want the value that is the entry box to be printed to terminal via the onClick event. But the output is always empty.
def onClick(event):
ent = event.widget # event.widget is the widget that called the event
print(ent.cget("text")) # Print the text for the selected button
event.widget.tk_focusNext().focus()
You don't use the text attribute to get the value in an Entry widget. Using cget("text") returns the value for the textvariable attribute. Since you haven't set that attribute, it will always be the empty string.
Instead, you need to call the get method:
print(ent.get())

NDB -- How to know if an entity has been contained under a root Key

I want to add player's data into NDB. However before I add them, I have to check whether the data exists in datastore or not. I can't find the obvious answer in official docs. Can anyone give me a simple code and explanation about this problem? Here is part of my code.
self.player = Player(parent=ndb.Key("Players", "PlayersKeys"), name = self.request.get("Name"), playerid = self.request.get("ID"))
self.player.put()
Update-------------------
By using query, if it contains the data, then qry.get() would not be None.
Here is my solution:
qry = Player.query(Player.userid == self.request.get("ID"))
if qry.get() == None:
# put the data to datastore
self.player = Player(parent=ndb.Key("Players", "PlayersKeys"), name = self.request.get("Name"), userid = playerid)
self.player.put()
else:
# Do nothing
The answer is Player.get_or_insert
player_key = Player.query(Player.userid == self.request.get("ID")).get(keys_only=True)
player = Player.get_or_insert(player_key, **data)
You have to know the id of the entity, which is playerid in your case, and the key of the parent.
Therefore
myPlayer = Player.get_by_id(int(playerid),parent=parentKey)
if myPlayer:
#The player already exists... do something
pass
else:
#The player does not exist (yet) you can create it
pass
UPDATE
try
playerCount= Player.query(Player.userid ==self.request.get("ID")).count(keys_only=True)
if PlayerCount>0:
#the player already exists
pass
else:
#the player does not exist
pass
This shouldn't increase the number of read operations

How to get all friends - TweetSharp

I'm using the ListFriends() method of TweetSharp library to get all friends of my user (My user has 500 friends).
TwitterCursorList<TwitterUser> friendsList = service.ListFriends(new ListFriendsOptions { Cursor=-1,SkipStatus=true});
while (friendsList.NextCursor != null)
{
foreach (var item in friendsList)
{
count++;
}
TwitterCursorList<TwitterUser> friendsList = service.ListFriends(new ListFriendsOptions { Cursor = friendsList.NextCursor, SkipStatus = true });
}
The above code is working well but it gives me only 300 friends because ListFriends() method has rate limit of 15 per 15 mins and when I'm trying to get more friends its rate limits get over.
How to get all friends in one attempt coz my requirement is to show all friends.
friends/ids will give you the id's of your friends (5.000 max/request). After that you can do a users/show to get the details for the userid's. I don't know what TweetSharp methods you need to use, but I think you can find that in the documentation.
You have one mistake in your code. You cant define friendsList again inside your loop. Thus the last line of code should looks like:
friendsList = service.ListFriends(new ListFriendsOptions { Cursor = friendsList.NextCursor, SkipStatus = true });

ndb fetch_page does not return next cursor after delete

I have basic paging implemented for my app where I show 5 items(ndb.Model) at a time. I query them using code below,
fetched_resutls,next_cursor, more = Content.query(Content.user_email == user_email).order(-Content.sent_time).fetch_page(5, start_cursor=cursor)
When user deletes an item, I use below code to delete an item and requery first five items. I pass an empty cursor to delete. During this re-query, next_cursor is None although there are more items. Can anybody explain why?
contentIntId = int(content_id)
content = Content.get_by_id(contentIntId)
content.key.delete()
fetched_results, next_cursor = Content.find_by_email(user.email(), cursor)
If I do a plain re-query without delete preceeding it, then I do get the next cursor.
-----Edit 1-------
Code for find_by_email
def find_by_email(cls, user_email, cursor):
fetched_resutls,next_cursor, more = Content.query(Content.user_email == user_email).order(-Content.sent_time).fetch_page(5, start_cursor=cursor)
li = []
ep = None
for p in fetched_resutls:
ep = p.to_dict()
ep['id'] = str(p.key.id())
li.append(ep)
next_bookmark = None
if more:
next_bookmark = next_cursor.to_websafe_string()
return li, next_bookmark
Sequence of events,
I first do a plain query using empty cursor. I get 5 items with a
cursor back.
User deletes an item from the list and I re-query first
five items with an empty cursor. Although, I get items, I don't get a cursor back.

Resources