Exempel

Added by Patrik about 4 years ago

Hej,
har fått Python exemplet att fungera, undrar om någon med vana skulle kunna lägga upp ett kod exempel hur man kan se information om sitt egna konto, typ hur mycket pengar man har på det. Har aldrig jobbat med http requests på det sättet innnan.

MvH
Patrik


Replies (10)

RE: Exempel - Added by Patrik about 4 years ago

Har försökt subscriba till en feed men får bara tomma svar tillbaks. Kan någon säga vad jag missat.

import time
import base64
from M2Crypto import RSA
import httplib, urllib
import json
import socket, ssl, pprint

def print_json(j,prefix=''):
for key, value in j.items():
if isinstance (value,dict):
print '%s%s' % (prefix,key)
print_json(value, prefix+' ')
else:
print '%s%s:%s' % (prefix,key,value)

username = '********'
password = '*********'
service = 'NEXTAPI'
URL='api.test.nordnet.se'
API_VERSION='2'

timestamp = int(round(time.time()*1000))
timestamp = str(timestamp)
buf = base64.b64encode(username)+':'+base64.b64encode(password)+':'+base64.b64encode(timestamp)
rsa=RSA.load_pub_key('NEXTAPI_TEST_public.pem')
encrypted_hash = rsa.public_encrypt(buf, RSA.pkcs1_padding)
hash = base64.b64encode(encrypted_hash)

headers = {"Accept": "application/json"}
conn = httplib.HTTPSConnection(URL)

  1. GET server status
    conn.request('GET','/next/'+API_VERSION + '/', '', headers)
    r=conn.getresponse()
    response=r.read()
    j = json.loads(response)
    print_json(j)
  1. POST login
    params = urllib.urlencode({'service': 'NEXTAPI', 'auth': hash})
    conn.request('POST','/next/'+API_VERSION+'/login',params,headers)
    r=conn.getresponse()
    response=r.read()
    j = json.loads(response)
    print_json(j)

#Create SSL-wrapped socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ssl_socket = ssl.wrap_socket(s)
#Connect to socket
ssl_socket.connect(("pub.api.test.nordnet.se", 443))
print repr(ssl_socket.getpeername)
print ssl_socket.cipher()
#Send session key
cmd = {"cmd":"login", "args":{"session_key":buf, "service":"NEXTAPI"}}
num_bytes = ssl_socket.write(json.dumps(cmd) + "\n")
print "Session key sent (%d bytes)" % num_bytes
#Get account information

#Subscribe to a stock
market = 11
instrument = "101"
cmd = {"cmd":"subscribe", "args":{"t":"price", "m":market, "i":instrument}}
num_bytes = ssl_socket.send(json.dumps(cmd) + "\n")
print "Subscription request sent for market = %d and instrument = %s (%d bytes)" % (market, instrument, num_bytes)
#Read stream
print "Reading stream"
for i in range(10):
output = ssl_socket.read(1024)
print (output)
time.sleep(1)
#print ("-")
#output = ssl_socket.recv()
#print output

#print "Closing socket connection..."
del ssl_socket
s.close()

RE: Exempel - Added by Björn almost 4 years ago

Det ser ut som att du skickar ett felaktigt login-meddelande på feeden.
Wikin säger följande:
"session_key" The session key from the HTTP login
Med det menas att du ska skicka "session_key" från svaret från HTTP login.

RE: Exempel - Added by Patrik almost 4 years ago

Hej Björn,
Tack för hjälpen! Nu har jag fått subscribtion att funka och kan följa aktier. Har dock lite problem att förstå vad skillnaden mellan Public och Private Feed är samt. När jag försöker få information från den publica feeden så får jag bara tomma rader. Missar antagligen ngt uppenbart...

Koden jag använder ser ut så här.

public_cmd = {"cmd": "subscribe", "args": {"session_key": session_key}}
num_bytes = ssl_socket.send(json.dumps(public_cmd) + "\n")
print "Trying to log into public feed."
while(True):
public_output = ssl_socket.read()
print public_output

RE: Exempel - Added by Lars almost 4 years ago

På Private Feed loggar du in och sedan bara lyssnar, där kommer uppdateringar angående order och avslut på dina egna konton. På Public Feed loggar du först in och sedan prenumererar på prisdata, orderdjup, avslut etc för utvalda instrument, där data avser marknaden som helhet.

{"cmd": "subscribe", "args": {"session_key": session_key}}

Detta ser ut som en sammanblandning av kommandon och argument, "session_key"-argumentet hör ihop med login-kommandot. "subscribe"-kommandot ska ha argument av typen: "args":{"t":"price", "i":"1869", "m":30} Ta en titt till på dokumentationen så klarnar det nog.

RE: Exempel - Added by sunh 2 days ago

"""먹튀검증"":https://mtboan.com/ Hello, my name is""먹튀검증"":https://twiddeo.com/ and I live in ""안전놀이터"":https://twiddeo.com/%ec%95%88%ec%a0%84%eb%86%80%ec%9d%b4%ed%84%b0/ . I read your article well.""토토사이트"":https://twiddeo.com/%ed%86%a0%ed%86%a0%ec%82%ac%ec%9d%b4%ed%8a%b8/ It was really impressive to me. ""꽁머니"":https://twiddeo.com/%ea%bd%81%eb%a8%b8%eb%8b%88/ It was an article that could inspire me with different nationalities. ""안전놀이터"":https://mtboan.com/ Your writing skills are amazing.""스포츠중계"":https://mtboan.com/ Thank you once again and there are many good articles on my site, so please visit.""꽁머니"":https://mtboan.com/ Thank you. Have a nice day! In addition, ""https://mtboan.com/"":https://mtboan.com/ COVID-19 is becoming a problem all over the world these days. ""먹튀보안관"":https://mtboan.com/ I hope there's no harm to you and your family. ""먹튀가디언"":https://twiddeo.com/ Thank you ""https://twiddeo.com/"":https://twiddeo.com/ And the information on my site ""토토안전놀이터"":https://twiddeo.com/%ec%95%88%ec%a0%84%eb%86%80%ec%9d%b4%ed%84%b0/ I'm sure you'll admire it. ""안전토토사이트"":https://twiddeo.com/%ec%95%88%ec%a0%84%eb%86%80%ec%9d%b4%ed%84%b0/ is awesome. I am sure it will be because I am also surprised by your ""꽁머니토토"":https://twiddeo.com/%ea%bd%81%eb%a8%b8%eb%8b%88/And if you visit my site, ""메이저안전놀이터"":https://mtboan.com I think there will be a lot of information you want ""안전놀이터추천"":https://mtboan.com Or, if you have the purpose of inquiry, it would be nice to say ""먹튀사이트조회"":https://twiddeo.com/
"

RE: Exempel - Added by sunh 2 days ago

"""먹튀검증"":https://mtboan.com/ First of all, thank you for letting me see this information.""먹튀검증"":https://twiddeo.com/ I think this article can give me a lot of inspiration.""안전놀이터"":https://twiddeo.com/%ec%95%88%ec%a0%84%eb%86%80%ec%9d%b4%ed%84%b0/ I would appreciate it ""토토사이트"":https://twiddeo.com/%ed%86%a0%ed%86%a0%ec%82%ac%ec%9d%b4%ed%8a%b8/ if you could post more good contents in the future. ""꽁머니"":https://twiddeo.com/%ea%bd%81%eb%a8%b8%eb%8b%88/ There are also many good articles on my site. ""꽁머니"":https://mtboan.com/ I would appreciate it if you could visit once and enjoy it.""안전놀이터"":https://mtboan.com/ Thank you. Have a nice day!""스포츠중계"":https://mtboan.com/ In addition, ""https://mtboan.com/"":https://mtboan.com/ COVID-19 is becoming a problem all over the world these days. ""먹튀보안관"":https://mtboan.com/ I hope there's no harm to you and your family. ""먹튀가디언"":https://twiddeo.com/ Thank you ""https://twiddeo.com/"":https://twiddeo.com/ And the information on my site ""토토안전놀이터"":https://twiddeo.com/%ec%95%88%ec%a0%84%eb%86%80%ec%9d%b4%ed%84%b0/ I'm sure you'll admire it. ""안전토토사이트"":https://twiddeo.com/%ec%95%88%ec%a0%84%eb%86%80%ec%9d%b4%ed%84%b0/ is awesome. I am sure it will be because I am also surprised by your ""꽁머니토토"":https://twiddeo.com/%ea%bd%81%eb%a8%b8%eb%8b%88/And if you visit my site, ""메이저안전놀이터"":https://mtboan.com I think there will be a lot of information you want ""안전놀이터추천"":https://mtboan.com Or, if you have the purpose of inquiry, it would be nice to say ""먹튀사이트조회"":https://twiddeo.com/
"

RE: Exempel - Added by sunh 2 days ago

"""먹튀검증"":https://mtboan.com/ Your article was very impressive to me. ""먹튀검증"":https://twiddeo.com/ It was unexpected information,""안전놀이터"":https://twiddeo.com/%ec%95%88%ec%a0%84%eb%86%80%ec%9d%b4%ed%84%b0/ but after reading it like this,""토토사이트"":https://twiddeo.com/%ed%86%a0%ed%86%a0%ec%82%ac%ec%9d%b4%ed%8a%b8/ I found it very interesting. ""꽁머니"":https://twiddeo.com/%ea%bd%81%eb%a8%b8%eb%8b%88/ Thank you very much. ""꽁머니"":https://mtboan.com/ It was an honor to see this information. ""안전놀이터"":https://mtboan.com/ I should upload similar information on my website. ""스포츠중계"":https://mtboan.com/ Come and check it out for me. In addition, ""https://mtboan.com/"":https://mtboan.com/ COVID-19 is becoming a problem all over the world these days. ""먹튀보안관"":https://mtboan.com/ I hope there's no harm to you and your family. ""먹튀가디언"":https://twiddeo.com/ Thank you ""https://twiddeo.com/"":https://twiddeo.com/ And the information on my site ""토토안전놀이터"":https://twiddeo.com/%ec%95%88%ec%a0%84%eb%86%80%ec%9d%b4%ed%84%b0/ I'm sure you'll admire it. ""안전토토사이트"":https://twiddeo.com/%ec%95%88%ec%a0%84%eb%86%80%ec%9d%b4%ed%84%b0/ is awesome. I am sure it will be because I am also surprised by your ""꽁머니토토"":https://twiddeo.com/%ea%bd%81%eb%a8%b8%eb%8b%88/And if you visit my site, ""메이저안전놀이터"":https://mtboan.com I think there will be a lot of information you want ""안전놀이터추천"":https://mtboan.com Or, if you have the purpose of inquiry, it would be nice to say ""먹튀사이트조회"":https://twiddeo.com/
"

RE: Exempel - Added by sunh 2 days ago

먹튀검증:https://mtboan.com/ Your information was very useful to me. 먹튀검증 That's exactly what I've been looking for! 안전놀이터 Thank you.토토사이트 How did you come up with this?꽁머니 That's amazing. I'm not good enough, but I'm running a site that deals with similar information. 꽁머니 I hope you can visit once and talk with me.안전놀이터 Thank you. Have a nice day!스포츠중계 In addition, https://mtboan.com/ COVID-19 is becoming a problem all over the world these days. 먹튀보안관 I hope there's no harm to you and your family. 먹튀가디언 Thank you https://twiddeo.com/ And the information on my site 토토안전놀이터 I'm sure you'll admire it. 안전토토사이트 is awesome. I am sure it will be because I am also surprised by your 꽁머니토토 if you visit my site, 메이저안전놀이터 I think there will be a lot of information you want 안전놀이터추천 Or, if you have the purpose of inquiry, it would be nice to say 먹튀사이트조회

RE: Exempel - Added by sunh 2 days ago

토토레프리 Your post really helped me a lot. 먹튀검증 As an opportunity to read one article, 먹튀 I'm reading all your other posts. 먹튀검증업체 I found out that you are a person https://elephonemobile.com/ with a lot of abilities. 먹튀사이트 Your website is 메이저놀이터 full of really needed content. I envy you. I also run one of my websites. 메이저놀이터 It's a little different from you, 사설토토 but many posts are registered on 메이저사설토토 my site, and I'm still writing them. The posts are being updated 사설놀이터 almost every week, 안전놀이터 so if you're interested, visit them and read them. 안전놀이터 I'm sure it'll help you, too. 토토사이트 There are many problems happening all over the world these days, and I hope you don't have any problems, 메이저토토사이트 and I hope you have a great day today. Thank you again for letting me read this, 토토사이트추천 and I'll see you next time. 토토사이트 Good bye

RE: Exempel - Added by sunh 2 days ago

안전놀이터검증및연구센터 I finally found 토토사이트분석전문블로그 what I was looking for! 먹튀검증의새로운패러다임 I'm so happy. https://kipu.com.ua/ You don't know https://remarka.kz/ how much I've tried https://subtitles.ee/ to find content like your post. 안전놀이터 Thank you for finally finding the post 먹튀검증 I was looking for. 토토사이트 Actually, 먹튀사이트검증 I also run a website that 메이저토토사이트 is similar to your post theme. 메이저안전놀이터 If you have time, 안전한사설토토사이트 could you visit my website? 공식안전놀이터 I think it would be very helpful for me 먹튀검증커뮤니티 if you could visit my site 먹튀검증토토사이트 and read the uploaded post 먹튀검증토토 and leave your comments on 사설안전놀이터] it would be very helpful for me. I live in a different country from you. But the content of your article will be very popular in my country. Thank you so much for letting me read this post again. Have a nice day today. Thank you.Nowadays,토토사이트검증업체 the weather is getting colder every day토토안전놀이터 , so wear warm clothes and watch out for a cold 확실한먹튀검증 It's really cool 검증토토사이트. I'd like to know more information. Just like your 안전한먹튀검증 I have 최고의안전놀이터

(1-10/10)